Pages

Friday 18 March 2011

PROGRAM OF FUNCTION OVERLOADING

DESCRIPTION-:IN Function overloading we use same function name for multiple purpose.Thus in function defination we have same function name the only difference is the arguments or parameters.The arguments pass in program defination is different and if we have same arguments in two function definitions then it will generate the error.
Following is the program of the function overloading which calculate the area of square,rectangle and triangle.
In this we have same function name"area" but arguments pass to them are different.
PROGRAM-:
#include<iostream.h>
#include<conio.h>
#include<math.h>
void area(int);
void area(int,int);
void area(int,int,int);
void main()
{
clrscr();
float a,b,c,le,br,side;
cout<<"enter the side of square";
cin>>side;
cout<<"enter length and breadth of rectangle";
cin>>le>>br;
cout<<"enter parameter a,b,c of traingle";
cin>>a>>b>>c;
area(side);
area(le,br);
area(a,b,c);
getch();
}
void area(int x)
{
int a;
a=x*x;
cout<<"area of square is"<<a<<"\n";
}
void area(int x,int y)
{
int b;
b=x*y;
cout<<"area of rectangle is"<<b<<"\n";
}
void area(int x,int y,int z)
{
float s=(x+y+z)/2;
float ar;
ar=sqrt(s*(s-x)*(s-y)*(s-z));
cout<<"area of triangle using HERO formula is"<<ar;
}

0 comments:

Post a Comment

 
Copyright (c) 2010 Concepts Of C++. Design by WPThemes Expert

Blogger Templates and RegistryBooster.