设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 1927|回复: 0
打印 上一主题 下一主题

求助一道题

[复制链接]
跳转到指定楼层
1#
发表于 2009-11-6 01:35:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
是算球体,正方体,立方体,圆柱体的体积,不知道最后输入的地方哪错了...
#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;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-19 13:22 , Processed in 0.086116 second(s), 9 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

快速回复 返回顶部 返回列表