-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethodoverloading1.cpp
More file actions
66 lines (62 loc) · 1.25 KB
/
methodoverloading1.cpp
File metadata and controls
66 lines (62 loc) · 1.25 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<iostream>
#define pi 3.14
using namespace std;
class fun
{
public:
void area(int); //area of circle
void area(int,int); //area of rectangle
void area(float,int,int); //area of triangle
};
void fun::area(int a)
{
cout << "Area of Circle = " << pi*a*a << endl;
}
void fun::area(int a,int b)
{
cout << "Area of Rectangle = " << a*b << endl;
}
void fun::area(float t,int a,int b)
{
cout << "Area of Triangle = " << t*a*b << endl;
}
int main()
{
int ch,r,l,b,h;
fun obj;
cout << "----METHOD OVERLOADING----\n\n" << endl;
cout << "1. Circle" << endl << "2. Rectangle" << endl << "3. Triangle" << endl << "4. Exit" << endl;
while(1)
{
cout << "Enter your choice : ";
cin >> ch;
switch(ch)
{
case 1:
cout << "Radius of circle : ";
cin >> r;
obj.area(r);
break;
case 2:
cout << "Length of rectangle : ";
cin >> l;
cout << "Breadth of rectangle : ";
cin >> b;
obj.area(l,b);
break;
case 3:
cout << "Base of triangle : ";
cin >> b;
cout << "Height of triangle : ";
cin >> h;
obj.area(0.5,b,h);
break;
case 4:
exit(0);
break;
default:
cout << "Enter correct choice." << endl;
}
}
return 0;
}