0% found this document useful (0 votes)
39 views2 pages

#Include #Include #Include

This C++ program uses a switch statement to calculate the area and moment of inertia for different shapes based on user input. The user selects between rectangle, triangle, hemisphere, or circle. The program then prompts for required shape dimensions, calculates the area and Ix or Iy moment of inertia, and displays the results.

Uploaded by

MR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

#Include #Include #Include

This C++ program uses a switch statement to calculate the area and moment of inertia for different shapes based on user input. The user selects between rectangle, triangle, hemisphere, or circle. The program then prompts for required shape dimensions, calculates the area and Ix or Iy moment of inertia, and displays the results.

Uploaded by

MR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1: #include<iostream>

2: #include<cmath>
3: #include<iomanip>
4: using namespace std;
5: int main()
6: {
7: int num;
8: double radius,base,height,area,Ix,Iy;
9:
10: cout<<"This program is used to determine the area and moment of inertia.\n";
11: cout<<"1 for rectangle.\n";
12: cout<<"2 for triangle.\n";
13: cout<<"3 for hemisphere.\n";
14: cout<<"4 for circle.\n";
15: cin>>num;
16:
17: switch (num)
18: {
19: case 1:
20: cout<<"What is the base of the rectangle in m?";
21: cin>>base;
22: cout<<"What is the height of the rectangle in m?";
23: cin>>height;
24: area=base*height;
25: Ix=(base*height*height*height)/12;
26: Iy=(height*base*base*base)/12;
27: cout<<"The area of rectangle is"<<area<<"m2."<<endl;
28: cout<<"The Ix of the rectangle is"<<Ix<<"m4."<<endl;
29: cout<<"The Iy of the rectangle is"<<Ix<<"m4."<<endl;
30: break;
31:
32: case 2:
33: cout<<"What is the base of the triangle in m?";
34: cin>>base;
35: cout<<"What is the height of the triangle in m?";
36: cin>>height;
37: area=(base*height)/2;
38: Ix=(base*height*height*height)/36;
39: cout<<"The area of the triangle is"<<area<<"m2."<<endl;
40: cout<<"The Ix of the triangle is"<<Ix<<"m4."<<endl;
41: break;
42:
43: case 3:
44: cout<<"What is the radius of the hemisphere in m?";
45: cin>>radius;
46: area=(3.142*radius*radius)/2;
47: Ix=(3.142*radius*radius*radius*radius)/8;
48: Iy=(3.142*radius*radius*radius*radius)/8;
49: cout<<"The area of hemisphere is"<<area<<"m2."<<endl;
50: cout<<"The Ix of the hemisphere is"<<Ix<<"m4."<<endl;
51: cout<<"The Iy of the hemisphere is"<<Ix<<"m4."<<endl;
52: break;
53:
54: case 4:
55: cout<<"What is the radius of the circle in m?";
56: cin>>radius;
57: area=(3.142*radius*radius);
58: Ix=(3.142*radius*radius*radius*radius)/4;
59: Iy=(3.142*radius*radius*radius*radius)/4;
60: cout<<"The area of circlee is"<<area<<"m2."<<endl;
61: cout<<"The Ix of the circle is"<<Ix<<"m4."<<endl;
62: cout<<"The Iy of the circle is"<<Ix<<"m4."<<endl;
63: break;
64: default:
65: cout<<"You can only choose 1,2,3 or 4";
66: break;
67: }
68: return 0;
69:
70:
71: }

You might also like