求高手帮我做两道实验题目。。谢谢。(C++)

2024-11-24 12:39:04
推荐回答(3个)
回答1:

#include
#include
#include
const float PI=3.1415926;
class circle //基类圆
{
public:
circle(float r){R=r;}
protected:
float R;
};
class ball:public circle //球类
{
public:
ball(float r):circle(r){}
void com_surface(){surface=4*PI*R*R;}
void com_volume(){volume=4*PI*R*R*R/3;}
float get_surface(){return surface;}
float get_volume(){return volume;}
private:
float surface;
float volume;
};
class taper:public circle // 圆锥类
{
public:
taper(float r,float bR):circle(r)
{ brad=bR; }
void com_surface(){surface=PI*brad*R+PI*brad*brad;}
void com_volume(){volume=PI*brad*brad*pow(R*R-brad*brad,0.5)/3;}
float get_surface(){return surface;}
float get_volume(){return volume;}

private:
float brad; //圆锥底圆半径
float surface;
float volume;
};
class column:public circle //圆柱类
{
public:
column(float r,float h):circle(r)
{
high=h;
}
void com_surface(){surface=PI*R*R*2+2*PI*R*high;}
void com_volume(){volume=PI*R*R*high;}
float get_surface(){return surface;}
float get_volume(){return volume;}
private:
float high; //圆柱高
float surface;
float volume;
};
void main()
{
ball b(3.5);
b.com_surface();
b.com_volume();
cout<<"球的表面积:"<cout<<"球的体积:"<cout<<"----------------"<
taper t(5.1,4.6);
t.com_surface();
t.com_volume();
cout<<"圆锥的表面积:"<cout<<"圆锥的体积:"<cout<<"----------------"<
column c(3.3,5.0);
c.com_surface();
c.com_volume();
cout<<"圆柱的表面积:"<cout<<"圆柱的体积:"<}

回答2:

课本有~

回答3:

第二题已有人问了。我也做了答:http://zhidao.baidu.com/question/54090584.html