Overloading Fuction

Over loading function means that condition where we give the same function name and different argument. In the first example you will se we are using the function display and on second statement we have some argument within it.

 /*Function overloading example*/

#include<iostream>

using namespace std;

void display(){

cout<<"No argument function"<<endl;

}

void display(int a){

cout<<"Integer argument function"<<a<<endl;

}

int main(){

display();

display(23);

return 0;

}


Similarly here we will create a function named area and will use for rectangle, square and Circle. where we ill give a 'f' on the float denotation. 

/*Write a program to display area of rectangle, area of square and area of circle for each shape named area*/
#include<iostream>
using namespace std;
void area(int l, int b){
cout<<"Area of rectangle: "<<l*b<<endl;
}
void area(int l){
cout<<"Area of Square: "<<l*l<<endl;
}
void area(float r){
cout<<"Area of circle: "<<3.14*r*r<<endl;
}
int main(){
area(8,4);
area(7);
area(8.5f);

return 0;}




0 Comments had been done yet:

Post a Comment