Write a C++ program to find area of triangle, circle, and rectangle using function overloading.


#include<iostream.h>
#include<conio.h>

void area(int r)
{
  cout<<endl<<"Area of circle="<<3.142*r*r;
}

void area(int b,int h)
{
  cout<<endl<<"Area of triangle="<<0.5*b*h;
}

void area(float l,float b)
{
  cout<<endl<<"Area of rectangle="<<l*b;
}

int main()
{
  int r,b,h;
  float l,br;
  clrscr();
  cout<<endl<<"Enter radius of circle: ";
  cin>>r;
  area(r);
  cout<<endl<<"Enter base and height of triangle: ";
  cin>>b>>h;
  area(b,h);
  cout<<endl<<"Enter length and breadth of rectangle: ";
  cin>>l>>br;
  area(l,br);
  getch();
  return 0;
}

No comments:

Post a Comment