-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram64.cpp
72 lines (63 loc) · 1.59 KB
/
Program64.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
/*PROGRAM USING COMPILE TIME POLYMORPHISM (FUNCTION OVERLOADING)*/
#include <iostream>
#include <cstdlib>
#include <conio.h>
#define pi 3.14
class Areacalculate
{
public:
void area(int); // circle
void area(int, int); // rectangle
void area(float, int, int); // triangle
};
void Areacalculate::area(int a)
{
std::cout << "Area of circle: " << pi * a * a;
}
void Areacalculate::area(int a, int b)
{
std::cout << "Area of rectangle: " << a * b;
}
void Areacalculate::area(float t, int a, int b)
{
std::cout << "Area of triangle: " << t * a * b;
}
int main()
{
int ch;
int a, b, r;
char choice;
Areacalculate obj;
std::cout << "\n\t\t Function overloading ";
do
{
std::cout << "\n1. Area of circle\n2. Area of rectangle\n3. Area of Triangle\n4. Exit\nEnter your choice: ";
std::cin >> ch;
switch (ch)
{
case 1:
std::cout << "Enter Radius of the circle: ";
std::cin >> r;
obj.area(r);
break;
case 2:
std::cout << "Enter sides of the rectangle: ";
std::cin >> a >> b;
obj.area(a, b);
break;
case 3:
std::cout << "Enter sides of the triangle: ";
std::cin >> a >> b;
obj.area(0.5, a, b);
break;
case 4:
exit(0);
default:
std::cout << "Invalid choice!";
}
std::cout << "\nDo you want to continue? (y/n): ";
std::cin >> choice;
} while (choice == 'y' || choice == 'Y');
getch();
return 0;
}