编写一个 C++ 程序,通过示例查找长方体的体积和表面积。此 C++ 程序允许用户输入长方体的长度、宽度和高度。接下来,我们使用数学公式计算长方体的表面积、体积和侧面积。它们是:
- C++ 长方体体积 = lbh
- C++ 长方体表面积 = 2(lw + lh + wh)
- C++ 长方体侧面积 = 2h(l + w)
其中 l = 长度,b = 宽度,h = 高度,w = 宽度
#include<iostream>
using namespace std;
int main()
{
float cbd_Length, cbd_Width, cbd_Height, cbd_sa, cbd_Volume, cbd_LSA;
cout << "\nPlease Enter the Length of a Cuboid = ";
cin >> cbd_Length;
cout << "\nPlease Enter the Width of a Cuboid = ";
cin >> cbd_Width;
cout << "\nPlease Enter the Height of a Cuboid = ";
cin >> cbd_Height;
cbd_sa = 2 * (cbd_Length * cbd_Width + cbd_Length * cbd_Height + cbd_Width * cbd_Height);
cbd_Volume = cbd_Length * cbd_Width * cbd_Height;
cbd_LSA = 2 * cbd_Height * (cbd_Length + cbd_Width);
cout << "\nThe Surface Area of a Cuboid = " << cbd_sa;
cout << "\nThe Volume of a Cuboid = " << cbd_Volume;
cout << "\nThe Lateral Surface Area of a Cuboid = " << cbd_LSA;
return 0;
}
