Function Overloading


 Function Overloading - 

" Multiple Definition of a function with in same scope having different signature are called Function Overloading   "


Signature of a function- Number & Type of a parameter of a function is called signature of the function.






Question - Write an overloaded function area which will print the area of circle,rectangle and square.

Program -


#include<iostream>
using namespace std;

//function prototype 
int area(int);
int area (int,int);
double area (double);

int main(){

cout<<"Calling area with 5cm side : "<<area(5)<<endl;
cout<<"calling area with l=5,b=10 : "<<area(5,10)<<endl;
  cout<<"calling area with 5.5cm radius : "<<area(5.5);
return 0;


//Area of square 
int area (int side){
return (side*side);
}

//area of rectangle
int area(int length ,int breadth){
return (length * breadth);


//area of circle 
double area (double radius){
return (3.14*radius*radius);
}



Output -







By - Somesh Sah













Comments

Popular posts from this blog

Include Vs Import

Object Oriented Program (Paradigm)

Operators and Expressions