Calculate Area Using Function Overloading


Program to calculate area of circle,rectangle and triangle using 3 different function overloading in C++





#include<iostream.h>
#include<conio.h>
float area(float r)
{
          return(3.14*r*r);
}
float area(float c,float b,float h)
{
          return(b*h*c);
}
float area(float l,float b)
{
          return(l*b);
}
void main()
{
          float rad,base,ht;
          clrscr();
          float len,brdth;

          cout<<"\nEnter radius :";
          cin>>rad;
          cout<<"\nArea of circle :"<<area(rad);

          cout<<"\nEnter base and height :";
          cin>>base>>ht;
          cout<<"\nArea of triangle :"<<area(0.5,base,ht);

          cout<<"\nEnter length and breadth :";
          cin>>len>>brdth;
          cout<<"\nArea of rectangle :"<<area(len,brdth);

          getch();
}

OUTPUT

Enter radius :7
Area of circle :153.860001
Enter base and height :8 9
Area of triangle :36
Enter length and breadth :6 5
Area of rectangle :30


-----

Firoz Memon

Please view my other blogs:

          C++ Codes 4 Beginners

          Java Tips

          Java 4 Beginners

Previous Post Next Post