Function overloading means, two or more functions have the same names but different argument lists.
The arguments may differ in the type of arguments or number of arguments, or both.
However, the return types of overloaded methods can be the same or different is called function overloading.
Function overloading conceptshelps us to use the same function names multiple time in the same program.
Following program demonstrates the overloaded function to find the area of the circle, rectangle, and square.
#include
using namespace std;
int area(int x)
{
return x*x;
}
int area(int l, int b)
{
return l*b;
}
double area(double r)
{
return 3.142*r*r;
}
int main()
{
int x, l, b;
double r;
cout<<"Enter the length of a square: ";
cin>>x;
cout<<"Enter the length of rectangle: ";
cin>>l;
cout<<"Enter the width of rectangle: ";
cin>>b;
cout<<"Enter the radius of circle: ";
cin>>r;
cout<
OUTPUT:
Enter the length of a square: 10
Enter the length of rectangle: 10
Enter the width of rectangle: 15
Enter the radius of circle: 5.5
The area of square is 100
The area of rectangle is 150
The area of circle is 95.0455