标题:求助一道题
只看楼主
uptosky
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2006-10-30
 问题点数:0 回复次数:0 
求助一道题

是算球体,正方体,立方体,圆柱体的体积,不知道最后输入的地方哪错了...
#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;
}

搜索更多相关主题的帖子: private include public double return 
2007-05-28 13:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-142962-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014588 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved