求3个长方柱的体积,请编写一个基于对象的程序。数据成员包括length(长)、width(宽)、height(高)。要求用成员函数实现以下功能:
(1)由键盘分别输入3个长方体的长宽高
(2)计算长方体的体积;
(3)输出3个长方体的体积
输入:
连续输入9个数,用空格分开
输出:
分别输出三个长方柱的体积,用空格分开
示例:
input
3 2 1 6 5 4 9 8 7
output
box1=6 box2=120 box3=504
#include<iostream>
using namespace std;
class tiji
{
private:
float length;
float width;
float height;
public:
void set()
{
cin >> length >> width >> height;
}
float jisuan()
{
float tiji;
tiji = length * width*height;
return tiji;
}
};
int main()
{
float x, y, z;
tiji ti;
ti.set();
x = ti.jisuan();
ti.set();
y = ti.jisuan();
ti.set();
z = ti.jisuan();
cout << "box1=" << x<<endl;
cout << "box2=" << y << endl;
cout << "box3=" << z << endl;
}