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

โปรแกรมหาพื้นที่ผิวและปริมาตรของอิโคซาฮีดรอน (Icosahedron) ใน C++


ภาพรวมปัญหา

ในปัญหานี้ เราได้รับค่าที่แสดงความยาวด้านของอิโคซาฮีดรอน งานของเราคือสร้างโปรแกรมหาพื้นที่ผิวและปริมาตรของอิโคซาฮีดรอนใน C++

ข้อมูลพื้นฐาน

อิโคซาฮีดรอน (Icosahedron) คือ พอลิฮีดรอนปกติ 30 ด้าน (หน้า) ประกอบด้วยสามเหลี่ยมด้านเท่า 20 หน้า มีจุดยอด 12 จุด

โปรแกรมหาพื้นที่ผิวและปริมาตรของอิโคซาฮีดรอน (Icosahedron) ใน C++

เส้นประเป็นขอบที่อยู่ด้านหลัง

ตัวอย่าง

Input

a = 4

แนวทางแก้ปัญหา

ใช้สูตรเรขาคณิต:

  • พื้นที่ผิว (Surface Area) = 5√3 × a² ≈ 8.660 × a²
  • ปริมาตร (Volume) = (5/12)(3+√5) × a³ ≈ 2.1817 × a³

ตัวอย่างโปรแกรม

#include <iostream>
using namespace std;

float calcIcoSArea(float a) {
    return (8.660 * a * a);
}

float calcIcoVolume(float a) {
    return (2.1817 * a * a * a);
}

int main() {
    float a = 7;
    cout << "The length of side of icosahedron is " << a << endl;
    cout << "The surface area of icosahedron is " << calcIcoSArea(a) << endl;
    cout << "The volume of icosahedron is " << calcIcoVolume(a) << endl;
    return 0;
}

Output

The length of side of icosahedron is 7
The surface area of icosahedron is 424.34
The volume of icosahedron is 748.323