1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include <iostream>
#ifndef POINT_H
#define POINT_H
using namespace std;
class point
{
public:
point(double = 0.0, double = 0.0);
~point();
protected:
double x;
double y;
};
#endif
point::point(double a, double b)
{
x = a;
y = b;
cout << "point constructor: " << "[" << x << "," << y << "]" << endl;
}
point::~point()
{
cout << "point destructor: " << "[" << x << "," << y << "]" << endl;
}
#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 " << radius << "[" << x << "," << y << "]" << endl;
cout << "area is: " << area << endl;
}
circle::~circle()
{
cout << "circle destructor: radius is " << radius << "[" << x << "," << 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 " << radius << "[" << x << "," << y << "]" << endl;
cout << "height is: " << height << endl;
cout << "area is: " << area << endl;
}
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;
}
| |