C++ Menu Driven Program with Area, Perimeter and Volume
#include<iostream>
#define pi 3.14
using namespace std;
int main()
{
int ch,ch1;
float r,l,b,w,h,s,a,s1,s2,area,peri,vol;
system("cls");
cout<<"===========================================\n";
cout<<"\tMenu Of Programs | Nested Switch\n";
cout<<"===========================================\n";
cout<<"1. Area Programs\n";
cout<<"2. Perimeter programs\n";
cout<<"3. Volume Programs\n";
cout<<"Enter your Choice :";
cin>>ch;
switch(ch)
{
case 1:
system("cls");
cout<<"===========================================\n";
cout<<"\t\tMenu of Area Programs\n";
cout<<"===========================================\n";
cout<<"1.Circle\n";
cout<<"2.Rectangle\n";
cout<<"3.Square\n";
cout<<"4.Triangle\n";
cout<<"Enter Your choice :";
cin>>ch1;
switch(ch1)
{
case 1:
cout<<"===================================\n";
cout<<"\t\tArea Of Circle :\n";
cout<<"===================================\n";
cout<<"Enter Radius OF circle :";
cin>>r;
area=pi*r*r;
cout<<"Are Of Circle with "<<r<<" Radius is "<<area<<endl;
break;
case 2:
cout<<"===================================\n";
cout<<"\t\tArea Of Rectangle\n";
cout<<"===================================\n";
cout<<"Enter Length Of Rectangle :";
cin>>l;
cout<<"Enter the breadth Of Rectangle :";
cin>>b;
area=l*b;
cout<<"The Area Of Rectangle with Length "
<<l<<", And breadth "<<b<<" is "<<area<<endl;
break;
case 3:
cout<<"===================================\n";
cout<<"\t\tArea of Square\n";
cout<<"===================================\n";
cout<<"Enter Side of square :";
cin>>s;
area=s*s;
cout<<"The Area of Square with "<<s<<" side is "
<<area<<endl;
break;
case 4:
cout<<"===================================\n";
cout<<"\t\tArea Of Triangle\n";
cout<<"===================================\n";
cout<<"Enter the Base Of Triangle :";
cin>>b;
cout<<"Enter the Height Of Triangle";
cin>>h;
area=0.5*b*h;
cout<<"The Area of Triangle With Base "<<b<<" And "
<<"Height "<<h<<" Is "<<area<<endl;
break ;
default:
cout<<"Invalid Choice!!!\n";
break;
}
break;
case 2:
system("cls");
cout<<"===================================\n";
cout<<"\tMenu Of Perimeter Programs\n";
cout<<"===================================\n";
cout<<"1. Circle\n";
cout<<"2. Square\n";
cout<<"3. Rectangle\n";
cout<<"4. Triangle\n";
cout<<"Enter Your Choice :";
cin>>ch1;
switch(ch1)
{
case 1:
cout<<"\n===================================\n";
cout<<"Perimeter Of Circle";
cout<<"\n===================================\n";
cout<<"Enter Radius OF Circle :";
cin>>r;
peri=2*pi*r;
cout<<"The Circumferance of Circle with Radius "
<<r<<" Is "<<peri<<endl;
break;
case 2:
cout<<"===================================\n";
cout<<"\t Perimeter of Rectangle ";
cout<<"===================================\n";
cout<<"Enter Side Of Square : ";
cin>>s;
peri=s*4;
cout<<"The Perimeter OF Square with "<<s<<" Side is"
<<peri<<endl;
break;
case 4:
cout<<"===================================\n";
cout<<"Perimeter Of Triangle";
cout<<"===================================\n";
cout<<"Enter Base Of Triangle :";
cin>>b;
cout<<"Enter The Side 1 Of Triangle :";
cin>>s1;
cout<<"Enter The Side 2 Of Triangle :";
cin>>s2;
peri=s1+s2+b;
cout<<"The Perimeter Of Triangle with "
<<b<<" base,\n"<<s1<<" Side 1 and "
<<s2<<"Side 2 is "<<peri<<endl;
break;
default:
cout<<"Invalid Choice!!!\n";
break;
}
break;
case 3:
system("cls");
cout<<"===================================\n";
cout<<"\t\tMenu Of Volume Programs\n";
cout<<"===================================\n";
cout<<"1. Sphere\n";
cout<<"2. Cuboid\n";
cout<<"3. Cube\n";
cout<<"4. Triangular Pyramid\n";
cout<<"Enter Your Choice :";
cin>>ch1;
switch(ch1)
{
case 1:
cout<<"\n===================================\n";
cout<<"\t\tVolume Of Cuboid";
cout<<"===================================\n";
cout<<"Enter Radius Of Sphere :";
cin>>r;
vol=4.0/3.0*pi*r*r*r;
cout<<"The Volume of Sphere With Radius "
<<r<<" Is "<<vol<<endl;
break;
case 2:
cout<<"\n===================================\n";
cout<<"\t\tVolume Of Cuboid";
cout<<"\n===================================\n";
cout<<"Enter Length Of Rectangle :";
cin>>l;
cout<<"Enter Width Of Rectangle :";
cin>>w;
cout<<"Enter Height Of Rectangle :";
cin>>h;
vol=l*w*h;
cout<<"The Volume Of Rectangle With "
<<l<<" Length ,\n"<<w<<" Width and "
<<h<<", and Height is "<<vol<<endl;
break;
case 3:
cout<<"\n===================================\n";
cout<<"\t\tVolume Of Cube";
cout<<"\n===================================\n";
cout<<"Enter side Of Cube";
cin>>s;
vol=s*3;
cout<<"The Volume of Cube With "
<<s<<" Side is "<<vol<<endl;
break;
case 4:
cout<<"===================================\n";
cout<<"\t\tVolume Of Triangular Pyramid";
cout<<"===================================\n";
cout<<"Enter The Apothem Length :";
cin>>a;
cout<<"Enter THe Side Length :";
cin>>s;
cout<<"Enter the Height :";
cin>>h;
vol=a*s*h/6;
cout<<"The Volume of Triangle with "
<<a<<" Apothem Length, \n"
<<s<<" Side Length and "
<<h<<" Height Is "<<vol<<endl;
break;
default :
cout<<"Invalid Choice !!!\n";
break;
}
break;
}
return 0;
}
Comments
Post a Comment