Program to calculate area of a circle, rectangle, scalene triangle using function overloading | C++ Programming
Float Saturday, February 29, 2020//program to calculate area of a circle,rectangle,scalene triangle using function overloading
#include<iostream.h>
#include<conio.h>
#include<math.h>
void area(float r)
{ cout<<"\nArea of triangle is :"
<<(4* 3.14*r);
}
void area(int L, int B)
{ cout<<"\nArea of rectangle is :"
<<(L*B);
}
void area(float a, float b, float c)
{float s=(a+b+c)/2;
cout<<"\nArea of scalene triangle is :"
<<sqrt(s*(s-a)*(s-b)*(s-c));
}
void main()
{
clrscr();
int L,B;
float r,a,b,c;
int ch;
cout<<"\n Press 1 to calculate area of circle.";
cout<<"\n Press 2 to calculate area of rectangle.";
cout<<"\n Press 3 to calculate area of scalene triangle.";
cout<<"\n Enter your choice: ";
cin>>ch;
if(ch==1)
{ cout<<"\n Enter radius of the circle: ";
cin>>r;
area(r);
}
else if(ch==2)
{ cout<<"\n Enter length & breadth of the rectangle: " ;
cin>>L>>B;
area(L,B);
}
else if(ch==3)
{ cout<<"\n Enter three sides of the triangle : ";
cin>>a>>b>>c;
area(a,b,c);
}
else
cout<<"\n You have entered wrong choice!!!!";
getch();
}
#include<iostream.h>
#include<conio.h>
#include<math.h>
void area(float r)
{ cout<<"\nArea of triangle is :"
<<(4* 3.14*r);
}
void area(int L, int B)
{ cout<<"\nArea of rectangle is :"
<<(L*B);
}
void area(float a, float b, float c)
{float s=(a+b+c)/2;
cout<<"\nArea of scalene triangle is :"
<<sqrt(s*(s-a)*(s-b)*(s-c));
}
void main()
{
clrscr();
int L,B;
float r,a,b,c;
int ch;
cout<<"\n Press 1 to calculate area of circle.";
cout<<"\n Press 2 to calculate area of rectangle.";
cout<<"\n Press 3 to calculate area of scalene triangle.";
cout<<"\n Enter your choice: ";
cin>>ch;
if(ch==1)
{ cout<<"\n Enter radius of the circle: ";
cin>>r;
area(r);
}
else if(ch==2)
{ cout<<"\n Enter length & breadth of the rectangle: " ;
cin>>L>>B;
area(L,B);
}
else if(ch==3)
{ cout<<"\n Enter three sides of the triangle : ";
cin>>a>>b>>c;
area(a,b,c);
}
else
cout<<"\n You have entered wrong choice!!!!";
getch();
}