Menu Driven Program for Area of various figures in C++

#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<math.h>
float area(float);
float area(float,float);
float area(float,float,float);
void main()
{
float a,b,c,s,ar;
int ch;
clrscr();
while(1)
{
cout<<"\nYou can chose from the following options:"<<endl;
cout<<"Press 1: Area of Square"<<endl;
cout<<"Press 2: Area of Rectangle"<<endl;
cout<<"Preaa 3: Area of Triangle"<<endl;
cout<<"Press 4: Exit"<<endl;
cout<<"Please Enter Your choice(1-4):";
cin>>ch;
switch (ch)
{
case 1:
cout<<"Please Enter the Side of the Square:";
cin>>a;
ar=area(a);
break;
case 2:
cout<<"Please enter the Length and Breadth of the Rectangle:";
cin>>a>>b;
ar=area(a,b);
break;
case 3:
cout<<"Please enter three sides of the Triangle:";
cin>>a>>b>>c;
ar=area(a,b,c);
break;
case 4:
exit(0);
default:
cout<<"Wrong Choice!! Please Enter the choice between 1 and 4"<<endl;
}
cout<<"Area of the given figure is: "<<ar;
cout<<"\nPreaa any key to continue...";
getch();
}
}
float area(float s)
{
return s*s;
}
float area(float l, float b)
{
return l*b;
}
float area(float a, float b, float c)
{
float s, ar;
s=(a+b+c)/2;
ar=sqrt(s*(s-a)*(s-b)*(s-c));
return ar;
}

Comments

Popular posts from this blog

Program for calculating Simple Interest using the concept of Default Arguments

Data communication Terminology

Program for Checking whether the given number is Palindrome or not