/*
2.*Copyright(c) 2016.烟台大学计算机与控制工程学院
3.*ALL rights reserved.
4.*文件名称:main.cpp
5.*作者:孙亚茹
6.*完成日期:2016年5月17日
7.*问题描述:自我设计,以Circle类为直接基类,派生出一个Cylinder类,并完成测试。
8.*/
#include <iostream>
using namespace std;
class Point
{
protected:
double x;
double y;
public:
Point(double x1,double y1):x(x1),y(y1){}
void show_Point();
};
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
{
protected:
double h;
public:
Cylinder(double q,double w,double e,double r):Circle(q,w,e),h(r){};
double area_Cy();
double volume();
void show_Cylinder();
};
void Point::show_Point()
{
cout<<"坐标为:"<<x<<" "<<y<<endl;
}
double Circle::area()
{
return 3.14*r*r;
}
void Circle::show_Circle()
{
cout<<"面积为:"<<area()<<endl;
}
double Cylinder::area_Cy()
{
return 3.14*r*r*2+3.14*2*h*r;
}
double Cylinder::volume()
{
return 3.14*r*r*h;
}
void Cylinder::show_Cylinder()
{
cout<<"表面积为:"<<area_Cy()<<" "<<"体积为:"<<volume()<<endl;
}
int main()
{
Point a(2.0,3.0);
Circle b(4.0,3.0,5.0);
Cylinder c(4.0,3.0,5.0,6.0);
a.show_Point();
b.show_Point();
b.show_Circle();
c.show_Cylinder();
return 0;
}