ลูกบาศก์คืออะไร
ทรงลูกบาศก์เป็นวัตถุสามมิติที่มีหน้าหกเหลี่ยมหกหน้า ซึ่งหมายความว่ามีด้านยาวและด้านกว้างต่างกัน ความแตกต่างระหว่างลูกบาศก์กับทรงลูกบาศก์คือลูกบาศก์มีความยาว ความสูง และความกว้างเท่ากัน ในขณะที่ลูกบาศก์ทั้งสามนั้นไม่เหมือนกัน
คุณสมบัติของทรงลูกบาศก์คือ −
- หกหน้า
- 12 ขอบ
- 8 จุดยอด
ด้านล่างเป็นรูปลูกบาศก์

ปัญหา
ด้วยความยาว ความกว้าง และปริมาตร ภารกิจคือการหาพื้นที่ผิวทั้งหมดและปริมาตรของทรงลูกบาศก์โดยที่พื้นที่ผิวคือพื้นที่ที่ใบหน้าครอบครอง และปริมาตรคือพื้นที่ที่รูปร่างสามารถบรรจุได้
ในการคำนวณพื้นที่ผิวและปริมาตรของทรงลูกบาศก์มีสูตร
พื้นที่ผิว =2(|*w + w * h + |*h )
ปริมาณ =L* W * H
ตัวอย่าง
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