#include using namespace std; class Cuboid { private: double length; double width; double height; public: // 默认构造函数 Cuboid() { length = 0; width = 0; height = 0; } // 构造函数,接受长、宽、高参数 Cuboid(double l, double w, double h) { length = l; width = w; height = h; } // 计算长方体表面积 double surfaceArea() { return 2 * (length * width + length * height + width * height); } // 计算长方体体积 double volume() { return length * width * height; } }; int main() { double l1, w1, h1; double l2, w2, h2; // 输入第一个长方体的长、宽、高 cout << "第一个长方体的长、宽、高:"; cin >> l1 >> w1 >> h1; // 输入第二个长方体的长、宽、高 cout << "第二个长方体的长、宽、高:"; cin >> l2 >> w2 >> h2; // 创建第一个长方体对象 Cuboid cuboid1; // 设置第一个长方体的长、宽、高 cuboid1 = Cuboid(l1, w1, h1); // 输出第一个长方体的表面积和体积 cout << "第一个长方体的表面积为:" << cuboid1.surfaceArea() << endl; cout << "第一个长方体的体积为:" << cuboid1.volume() << endl; // 创建第二个长方体对象 Cuboid cuboid2 = Cuboid(l2, w2, h2); // 输出第二个长方体的表面积和体积 cout << "第二个长方体的表面积为:" << cuboid2.surfaceArea() << endl; cout << "第二个长方体的体积为:" << cuboid2.volume() << endl; return 0; }