Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

โปรแกรมคำนวณปริมาตรและพื้นที่ผิว Frustum of Cone ใน C++


What is Frustrum of cone?

Frustum of a cone เกิดจากการตัดปลายกรวยออก ทิ้งฐานล่างและฐานบน เรียกว่า frustum ตามรูป ฐานบนมีรัศมี 'r' ฐานล่างมีรัศมี 'R' ความสูง 'h' และความสูงเอียง 'L'

ภาพ Frustrum of cone

โปรแกรมคำนวณปริมาตรและพื้นที่ผิว Frustum of Cone ใน C++

ปัญหา

ให้ slant height, height, upper base radius 'r' และ lower radius 'R' คำนวณปริมาตรและพื้นที่ผิวของ Frustum of cone

สูตร −

Volume (V) = 1/3 * pi * h(r² + R² + r*R) Curved Surface Area (CSA) = pi * l(R + r) Total Surface Area (TSA) = pi * l(R + r) + pi(R² + r²)

ตัวอย่าง

Input-: r=4 R=9 h=12 L=13 Output-: Volume Of Cone : 1671.33   Curved Surface Area Of Cone : 530.929   Total Surface Area Of Cone : 835.663

อัลกอริทึม

Start Step 1 -> define macro as   #define pi 3.14 Step 2 -> Declare function to calculate Volume of cone   float volume(float r, float R, float h)     return (float(1) / float(3)) * pi * h * (r * r + R * R + r * R) Step 3 -> Declare function to calculate Curved Surface area of cone   float CSA(float r, float R, float l)     return pi * l * (R + r) Step 4 -> Declare function to calculate Total Surface area of cone   float TSA(float r, float R, float l, float h)     return pi * l * (R + r) + pi * (r * r + R * R) step 5 -> In main()   declare variables as R1=4, R2=9, slantHeight=13 and height=12   call volume(R1, R2, height)   Call CSA(R1, R2, slantHeight)   TSA(R1, R2,slantHeight, height) Stop

ตัวอย่าง

#include <iostream> #define pi 3.14159 using namespace std; // Function to calculate Volume of cone float volume(float r, float R, float h){   return (float(1) / float(3)) * pi * h * (r * r + R * R + r * R); } // Function to calculate Curved Surface area of cone float CSA(float r, float R, float l){   return pi * l * (R + r); } // Function to calculate Total Surface area of cone   float TSA(float r, float R, float l, float h){   return pi * l * (R + r) + pi * (r * r + R * R); } int main(){   float R1 = 4;   float R2 = 9;   float slantHeight = 13;   float height = 12;   cout << "Volume Of Cone : "<< volume(R1, R2, height)<< endl;   cout << "Curved Surface Area Of Cone : "<<CSA(R1, R2, slantHeight)<< endl;   cout << "Total Surface Area Of Cone : "<<TSA(R1, R2,slantHeight, height);   return 0; }

ผลลัพธ์

Volume Of Cone : 1671.33 Curved Surface Area Of Cone : 530.929 Total Surface Area Of Cone : 835.663