C++长方体体积和表面积程序


什么是长方体?

长方体是一个三维物体,具有六个矩形面,这意味着它具有不同长度和宽度的边。长方体和立方体的区别在于,立方体的长度、高度和宽度相等,而长方体的这三个维度不相等。

长方体的属性:

  • 六个面
  • 十二条棱
  • 八个顶点

以下是立方体的图形

问题

给定长、宽和体积,任务是求长方体的总表面积和体积,其中表面积是由面所占的空间,体积是形状可以容纳的空间。

计算长方体的表面积和体积的公式如下:

表面积 = 2(长*宽 + 宽*高 + 长*高)

体积 = 长*宽*高


示例

Input-: L=3 H=2 W=3
Output-: Volume of cuboid is: 18
   Total Surface Area of cuboid is: 42

算法

Start
Step 1 -> declare function to find volume of cuboid
   double volume(double l, double h, double w)
      return (l*h*w)
Step 2 -> declare function to find area of cuboid
   double surface_area(double l, double h, double w)
      return (2 * l * w + 2 * w * h + 2 * l * h)
Step 3 -> In main()
   Declare variable double l=3, h=2 and w=3
   Print volume(l,h,w)
   Print surface_area(l, h ,w)
Stop

示例

#include <bits/stdc++.h>
using namespace std;
//function for volume of cuboid
double volume(double l, double h, double w){
   return (l * h * w);
}
//function for total surface area of cuboid
double surface_area(double l, double h, double w){
   return (2 * l * w + 2 * w * h + 2 * l * h);
}
int main(){
   double l = 3;
   double h = 2;
   double w = 3;
   cout << "Volume of cuboid is: " <<volume(l, h, w) << endl;
   cout << "Total Surface Area of cuboid is: "<< surface_area(l, h, w);
   return 0;
}

输出

Volume of cuboid is: 18
Total Surface Area of cuboid is: 42

更新于:2019年9月20日

654 次浏览

开启你的职业生涯

完成课程获得认证

开始学习
广告
© . All rights reserved.