-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq15.cpp
62 lines (55 loc) · 1.8 KB
/
q15.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
/* WAP to demonstrate the concept of function overloading. Make a menu-driven
* program using while loop and a switch case within it. */
#include <iostream>
#define PI 3.14
using namespace std;
float area(float radius) {
return PI * radius * radius;
}
float area(float length, float breadth) {
return length * breadth;
}
float area(float length, float breadth, float height) {
return 2*(length * breadth + breadth * height + height * length);
}
int main() {
int choice, running = 1;
float radius, length, breadth, height;
while (running) {
cout << "======== Pick an option ========" << endl;
cout << "\t1. Area of circle." << endl;
cout << "\t2. Area of rectangle." << endl;
cout << "\t3. Area of cuboid." << endl;
cout << "Your choice: ";
cin >> choice;
cout << "--------------" << endl;
switch (choice) {
case 1:
cout << "Enter radius: ";
cin >> radius;
cout << "Area : " << area(radius) << endl;
break;
case 2:
cout << "Enter length: ";
cin >> length;
cout << "Enter breadth: ";
cin >> breadth;
cout << "Area : " << area(length, breadth) << endl;
break;
case 3:
cout << "Enter length: ";
cin >> length;
cout << "Enter breadth: ";
cin >> breadth;
cout << "Enter height: ";
cin >> height;
cout << "Area : " << area(length, breadth, height) << endl;
break;
default:
running = 0;
cout << "Invalid option. Exiting..." << endl;
break;
}
}
return 0;
}