Function Overloading Function Overloading in C++: Add (Int A, Float B) Add (Float A, Int B) Add (Float A, Int B, Int C)
Function Overloading Function Overloading in C++: Add (Int A, Float B) Add (Float A, Int B) Add (Float A, Int B, Int C)
Here, we have two sum() function, first one gets two integer arguments and
second one gets two double arguments.
int main()
{
sum (10.5,20.5); // sum() with double parameters will be called
sum (10,20); // sum() with integer parameters will be called
}
29
Function overloading
/*08 Program to Find area of Circle, Triangle and Rectangle
using Function Overloading */
#include<iostream.h>
#include<conio.h>
int area(int,int);
float area(float);
float area(float,float);
int main()
{
int s,l,b;
float r,bs,ht;
cout<<"Enter radius of circle:";
cin>>r;
cout<<"Enter base and height of triangle:";
cin>>bs>>ht;
cout<<"Enter length and breadth of rectangle:";
cin>>l>>b;
area(r);
area(bs,ht);
area(l,b);
getch();
return 0;
}
int area(int l, int b)
{
cout<<"\nArea of circle = " <<l*b;
}
float area(float r)
{
cout<<"\nArea of triangle = " << 3.14*r*r;
}
float area(float bs,float ht)
{
cout<<"\nArea of rectangle = "<< (bs*ht)/2;
}
Output:
30