c++计算出圆和圆柱体的表面积和体积

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.编写一个程序计算出圆和圆柱体的表面积和体积。

要求:(1)定义一个点(point)类,包含数据成员x,y(坐标点),以它为基类,派生出一个circle类(圆类),增加数据成员r(半径),再以circle作为直接基类,派生出一个cylinder(圆柱体)类,再增加数据成员h(高)。

设计类中数据成员的访问属性。

(2)定义基类的派生类圆、圆柱都含有求表面积和体积的成员函数和输出函数。

(3)定义主函数,求圆、圆柱的面积和体积。

#include<>
class point
{
private:
float x,y;
public:
point()
{
x=0;
y=0;
}
point(float x1,float y1)
{
x=x1;
y=y1;
}
};
class circle:public point
{
public:
circle(float x2,float y2,float r1):point(x2,y2) {
r=r1;
}
void ci_area()
{
area1=r*r*;
}
void ci_output()
{
cout<<"圆面积="<<area1<<endl;
}
float r;
double area1;
};
class cylinder:public circle
{
private:
float h;
double area2,vo;
public:
cylinder(float x3,float y3,float r2,float h1):circle(x3,y3,r2) {
h=h1;
}
void cy_area()
{
area2=(2**r*h+2**r*r);
}
void cy_volume()
{
vo=*r*r*h;
}
void cy_outout()
{
cout<<"圆柱表面积="<<area2<<" 圆柱体积="<<vo<<endl;
}
};
void main()
{
circle c1,,;
();
();
cylinder c2,,,;
();
();
();
}。

相关文档
最新文档