-
Notifications
You must be signed in to change notification settings - Fork 0
/
HMC_0608.cpp
99 lines (79 loc) · 2.62 KB
/
HMC_0608.cpp
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*The following program is designed to find the area of a rectangle, the area of a circle, or the volume of a cylinder. However
* (a) the statements are in the incorrect order;
* (b) the function calls are incorrect;
* (c) the logical expression in the while loop is incorrect; and
* (d) the function definitions are incorrect.
* Rewrite the programs o that it works correctly.
* You program must be properly indented.
* (Note that the program is menu driven and allows the user to run the program as long as the user wishes.)
*/
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
const double long PI = 3.14159265359;
int main()
{
int choice;
double height, length, width, radius,
cylinder, rectangle, circle;
cout << fixed << showpoint << setprecision(2) << endl;
cout << "This program can calculate the area of a rectangle, the area of a circle, or volume of a cylinder." << endl;
cout << "To run the program enter: " << endl;
cout << "1: To find the area of rectangle." << endl;
cout << "2: To find the area of a circle." << endl;
cout << "3: To find the volume of a cylinder." << endl;
cout << "0: To terminate the program." << endl;
cin >> choice;
cout << endl;
while (choice != 0)
{
switch (choice)
{
case 1:
cout << "Enter the length of the rectangle: ";
cin >> length;
cout << "\nEnter the width of the rectangle: ";
cin >> width;
cout << endl;
rectangle = width * length;
cout << "Area = " << rectangle << endl;
cout << endl;
cout << endl;
break;
case 2:
cout << "Enter the radius of the circle: ";
cin >> radius;
cout << endl;
circle = PI * pow(radius, 2);
cout << "Area = " << circle << endl;
cout << endl;
cout << endl;
break;
case 3:
cout << "Enter the radius of the cylinder: ";
cin >> radius;
cout << "\nEnter the height of the cylinder: ";
cin >> height;
cout << endl;
cylinder = PI * pow(radius,2) * height;
cout << "Volume = " << cylinder << endl;
cout << endl;
cout << endl;
break;
default:
cout << "Invlaid choice!" << endl;
cout << endl;
cout << endl;
}
cout << "This program can calculate the area of a rectangle, the area of a circle, or volume of a cylinder." << endl;
cout << "To run the program enter: " << endl;
cout << "1: To find the area of rectangle." << endl;
cout << "2: To find the area of a circle." << endl;
cout << "3: To find the volume of a cylinder." << endl;
cout << "0: To terminate the program." << endl;
cin >> choice;
cout << endl;
}
return 0;
}