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

/*
 * 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;
}

运行结果:


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值