每天打卡一小时 第二十三天
6-6 【CPP0028】以圆类Circle及立体图形类Solid为基础设计圆柱类Cylinder
分数 10
作者 C++多态编程
单位 石家庄铁道大学
以点类Point及平面图形类Plane为基类公有派生圆类Circle,再以圆类Circle及立体图形类Solid为基类公有派生圆柱类Cylinder,main(void)函数完成对圆柱类Cylinder的测试。
和昨天的圆锥类似
代码 复制,粘贴就好了 随便改改就对了 好简单
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 | #define PI 3.14159 class Circle: public Point, public Plane { private : double radius; public : Circle( double a=0.0, double b=0.0, double c=0.0) { setX(a); setY(b); radius = c; cout<< "Circle Constructor run" <<endl; } Circle( const Circle &p):Point(p) { radius=p.radius; cout<< "Circle CopyConstructor run" <<endl; } ~Circle() { cout<< "Circle Destructor run" <<endl; } void setR( double r) { radius=r; } double getR() const { return radius; } void show() const { cout << "Circle(Point(" << "X=" << getX() << "," << "Y=" << getY() << ")," << "Radius=" << radius << ")" ; } double area() const { return radius * PI * radius; } double length() const { return 2 * radius * PI; } }; class Cylinder: public Circle, public Solid { private : double height; public : Cylinder( double a=0.0, double b=0.0, double c=0.0, double d=0.0):Circle(a,b,c) { height=d; cout<< "Cylinder Constructor run" <<endl; } Cylinder( const Cylinder &p):Circle(p) { height=p.height; cout<< "Cylinder CopyConstructor run" <<endl; } ~Cylinder() { cout<< "Cylinder Destructor run" <<endl; } void show() const { cout<< "Cylinder(Circle(Point(X=" <<getX()<< ",Y=" <<getY()<< "),Radius=" <<getR()<< ")," << "Height=" <<height<< ")" ; } double s_Area() const { return getR()*getR()*PI*2+2*PI*getR()*height; } double volume() const { return getR()*getR()*PI*height; } void setH( double a) { height=a; } double getH() const { return height; } }; |
游刃有余
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix