#Include #Ifndef POINT - H #Define POINT - H Using Namespace STD Class Point
#Include #Ifndef POINT - H #Define POINT - H Using Namespace STD Class Point
0, double = 0.0); ~point(); protected: double x; double y; }; #endif point::point(double a, double b) { x = a; y = b; cout << "point constructor: } point::~point() { cout << "point destructor: } #ifndef CIRCLE_H #define CIRCLE_H class circle : public point { public: circle(double r = 0.0, double x = 0.0, double y = 0.0); ~circle(); protected: double radius; double area; }; #endif circle::circle(double r, double a, double b): point(a, b) { radius = r; area = 3.141593 * (radius * radius); cout << "circle constructor: radius is << y << "]" << endl; cout << "area is: " << area << endl; } circle::~circle() { " << radius << "[" << x << "," " << "[" << x << "," << y << "]" << endl;
" << "[" << x << "," << y << "]" << endl;
cout << "circle destructor: radius is << y << "]" << endl; cout << "area is: " << area << endl; } #ifndef CYLINDER_H #define CYLINDER_H
class cylinder : public point { public: cylinder(double r = 0.0, double h = 0.0, double x = 0.0, double y = 0.0); ~cylinder(); protected: double radius; double height; double area; }; #endif cylinder::cylinder(double r, double h, double a, double b): point(a, b) { radius = r; height = h; area = 3.141593 * (radius * radius) * height; cout << "cylinder constructor: radius is "," << y << "]" << endl; cout << "height is: " << height << endl; cout << "area is: " << area << endl; } " << radius << "[" << x <<
cylinder::~cylinder() { cout << "cylinder destructor: radius is " << radius << "[" << x << "," << y << "]" << endl; cout << "height is: " << height << endl; cout << "area is: " << area << endl; } int main() { { point p(30.0, 40.5); } cout << endl; circle circle1(6.0, 20.0, 16.5); cout << endl; cylinder cylinder1(12.0, 30.0, 20.0, 40.0); cout << endl; system("pause"); return 0; }
OUTPUT: point constructor: [30,40.5] point destructor: [30,40.5] point constructor: [20,16.5] circle constructor: radius is 6[20,16.5] area is: 113.097 point constructor: [20,40] cylinder constructor: radius is 12[20,40] height is: 30 area is: 13571.7