...①定义一个基类圆,至少含有一个数据成员半径。 ②定
发布网友
发布时间:2024-03-27 01:53
我来回答
共1个回答
热心网友
时间:2024-03-28 03:39
#include<iostream>
using namespace std;
const double PI=3.14159;
class Circle
{
protected:
double r;
public:
Circle(double a=1)
{
r=a;
}
};
class Globe:public Circle
{
public:
Globe(double a=1):Circle(a) {}
double GetGlobe()
{
return (4*PI*r*r*r)/3;
}
void ShowGlobe()
{
cout<<"GlobeV ="<<GetGlobe()<<endl;
}
};
class Circular:public Circle
{
double tall;
public:
Circular(double a=1,double h=1):Circle(a)
{
tall=h;
}
double GetCircular()
{
return PI*r*r*tall;
}
void ShowCircular()
{
cout<<"CircularV ="<<GetCircular()<<endl;
}
};
class Cone:public Circle
{
double tall;
public:
Cone(double a=1,double h=1):Circle(a)
{
tall=h;
}
double GetCone()
{
return (PI*r*r*tall)/3;
}
void ShowCone()
{
cout<<"ConeV="<<GetCone()<<endl;
}
};
int main()
{
Globe a(10);
Circular b(10,10);
Cone c(10,10);
a.ShowGlobe();
b.ShowCircular();
c.ShowCone();
return 0;
}