Monday, May 15, 2017

Program to find Area of Circle, Square and Rectangle using Switch Case in C++

Description:

Here the solution of finding area of Circle, Square and Rectangle in c++ using Switch case Method.

Program:


#include
#include

void area()
{
//squre
int l,ans;
cout<<"\nEnter length of square:";
cin>>l;
ans=l*l;
cout<<"\n area of square is "<}

void area(int l,int b)
{
//Rectangle
int ans;
ans=l*b;
cout<<"\n area of rectangle is "<}

float area(int t)
{
//Circle
float r,ans;
cout<<"\nEnter radius of circle:";
cin>>r;
ans=(3.14)*r*r;
return ans;
}

float area(float h,int b)
{
//Triangle
float ans;
ans=(0.5)*h*b;
return ans;
}

void main()
{
int ch,b,l;
float h;
clrscr();

cout<<"\nEnter \n1-Square \n2-Rectangle \n3-Circle \n4-Triangle\n";
cout<<"\nEnter your choice:";
cin>>ch;

switch(ch)
{
case 1:area();
break;
case 2:cout<<"\nEnter length of rectangle:";
cin>>l;
cout<<"\nEnter breadth of rectangle:";
cin>>b;
area(l,b);
break;
case 3: cout<<"\nThe area of circle is "< break;
case 4:cout<<"\nEnter the height of triangle:";
cin>>h;
cout<<"\nEnter the breadth of triangle:";
cin>>b;
cout<<"\nThe area of triangle is "< break;
default:(0);
break;
}
getch();
}

No comments:

Post a Comment