-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharea_of_shapes_usong_switch.cpp
More file actions
46 lines (38 loc) · 1.01 KB
/
Copy patharea_of_shapes_usong_switch.cpp
File metadata and controls
46 lines (38 loc) · 1.01 KB
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
#include <iostream>
const float PI = 3.14;
void calculateArea(std::string shape)
{
/* Comparing first character of shape string */
switch (shape[0]) {
case 'c':
float r;
std::cout << "\nEnter the radius ";
std::cin >> r;
std::cout << "\nArea of Circle : " << PI * r * r
<< " square units" << std::endl;
break;
case 's':
float a;
std::cout << "\nEnter the side length ";
std::cin >> a;
std::cout << "\nArea of Square : " << a * a
<< " square units" << std::endl;
break;
case 'r':
float b, h;
std::cout << "\nEnter the breadth ";
std::cin >> b;
std::cout << "\nEnter the height ";
std::cin >> h;
std::cout << "\nArea of Rectangle : " << b * h
<< " square units" << std::endl;
break;
}
}
int main()
{
std::string s;
std::cout << "Enter the shape : ";
getline(std::cin, s);
calculateArea(s);
}