/*
* Copyright(c)2016,烟台大学计算机与控制工程学院
* All rights reserved.
* 文件名称:第10、11周项目1:点-圆-圆柱类族的设计(3)
* 作者:于子娴
* 完成日期:2016.5.11
* 版本号:v1.0
*
* 问题描述:再以Circle类为直接基类,派生出一个Cylinder(圆柱体)类,再增加数据成员h(高),,以及求圆柱表面积的成员函数area和求圆柱体积的成员函数volume,实现需要的成员函数,并设计main函数完成测试。
* 输入描述:
* 程序输出:
*/
#include<iostream>
using namespace std;
class Point
{
protected:
double x;
double y;
public:
Point(double x=0,double y=0);
int getX()
{
return x;
}
int getY()
{
return y;
}
void setpoint(double,double);
void show_point();
};
Point::Point(double a,double b)
{
x=a;
y=b;
}
void Point::setpoint(double a,double b)
{
x=a;
y=b;
}
void Point::show_point()
{
cout<<"("<<x<<","<<y<<")"<<endl;
}
class Circle:public Point
{
protected:
double r;
public:
Circle(double x=0,double y=0,double r=0);
void setR(double);
double getR();
double get_area();
void show_circle();
};
Circle::Circle(double a,double b,double r):Point(a,b),r(r){}
void Circle::setR(double R)
{
r=R;
}
double Circle::getR()
{
return r;
}
double Circle::get_area()
{
return 3.1415926*r*r;
}
void Circle::show_circle()
{
cout<<"圆心为("<<x<<","<<y<<"),半径为"<<r<<",面积为"<<get_area()<<endl;
}
class Cylinder:public Circle
{
protected:
double h;
public:
Cylinder(double x=0,double y=0,double r=0,double h=0);
void setH(double);
double getH();
double get_Biaoarea();
double get_Volume();
void show_Cylinder();
};
Cylinder::Cylinder(double a,double b,double r,double h):Circle(a,b,r),h(h){}
void Cylinder::setH(double H)
{
h=H;
}
double Cylinder::getH()
{
return h;
}
double Cylinder::get_Biaoarea()
{
return get_area()*2+2*3.1415926*r*h;
}
double Cylinder::get_Volume()
{
return get_area()*h;
}
void Cylinder::show_Cylinder()
{
cout<<"圆心为("<<x<<","<<y<<"),半径为"<<r<<",面积为"<<get_area()<<endl;
cout<<"圆柱的高为"<<h<<",表面积为"<<get_Biaoarea()<<",体积为"<<get_Volume()<<endl;
}
int main( )
{
Cylinder cy1(3,4,5,10);
cy1.show_Cylinder();
cy1.setH(15);
cy1.setR(6);
cy1.setpoint(5,5);
cy1.show_Cylinder();
return 0;
}
运行结果: