/*copyright(c)2016.烟台大学计算机学院 * All rights reserved, * 文件名称:text.Cpp * 作者:舒文超 * 完成日期:2016年4月30日 * 版本号:vc++6.0 * 问题描述:先设计一个点类,再以点类为基类 设计一个圆类,再以圆类为基类设 计一个圆柱类 */ #include<iostream> using namespace std; #define Pi 3.1415926 class Point { private: double x,y; public: Point(double xx,double yy):x(xx),y(yy){} void printXY() { cout<<"横坐标为:"<<x<<"\t纵坐标为:"<<y<<endl; } double getX() { return x; } double getY() { return y; } }; class Circle:public Point { private: double r; double s; double perimeter; public: Circle(double xx,double yy,double rr):Point(xx,yy),r(rr){} void printR() { cout<<"半径为:"<<r<<endl; } void calS() { s=Pi*r*r; } void calPerimeter() { perimeter=2.0*Pi*r; } void printS() { cout<<"面积为:"<<s<<endl; } void printPerimeter() { cout<<"周长为:"<<perimeter<<endl; } double getR() { return r; } double getS() { return Pi*r*r; } double getPerimeter() { return 2.0*Pi*r; } }; class Cylinder:public Circle { private: double h; double area; double volume; public: Cylinder(double xx,double yy,double rr,double hh):Circle(xx,yy,rr),h(hh){} double getH() { return h; } void CalArea() { area=Circle::getS()*2.0+Circle::getPerimeter()*h; } void CalVolume() { volume=Circle::getS()*h; } void printH() { cout<<"圆柱高为:"<<h<<endl; } void printArea() { cout<<"圆柱表面积为:"<<area<<endl; } void printVolume() { cout<<"圆柱体积为:"<<volume<<endl; } }; int main() { Point p(1.0,1.0); p.printXY(); Circle c(1.0,1.0,1.0); c.calPerimeter(); c.calS(); c.printR(); c.printS(); c.printPerimeter(); Cylinder C(1.0,1.0,1.0,2.0); C.printH(); C.CalArea(); C.CalVolume(); C.printArea(); C.printVolume(); return 0; }