/*
* 程序的版权和版本声明部分
* 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;
}
类族的设计
最新推荐文章于 2024-08-15 10:15:00 发布