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

问题描述:

用C#计算出球、圆柱和圆锥的表面积和体积的源代码:
请帮我做哈
1个回答 分类:综合 2014-11-05

问题解答:

我来补答
#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
 
 
展开全文阅读
剩余:2000
下一页:练习2.3