问题描述
定义一个point类,用来记录点的坐标。由point类派生出cricle类,继承圆心坐标,同时增加新的数据成员,半径r。最后定义组合类cone,其中有两个成员对象,一个是顶点point,一个是底面圆corcle,同时增加新的数据成员,体积V。输出圆锥体积V。
代码展示
#include<iostream>
#include<iomanip>
#define PAI 3.14
using namespace std;
class point //定义类 点
{
private:
int x, y;
public:
point(int x, int y)
{
this->x = x;
this->y = y;
}
point()
{
}
int getx()
{
return x;
}
int gety()
{
return y;
}
void show()
{
cout << "顶点的坐标为:(" << x << "," << y << ")" << endl;
}
};
class circle : public point //由点派生出圆
{
private:
int r; //继承了点的坐标(即圆心)后,新加入成员数据 半径
float S; //圆的面积
public:
circle(int x, int y, int r) :point(x, y)
{
this->r =