public:
Circle (double rVal =0): r(rVal) {}
void setRadius(double rVal) { r = rVal; }
double getRadiusO { return r; } .double Area() { return pi*r*r; }
void showData();
};
class Cylinder: public Circle { protected:
double h;
public:
Cylinder(double hVal = 0, double rVal = 0)
: getHeight(hVal), Circle(rVal) { }
void setHeight(double hVal) { h = hVal; }
double getHeight() { return h; }
double Area() { return 2*Circle::Area()+2*pi*r*h; }
void showData();
void Circle::showData() {
cout " = " getRadius() endl
" = " Area endl endl;
}
void Cylinder::showData()
{
cout " = " getRadius() endl
" = " getHeight() endl
" = " Area () endl;
}
void main()
{
Circle circle(2);
Cylinder cylinder(10, 1);
circle.showData ();
cylinder.showData();
3.8. .
Circle r, . r . : , , . r "" rVal .
setRadius , a getRadius . Area . showData .
Cylinder, Circle, h, . setRadius getRadius. h . : h hVal, - Circle rVal.
setHeight , a getHeight h. Circle::Area , . showData , .
main circle Circle 2 cylinder Cylinder 10 1, showData :
= 2 = 12.566
= 1 = 10 = 69.115