- /*
- *Copyright (c) 2016,烟台大学计算机学院
- *All rights reserved.
- *文件名称:zwj.cpp
- *作 者:李落才
- *完成日期:2016年6月5日
- *版 本 号:v1.0
- *
- *问题描述:按照提示,从基类开始逐渐完成点——圆——圆柱类族的设计。
- *输入描述:
- *程序输出:
- */
- #include<iostream>
- using namespace std;
- class Point
- {
- public:
- Point(double a=0,double b=0);
- void show_point();
- double getx(){return x;}
- double gety(){return y;}
- protected:
- double x;
- double y;
- };
- class Circle:public Point
- {
- protected:
- double r;
- public:
- Circle(double a,double b,double c):Point(a,b),r(c){}
- double area();
- void show_circle();
- };
- class Cylinder:public Circle
- {
- private :
- double h;
- public :
- Cylinder(double a,double b, double c,double d):Circle(a,b,c),h(d){}
- double zhu_area(){return 2*r*r+2*r*3.1415926*h;}
- double zhu_volume(){return r*r*h;}
- void show_zhuarea(){cout<<"圆柱的表面积为:"<<zhu_area()<<endl;}
- void show_zhuvolume(){cout<<"圆柱的体积为:"<<zhu_volume()<<endl;}
- };
- Point::Point(double a,double b)
- {
- x=a;
- y=b;
- }
- void Point::show_point()
- {
- cout<<"点的坐标为:"<<x<<","<<y<<endl;
- }
- double Circle::area()
- {
- return r*r*3.1415926 ;
- }
- void Circle::show_circle()
- {
- cout<<"圆的面积为:"<<area()<<endl;
- }
- int main()
- {
- Point p1(1,2);
- Circle r1(1,2,2.0);
- p1.show_point();
- r1.show_circle();
- Cylinder c1(1,2,2,6);
- c1.show_zhuarea();
- c1.show_zhuvolume();
- return 0;
- }