您好,欢迎来到爱玩科技网。
搜索
您的当前位置:首页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;}

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

Copyright © 2019- aiwanbo.com 版权所有 赣ICP备2024042808号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务