ya ini program di buat dalam keadaan tergesa-gesa. ,hehehe . , maklum lagi di kejar waktu. ,soalnya siang harus di presentasikan jadinya pagi-pagi jam 8 harus berkutat dengan dev. ,saya memakai dev C++ untuk membuat program ini. ,hehe.
#include
#include
using namespace std;
class Luas
{
protected : int panjang, lebar, sisi,jari,alas,tinggi,pilihan;
char k;
public : void nilai(int a, int b, int c, int r, int x , int y)
{ panjang=a; lebar=b; sisi=c; jari=r; alas=x; tinggi=y; }
};
class Persegipanjang : public Luas
{
public : int area(void)
{ return(panjang*lebar); }
};
class Segitiga : public Luas
{
public : int area(void)
{ return(panjang*lebar/2); }
};
class Persegi : public Luas
{
public : int area(void)
{ return(sisi*sisi); }
};
class Lingkaran : public Luas
{
public : int area(void)
{ return(3.14*jari*jari); }
};
class Jajargenjang : public Luas
{
public : int area(void)
{ return(alas*tinggi); }
};
class Bola : public Luas
{
public : int area(void)
{ return(4*3.14*jari*jari); }
};
int main()
{
int a,b,c,r,x,y;
Persegipanjang ppg;
cout << "===================================" << endl; cout << "I Menghitung Luas Persegi Panjang I" << endl; cout << "===================================" << endl; cout << endl; cout << " Masukan Panjang = " ; cin >> a;
cout << " Masukan Lebar = " ; cin >> b;
cout << endl; ppg.nilai(a,b,c,r,x,y); cout << " Luas Persegi Panjang = " ; cout << ppg.area() << endl; Segitiga sgt; cout << "===================================" << endl; cout << "I Menghitung Luas Segitiga I" << endl; cout << "===================================" << endl; cout << endl; cout << " Masukkan panjang = " ; cin >> a;
cout << " Masukkan Lebar = " ; cin >> b;
cout << endl; sgt.nilai(a,b,c,r,x,y); cout << " Luas Segitiga = " ; cout << sgt.area() << endl; Persegi psg; cout << "===================================" << endl; cout << "I Menghitung Luas Persegi I" << endl; cout << "===================================" << endl; cout << endl; cout << " Masukkan sisi = " ; cin >> c;
cout << endl; psg.nilai(a,b,c,r,x,y); cout << " Luas Persegi = " ;cout << psg.area() << endl; Lingkaran lin; cout << "===================================" << endl; cout << "I Menghitung Luas Lingkaran I" << endl; cout << "===================================" << endl; cout << endl; cout << " Masukkan jari - jari = " ; cin >> r;
cout << endl; lin.nilai(a,b,c,r,x,y); cout << " Luas Lingkaran = " ; cout << lin.area() << endl; Jajargenjang jjr; cout << "===================================" << endl; cout << "I Menghitung Luas Jajar genjang I" << endl; cout << "===================================" << endl; cout << endl; cout << " Masukkan alas = " ; cin >> x;
cout << " Masukkan tinggi = " ; cin >> y;
cout << endl; lin.nilai(a,b,c,r,x,y); cout << " Luas Jajar Genjang = " ; cout << jjr.area() << endl; Bola bol; cout << "===================================" << endl; cout << "I Menghitung Luas Bola I" << endl; cout << "===================================" << endl; cout << endl; cout << " Masukkan jari - jari = " ; cin >> r;
cout << endl;
bol.nilai(a,b,c,r,x,y);
cout << " Luas Bola = " ; cout << bol.area() << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
semoga bermanfaat..
0 comments:
Posting Komentar