发布网友 发布时间:2024-10-23 23:27
共1个回答
热心网友 时间:2024-10-30 12:25
#include <iostream>
using namespace std;
class Box {
float length, width, height;
public:
Box();
Box(float l, float w, float h);
float GetVolume() const;
};
Box::Box() : length(1), width(1), height(1) {}
Box::Box(float l, float w, float h)
: length(l), width(w), height(h) {}
float Box::GetVolume() const {
return height * width * length;
}
int main()
{
Box b1, b2(2, 3, 4);
float v1, v2;
v1 = b1.GetVolume();
v2 = b2.GetVolume();
if (v1>v2)
cout << v1 << " " << v2 << endl;
else
cout << v2 << " " << v1 << endl;
return 0;
}