C++ language

Program To Calculate The Area Of Circle, Rectangle And Triangle
Previous Home Next

Example:

#include<stdio.h>
void main();
void area_circle();
void area_rect();
void area_tri();
void main()
{
int option;
{
do
menu();
cin>>option;
do
{
menu();
cin>>option;
switch(option)
{
case 1:
area_circle();
break;
case 2:
area_rect();
break;
case 3:
area_tri();
break;
}
}
while(option>3);
}
void menu()
{
cout<<"\n Menu";
cout<<"\n 1: Area of circle";
cout<<"\n 2: Area of rectangle";
cout<<"\n 3: Area of trangle";
cout<<"\n 4 or greater :Exit";
cout<<"\n Eneter your choice";
}
void area_circle()
{
int r;
cout<<"\n Enter radius";
cin>>r;
float area=3.14*r*r/4;
cout<<"\n area of circle"<<area;
}
void area_rect()
{
int a,b;
cout<<"\n enter sides";
cin>>a>>b;
int area=a*b;
cout<<"\narea of rectangle"<<area;
}
void area_triangle()
{
float s,a,b,c;
cout<<"\n enter sides";
cin>>a>>b>>c;
s=(a+b+c)/2
float area=s*(s-a)*(s-b)*(s-c);
cout<<"\n area of triangle"<<area;
}

Output:

Menu
1 : Area of circle
2 : Area of rectangle
3 : Area triangle
4 or greater Exit
Enter your choice
1
enter radius
4
Area of circle
12.56
Previous Home Next