C++先建立一个Point(点)类,包含保护数据成员x,y(坐标).以Point类为基类,派生出一个Circle(圆)类,

2024-12-02 08:12:22
推荐回答(2个)
回答1:

#include
using namespace std;
class Point
{
public:
Point(int xx = 0,int yy = 0)
{
x = xx;
y = yy;
}
~Point(void)
{
}

protected:
int x,y;
};

class Circle:public Point
{
public:
Circle(int xx = 0,int yy = 0,int rr = 0)
{
Point(xx,yy);
r = rr;
}
~Circle(void)
{
}
void area(void)
{
double ar = 3.14*r*r;
cout< }

protected:
int r;
};

class Cylinder:public Circle
{
public:
Cylinder(int xx = 0,int yy = 0,int rr = 0,int hh = 0)
{
Point(xx,yy);
Circle(xx,yy,rr);
h = hh;

}
~Cylinder(void)
{
}
void area(void)//表面积
{
double ar = 3.14*r*r*h/3;//具体的公式忘记了
cout< }

void volume(void)//体积
{
double ar = ****;//体积公式忘记了,自己补充
cout< }

private:
int h;

};

int main(void)
{
Circle cir(1,2,3);
cir.area();

Cylinder cy(1,2,3,4);
cy.area();
cy.volume();
system("pause");
return 0;
}

回答2: