编写程序实现计算长方体表面积和体积:从键盘输入长=12.0,宽=4.0,高=6.0,输出其表面积和体积
时间: 2024-06-12 10:09:11 浏览: 89
计算长方体体积.c
#include<iostream>
using namespace std;
class Cuboid {
public:
Cuboid(double l = 0, double w = 0, double h = 0) {
length = l;
width = w;
high = h;
}
double GetSurface() {
return 2 * (length * width + length * high + width * high);
}
double GetVolume() {
return length * width * high;
}
private:
double length, width, high;
};
int main() {
double length, width, high;
cout << "请输入长方体的长,宽和高:" << endl;
cin >> length >> width >> high;
Cuboid c(length, width, high);
double surface = c.GetSurface();
double volume = c.GetVolume();
cout << "表面积为:" << surface << endl;
cout << "体积为:" << volume << endl;
return 0;
}
阅读全文