//Downloaded From theonlinetutorials.com
//Function Overloading to calculate the area of a circle,rectangle and triangle
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
void area(float r)
{
float area;
cout<<"\nArea:"<<(3.14*r*r);
}
void area(float l,float b)
{
float area ;
cout<<"\nArea:"<<l*b;
}
void area(float x,float y,float z)
{
float s;
s=(x+y+z)/2;
cout<<"\nArea:"<<sqrt(s*s-x*s-y*s-z);
}
void main()
{
clrscr();
int opt,x,y,z,l,b,r;
char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"\nMENU\n\n1.Area of circle\n2.Area of Rectangle\n3.Area of Triangle";
cout<<"\nEnter your Option:";
cin>>opt;
switch(opt)
{
case 1:cout<<"\nEnter radius of the circle:";
cin>>r;
area(r);
break;
case 2:cout<<"\nEnter the length and breadth of the rectangle:";
cin>>l>>b;
area(l,b);
break;
case 3:cout<<"\nEnter side 1:";
cin>>x;
cout<<"\nEnter side 2:";
cin>>y;
cout<<"\nEnter side 3:";
cin>>z;
area(x,y,z);
break;
default:cout<<"Wrong Option!!";
}
cout<<"\nDo you wnat to continue?(Y/N):";
cin>>ch;
}
getch();
}
Not Satisfied ? Just search & get the result
Related posts:
- C program to accept a figure code and find the ares of different geometrical figures such as circle, square, rectangle etc using switch
- C++ program – Swap two variables using function overloading
- C++ program – Perform arithmetic operations of two complex numbers using operator overloading
- C++ Program – Calculator
- C++ Program – Binary File Handling
