Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

TOPIC

: Calculate the area of some basic shapes

AIM: Users select the shape, and then enter the values used to calculate the area of the
shapes
Code:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#define pi 3.14
#define half (0.5)
void rect()
{
float width, breadth,Area;
cout<<"Enter the width and breadth of a rectangle to calculate its area\n";
cout<<"The formula of the area of a rectangle is \n\t width * breadth\n";
cout<<"Enter\n"<<"Width =>>";
cin>>width;
cout<<"Breadth =>>";
cin>>breadth;
Area=width*breadth;
cout<<" the area of the rectangle with width of "<<width<< " cm" << " and ";
cout<<"breadth of" << breadth<<" cm = "<<Area;
getch();
}
void square()
{
float width, breadth,Area;
cout<<"Enter the width and breadth of a square to calculate its area\n";
cout<<"The formula of the area of a square is \n\t width * breadth\n";
cout<<"Enter\n"<<"Width =>>";
cin>>width;
cout<<"Breadth =>>";
cin>>breadth;
Area=width*breadth;
cout<<" the area of the square with width of "<<width<< " cm" << " and ";
cout<<"breadth of" << breadth<<" cm = "<<Area;
getch();
}
void cir()
{
float r,Area;
cout<<"Please enter the radius of a circle to determine its area\n";
cout<<"Radius =>>";
cin>>r;
cout<<"Formula for area of circle is \n\t pii * radius^2\n";

Area= pi * (r*r);
cout<<"Area of circle of radius "<<r << "=>" <<Area;
getch();
}
void cylin()
{
float h,r,area,volume;
cout<<"Enter the height and radius respectively to calculate its area \n";
cout<<"Height = >>";
cin>>h;
cout<<"Radius =>>";
cin>>r;
area=pi * (r*r);
cout<<"Area of circle ="<<pi<<" * "<<r<<"^2 * "<<h<<" = " <<area;
}
void tri()
{
float b,h,Area;
cout<<"Enter the base and height of a triangle for its area to be calculated\n";
cout<<"Formula for Area of triangle is\n\t 1/2 base * Height\n";
cout<<"Base =>>";
cin>>b;
cout<<"Height =>>";
cin>>h;
Area=(half*b)*h;
cout<<"The area of the triangle with Base of "<<b<< " cm";
cout<<" and height of "<< h<<" cm ="<<Area;
getch();
}
void main()
{
char opt;
clrscr();
again:
cout<<"Select one of the following shapes to perform calculation relating to them\n";
cout<<"a. Circle"<<"\n b.Triangle"<<"\n c.Square"<<"\n d.Rectangle"<<"\n
opt=getch();
switch (opt)
{
case 'a'| 'A':
cir();
break;
case 'b'| 'B':
tri();
break;
case 'c'| 'C':

square();
break;
case 'd'| 'D':
rect();
break;
case 'e'| 'E':
cylin();
break;
case 'f'| 'F':
exit(1);
break;
default:
cout<<"Please check the list of shapes and choose the right option\n";
goto again;
break;
}
cout<<"Do you want to perform another operation[Y\\N]\n";
cin>>opt;
if (opt=='Y'||opt=='y')
{
goto again;
}
else
{
exit(1);
}
}
Output
Select one of the following shapes to perform calculation relating to them
a. Circle
b.Triangle
c.Square
d.Rectangle
e.Exit
Please enter the radius of a circle to determine its area
Radius =>>2
Formula for area of circle is
pii * radius^2
Area of circle of radius 2=>12.56

You might also like