@6-1 使用类计算长方体的体积 (60 分)
```cpp
类和函数接口如:
class Cube{
public:
void set_value(int len,int wd,int ht);
int cal_volume();
void show();
private:
int length,width,height;
};
```cpp
在这里插入代码片在这里给出函数被调用进行测试的例子:
int main()
{
int x,y,z;
Cube c;
cin>>x>>y>>z;
c.set_value(x,y,z);
c.show();
return 0;
}
/* 请在这里填写答案 */
```cpp
void Cube::set_value(int len, int wd, int ht)//判断长宽高是否合法
{
if (len > 0 && wd > 0 && ht > 0)
{
cout << "OK!" << endl;
length = len, width = wd, height = ht;
}
else
{
cout << "ERROR!" << endl;
length = 0, width = 0, height = 0;
}
}
int Cube::cal_volume()//计算长方体积
{
int sum;
sum = length * width * height;
return sum;
}
void Cube::show()//输出长宽高和体积
{
cout << "length=" << length << " width=" << width << " height=" << height << " volume=" << cal_volume();
}