新微赢技术网

标题: 求助一道题 [打印本页]

作者: 芙蓉泣露    时间: 2009-11-6 01:35
标题: 求助一道题
是算球体,正方体,立方体,圆柱体的体积,不知道最后输入的地方哪错了...
#include <iostream.h>
class Shape
{
public:
virtual double Volume() const=0;
};
class Cuboid:public Shape
{
public:
Cuboid(double l,double w,double h){L=l;W=w;H=h;}
double Volume() const {return L*W*H;}
private:
double L,W,H;
};
class Cube:public Shape
{
public:
Cube(double side){S=side;}
double Volume() const {return S*S*S;}
private:
double S;
};
class Circularcylinder:public Shape
{
public:
Circularcylinder(double r,double h){R=r;H=h;}
double Volume() const {return 3.1415*R*R*H;}
private:
double R,H;
};
class Spheroid:public Shape
{
public:
Spheroid(double r){R=r;}
double Volume() const {return 3.1415*R*R*R*4/3;}
private:
double R;
};
class Application
{
public:
double jisuan(double a,double b,double c,double d,double r,double s,double t);
double add();
private:
Shape **s;
};
double jisuan(double a,double b,double c,double d,double r,double s,double t)
{
s[0]= Cuboid(a,b,c);
s[1]= Cube(d);
s[2]= Spheroid(r);
s[3]= Circular(s,t);
}
double add()
{
int sum=0;
for(int i=0;i<4;i++)
sum=s[i]+sum;
return sum;
}
void main()
{
Application A;
double a,b,c,d,r,s,t;
cin>>a>>b>>c>>d>>r>>s>>t;
A.jisuan(a,b,c,d,r,s,t);
cout<<A.add;
}




欢迎光临 新微赢技术网 (http://bbs.weiying.cn/) Powered by Discuz! X3.2