圆柱类族的设计3


  1. /* 
  2.  *Copyright (c) 2016,烟台大学计算机学院 
  3.  *All rights reserved. 
  4.  *文件名称:zwj.cpp 
  5.  *作    者:李落才
  6.  *完成日期:2016年6月5日 
  7.  *版 本 号:v1.0 
  8.  * 
  9.  *问题描述:按照提示,从基类开始逐渐完成点——圆——圆柱类族的设计。 
  10.  *输入描述: 
  11.  *程序输出: 
  12.  */  
  13. #include<iostream>  
  14. using namespace std;  
  15. class Point  
  16. {  
  17. public:  
  18.     Point(double a=0,double b=0);  
  19.     void show_point();  
  20.     double getx(){return x;}  
  21.     double gety(){return y;}  
  22. protected:  
  23.     double x;  
  24.     double y;  
  25. };  
  26. class Circle:public Point  
  27. {  
  28. protected:  
  29.     double r;  
  30. public:  
  31.     Circle(double a,double b,double c):Point(a,b),r(c){}  
  32.     double area();  
  33.     void show_circle();  
  34. };  
  35. class Cylinder:public Circle  
  36. {  
  37. private :  
  38.     double h;  
  39. public :  
  40.     Cylinder(double a,double b, double c,double d):Circle(a,b,c),h(d){}  
  41.     double zhu_area(){return 2*r*r+2*r*3.1415926*h;}  
  42.     double zhu_volume(){return r*r*h;}  
  43.     void show_zhuarea(){cout<<"圆柱的表面积为:"<<zhu_area()<<endl;}  
  44.     void show_zhuvolume(){cout<<"圆柱的体积为:"<<zhu_volume()<<endl;}  
  45. };  
  46. Point::Point(double a,double b)  
  47. {  
  48.     x=a;  
  49.     y=b;  
  50. }  
  51. void Point::show_point()  
  52. {  
  53.     cout<<"点的坐标为:"<<x<<","<<y<<endl;  
  54. }  
  55. double Circle::area()  
  56. {  
  57.     return r*r*3.1415926 ;  
  58. }  
  59. void Circle::show_circle()  
  60. {  
  61.     cout<<"圆的面积为:"<<area()<<endl;  
  62. }  
  63. int main()  
  64. {  
  65.     Point p1(1,2);  
  66.     Circle r1(1,2,2.0);  
  67.     p1.show_point();  
  68.     r1.show_circle();  
  69.     Cylinder c1(1,2,2,6);  
  70.     c1.show_zhuarea();  
  71.     c1.show_zhuvolume();  
  72.     return 0;  
  73. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值