您的位置:首页 > 其它

第三周项目四-长方柱类

2014-03-13 23:12 204 查看
#include <iostream>

using namespace std;
class Bulk
{

public:
void set();
void c_volume();
void c_areas();
private:
double length;
double width;
double heigth;

};
void Bulk::set()
{
double l,w,h;
cout<<"请分别输入长、宽、高:";
cin>>l>>w>>h;
length=l;
width=w;
heigth=h;
}
void Bulk::c_volume()
{
double v;
v=length*width*heigth;
cout<<"体积为:"<<v<<endl;
}
void Bulk::c_areas()
{
double a;
a=(length*width+length*heigth+width*heigth)*2;
cout<<"表面积为:"<<a<<endl;

}
int main()
{
Bulk x,y,z;
x.set();
y.set();
z.set();
x.c_volume();
x.c_areas();
y.c_volume();
y.c_areas();
z.c_volume();
z.c_areas();
return 0;
}

运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: