爱玩科技网
您的当前位置:首页C++定义基类的派生类题文档

C++定义基类的派生类题文档

来源:爱玩科技网
(1)定义一个基类圆,至少含有一个数据成员半径;

(2)定义基类的派生类球、圆柱、圆锥,都含有求体积的成员函数和输出函数。 (3)定义主函数,求球、圆柱、圆锥的和体积。 #include class shape{

protected: double r; public: shape(double x)

{ r=x; cout<<\"constructing shape\"<~shape() { cout<<\"destructing shape\"<public shape{ public: square(double x):shape(x) { cout<<\"constructing square\"<void area(){}};

class in_square:public square{ public: in_square(double x):

square(x) { cout<<\"constructing in_square\"<void area() { cout<<\"The area of the square is \"<public: circle(double x):shape(x) { cout<<\"constructing circle\"<{ shape *ptr; circle obj1(4); in_square obj2(4); ptr=&obj1; ptr->area(); ptr=&obj2; ptr->area(); return 0;}

因篇幅问题不能全部显示,请点此查看更多更全内容