-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOver_loading_of_function.cpp
63 lines (61 loc) · 1.78 KB
/
Over_loading_of_function.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
/* author: jaydattpatel
working of function overloading
If The class has same name of different function with different arguments in same scope then it is called function overloading.
*/
#include<iostream>
#include<math.h>
using namespace std;
#define pi 3.14
class Areacalculate
{
public:
void area(float a)
{
cout<<"Area of Circle:"<<pi*a*a;
}
void area(float a,float b)
{
cout<<"Area of rectangle:"<<a*b;
}
void area(float a,float b,float c)
{
float area;
float s = (a+b+c)/2;
area = sqrt((s*(s-a)*(s-b)*(s-c)));
cout<<"Area of triangle:"<<area;
}
};
int main()
{
int ch;
float a,b,c,r;
Areacalculate Area;
cout<<"\n\t\tFunction Overloading";
while(1)
{
cout<<"\n\n1.Area of Circle\t2.Area of Rectangle\t3.Area of Triangle\t4.Exit\n";
cout<<"Enter your Choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter Radious of the Circle:";
cin>>r;
Area.area(r);
break;
case 2:
cout<<"\nEnter Two Sides of the Rectangle:";
cin>>a>>b;
Area.area(a,b);
break;
case 3:
cout<<"\nEnter Three Sides of the Triangle:";
cin>>a>>b>>c;
Area.area(a,b,c);
break;
case 4:
exit(0);
}
}
return 0;
}