立方体类
编写基于对象的程序,求长方柱(Bulk)的体积。数据成员包括长(length)、宽(width)、高(heigth)、体积,要求用成员函数实现下面的功能:
(1)由键盘输入长方柱的长、宽、高;
(2)计算长方柱的体积(volume)和表面积(areas);
(3)输出这长方柱的体积和表面积。
输入长方柱的长、宽、高。
输出长方柱的体积和表面积。
输入
2 3 4
输出
24
52
//立方体类
#include <iostream>
#include <string.h>
using namespace std;
class Bulk
{
private:
int length;
int width;
int height;
int v;
int a;
public:
void volume()
{
v=length*width*height;
}
void areas()
{
a=2*(length*width)+2*(width*height)+2*(length*height);
}
void getin()
{
cin>>length>>width>>height;
}
void output()
{
cout<<v<<endl;
cout<<a<<endl;
}
};
int main(void)
{
Bulk x;
x.getin();
x.volume();
x.areas();
x.output();
return 0;
}