#include<iostream.h>
#include<conio.h>
class point {
public :
point(float =0.0 ,float =0.0) ;
void cetakPoint () ;
protected:
float x,y;
};
point :
oint(float a,float b)
{
cout<<”Konsruktor Point Dijalankan”<<endl;
x= a;
y=b;
}
void point::cetakPoint()
{
cout<<”Point : “<<’[‘<<x<<”,”<<y<<’]’<<endl;
}
Class Circle
ublic Point{
public:
Circle(float r= 0.0, float a = 0.0,float b =0.0;//konstruktor
float area ();
void cetekPoint();
protected:
float radius.1;
};
Circle::Circle(float r, float a,float b)
:Point(a,b) {
cout<<”Konstruktor Circle dijalankan”<<endl;
radius= r;
}
float Circle ::area()
{
1=3.14 *radius*radius;
return 1;
}
void Circle ::cetakPoint ()
{
Point::catakPoint ();
cout<<Circle dgn r: “<<radius<<” Center :[“<<x<<”,”<<y<<”]”<<endl;
cout<<”Luas circle : “<<1<<endl;
}
class Cylinder:
ublic Circle {
public :Cylinder (float h = 0.0 ,float r =0.0 float a =0.0,float a=0.0,float b=0.0);//konstruktor
float area() ;
float vol () ;
void cetakPoint () ;
protected:
float height,1,v;
};
Cylinder ::Cylinder (floa h,float r,float a,float b)
:Circle (r,a,b)
{
cout<<”Konstrutor Cylinder dijalankan”<<endl;
height=h;
}
float Cylinder::area ()*height );
{
1=(2*Circle::area() + 2*3.24*radius *height);
return 1;
}
float Cylinder::vo1()
{
v=(Circle::area() * height);
return v;
}
void Cylinder::cetakPoint()
{
Circle::cetakPoint();
cout<<”Tinggi tabung(h):”<<height<<endl;
cout<<”Luas Tabung :<<1<<endl;
cout<<”Volume tabung :<<v<<endl;
}
int main()
{
Point p(1.1,2.2);
cout<<endl;
Circle lingkaran(10,5,5);
lingkaran.area();
lingkaran.cetakPoint();
cout<<endl;
Cylinder tabung (20,30,3,4);
tabung.area();
tabung.vol();
tabung.cetakPoint();
getch ();
return 0;
}
2. Buatlah program untuk menghitung luas dan kelilng persegi panjang serta volume dan keliling kotak . Program tersebut harus menerapkan prinsip pewarisan!