求三个长方体的体积,数据成员包括length、width、height。要求用成员函数实现:
1.输入三个长方体的长宽高
2.计算长方体体积
3.输出三个长方体的体积
#include <iostream>
using namespace std;
class box
{
float length;
float width;
float height;
float v;
public:
void set();
void volum();
void show();
};
void box::set()
{
cin>>length;
cin>>width;
cin>>height;
}
void box::volum()
{
v=length*width*height;
}
void box::show()
{
cout<<v<<endl;
}
int main()
{
box t1,t2,t3;
t1.set();
t1.volum();
t1.show();
t2.set();
t2.volum();
t2.show();
t3.set();
t3.volum();
t3.show();
return 0;
}