第11周项目1-点-圆-圆柱类族的设计 (3)

/*
All rights reserced.
文件名称:main.cpp
作者:李鑫
 完成日期:2016.5.26 

问题描述 :自我设计,以Circle类为直接基类,派生出一个Cylinder类,并完成测试。
 

*/

#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;
}

运行结果:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值