用C#计算出球、圆柱和圆锥的表面积和体积的源代码:

用C#计算出球、圆柱和圆锥的表面积和体积的源代码:
请帮我做哈
henrygalaxy 1年前 已收到1个回答 举报

aaalei 幼苗

共回答了22个问题采纳率:95.5% 举报

#include
#include
using namespace std;
class Ccircle
{
protected:
float r;
public:
};
class Csphere:public Ccircle
{
private:
public:
Csphere(float R){r=R;}
float getArea(){return 4*3.1416*r*r;}
float getVolume(){return 4/3*3.1416*r*r*r;}
};
class Ccylinder:public Ccircle
{
private:
float h;
public:
Ccylinder(float R, float H){r=R; h=H;}
float getArea(){return 3.1416*r*(r+2*h);}
float getVolume(){return 3.1416*r*r*h;}
};
class Ccone:public Ccircle
{
private:
float h;
public:
Ccone(float R, float H){r=R; h=H;}
float getArea(){return 3.1416*r*(r+sqrt(r*r+h*h));}
float getVolume(){return 3.1416*r*r*h/3;}
};
int main()
{
float r,h;
coutr;
Csphere sphere(r);
cout

1年前

8
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 5.908 s. - webmaster@yulucn.com