-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethodoverloading.cpp
More file actions
60 lines (60 loc) · 1.18 KB
/
Copy pathmethodoverloading.cpp
File metadata and controls
60 lines (60 loc) · 1.18 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
#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 x, int a, int b)
{
cout<<"Area of triangle: "<<x*a*b<<endl;
}
int main()
{
int n,a,b;
fun obj;
cout<<"----------------METHOD OVERLOADING---------------"<<endl;
cout<<"1.Area of circle"<<endl;
cout<<"2.Area of rectangle"<<endl;
cout<<"3.Area of triangle"<<endl;
cout<<"4.Exit"<<endl;
while(1)
{
cout<<"Enter your choice: ";
cin>>n;
switch(n)
{
case 1:
cout<<"Enter radius of circle: ";
cin>>a;
obj.area(a);
break;
case 2:
cout<<"Enter length and breadth of rectangle: ";
cin>>a;cin>>b;
obj.area(a,b);
break;
case 3:
cout<<"Enter height and base of triangle: ";
cin>>a;cin>>b;
obj.area(0.5,a,b);
break;
case 4:
exit(0);
default:
cout<<"Wrong choice"<<endl;
break;
}
}
}