类族的设计

/*
* 程序的版权和版本声明部分
* Copyright (c)2014, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: fibnacci.cpp
* 作    者:高古尊
* 完成日期:2014年5月18日
* 版本号: v1.0
*
* 输入描述:
* 问题描述:
* 程序输出:
* 问题分析:
*/
#include<iostream>
#include<Cmath>
using namespace std;
class Point //定义坐标点类
{
public:
    Point():x(0),y(0) {};
    Point(double x0, double y0):x(x0), y(y0) {};
    double getx()
    {
        return x;
    }
    double gety()
    {
        return y;
    }
    void PrintPoint(); //输出点的信息
protected:
    double x,y;   //点的横坐标和纵坐标
};
void Point::PrintPoint()
{
    cout<<"Point: ("<<x<<","<<y<<")"<<endl;    //输出点
}
class Circle: public Point   //利用坐标点类定义直圆类, 其基类的数据成员表示直线的圆点
{
public:
    Circle():r(0) {}
    Circle(Point, double ); //构造函数,用初始化直线的两个端点及由基类数据成员描述的圆心点
    double area();//计算并返回圆的面积
    double getr()
    {
        return r;
    }
    void Printarea();   //输出圆的面积
protected:
    double r;//圆的半径,从Point类继承的数据成员表示直线的圆心点
};

Circle::Circle(Point pt, double l):Point(pt.getx(),pt.gety())
{
    r=l;
}

double Circle::area()
{
    return 3.14*r*r;
}
void Circle::Printarea()
{
    cout<<area()<<endl;
}
class Cylinder:public Circle
{
public:
    Cylinder():h(0) {}
    Cylinder(Circle,double );
    double volume();
    void PrintCylinder();
private:
    double h;
};
Cylinder::Cylinder(Circle yuan,double h1):Circle(Point(yuan.getx(),yuan.gety()),yuan.getr())
{
    h=h1;
}
double Cylinder::volume()
{
    return h*area();
}
void Cylinder::PrintCylinder()
{
    cout<<volume()<<endl;
}
int main()
{
    Point p(1,1);
    Circle s(p,1);
    Cylinder a(s,1);
    cout<<"圆心为";
    a.PrintPoint();
    cout<<"圆的面积为";
    a.Printarea();
    cout<<"圆柱体的体积为";
    a.PrintCylinder();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值