-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArea_CircumferenceEx4.txt
84 lines (58 loc) · 1.87 KB
/
Area_CircumferenceEx4.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
This program is number 4 in exercises. The purpose is to reorder the program from sloppy error filled code
to a program that runs succesfully. It gathers user data and determines the area and perimeter for a rectangle,
area and circumference for a circle, and for a cylinder the volume and surface.
*/
#include<cmath>
#include<iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string shape;
double height;
double length;
const double PI=3.1416;
double radius;
double width;
cout<<"Enter the shape type: (rectangle, circle, cylinder) ";
cin>>shape;
cout<<endl;
if (shape == "rectangle")
{
cout <<"Enter the length of the rectangle: ";
cin>>length;
cout<<endl;
cout <<"Enter the width of the rectangle: ";
cin>>width;
cout<<endl;
cout<<"Area of the rectangle = "<<length*width<<endl;
cout<<"Perimeter of the rectangle = "<<2*(length+width)<<endl;
}
else if(shape == "circle")
{
cout<<"Enter the radius of the circle: ";
cin>>radius;
cout<<endl;
cout <<"Area of the circle = " <<PI * pow(radius,2.0) <<endl;
cout <<"Circumference of the circle: "<<2*PI*radius<<endl;
}
else if (shape == "cylinder")
{
cout <<"Enter the height of the cylinder: ";
cin >> height;
cout <<endl;
cout<<"Enter the radius of the base of the cylinder: ";
cin>>radius;
cout<<endl;
cout<<"Surface area of the cylinder: "<<2*PI*radius*height+2*PI*pow(radius,2.0)<<endl;
cout<<"Volume of the cylinder = "<<PI*pow(radius,2.0)*height<<endl;
}
else
{
cout<<"The program does not handle "<<shape<<endl;
cout<<fixed<<showpoint<<setprecision(2);
}
return 0;
}