Sunday, November 24, 2013

Menu Driven Program

Menu Driven Program

Output


Code:


#include<iostream>
#include<cstdlib>
#include<conio.h>
using namespace std;
int alpha;
char beta;
float side,length,width,side1,side2,side3,base,height,area;
void main()
{
    while(beta!='n')
 {

  
 label1:cout<<" press any key of your choice:\n\n"<<endl;
 cout<<"1: Perimeter Calculation"<<endl;
 cout<<"2: Area Calculation"<<endl;
 cout<<"3: Volume Calculation"<<endl;
 cout<<"4: Exit"<<endl;
 cin>>alpha;
  
 switch(alpha)
 {
  case 1:
   {    
    system("cls");
   cout<<"Press any key of your choice"<<endl;
   cout<<"1: Perimeter of a square"<<endl;
   cout<<"2: Perimeter of a rectangle"<<endl;
   cout<<"3: Perimeter of a triangle"<<endl;
   cout<<"4: Back to the Main menu"<<endl;
   cout<<"5: Exit"<<endl;
   cin>>alpha;

   switch(alpha)
   {
    case 1:
   {
    system("cls");
    
    cout<<"enter side of square:";
    cin>>side;
    cout<<"perimeter of square="<<4*side<<endl;
   } 
   break;
  
   case 2:
   {
    system("cls");
    cout<<"enter length of rectangle:";
    cin>>length;
    cout<<"enter width of rectangle:";
    cin>>width;
    cout<<"perimeter of rectangle is="<<2*(length+width)<<endl;
   }
   break;
  
   case 3:
   {
    system("cls");
    cout<<"enter sides of triangle:";
    cin>>side1>> side2>> side3;
    cout<<"perimeter of triangle is="<<side1+side2+side3<<endl;
   }
   break;

   case 4:
   {
    system("cls");
    goto label1;
   }
   break;

   case 5:
   {
    exit(alpha);
   }
   break;
    }
   } 
  break;

 case 2:
 {
  system("cls");
  cout<<" Press any key of your choice"<<endl;
  cout<<"1: Area of a square"<<endl;
  cout<<"2: Area of a rectangle"<<endl;
  cout<<"3: Area of a triangle"<<endl;
  cout<<"4: Back to the Main menu"<<endl;
  cout<<"5: Exit"<<endl;
  cin>>alpha;

  switch(alpha)
  {
   case 1:
   {
    system("cls");
    cout<<"Enter side of square:";
    cin>>side;
    cout<<"Area of square is="<<side*side<<endl;
   }
   break;

   case 2:
   {
    system("cls");
    cout<<"Enter length of rectangle:";
    cin>>length;
    cout<<"Enter width of rectangle:";
    cin>>width;
    cout<<"Area of rectangle="<<length*width<<endl;
   }
   break;
   
   case 3:
   {
    system("cls");
    cout<<"enter base and height of triangle:";
    cin>>base>> height;
    cout<<"Area of triangle is="<<1/2*(base*height)<<endl;
   }
   break;

   case 4:
   {
    system("cls");
    goto label1;
   }
   break;

   case 5:
   { 
    exit(alpha);
   }
   break;
   }
  }
  break;


 case 3:
 {
  system("cls");
  cout<<" Press any key of your choice"<<endl;
  cout<<"1: Volume of a cube"<<endl;
  cout<<"2: Volune of a box"<<endl;
  cout<<"3: Volume of a prism"<<endl;
  cout<<"4: Back to the Main menu"<<endl;
  cout<<"5: Exit"<<endl;
  cin>>alpha;
  switch(alpha)
  {
  case 1:
  {
   system("cls");
   cout<<"Enter side of cube:";
   cin>>side;
   cout<<"Volume of square is="<<side*side*side<<endl;
  }
   break;
  
  case 2:
  {
   system("cls");
   cout<<"enter length of box:";
   cin>>length;
   cout<<"enter width of box:";
   cin>>width;
   cout<<"enter height of box:";
   cin>>height;
   cout<<"Volume of box is:="<<length*width*height<<endl;
  }
  break;

  case 3:
  {
   system("cls");
   cout<<"enter area of prism:";
   cin>>area;
   cout<<"enter length of prism:";
   cin>>length;
   cout<<"Volume of prism="<<area*length<<endl;
  }
  break;

  case 4:
  {
   system("cls");
   goto label1;
  }
  break;

  case 5:
  {
   exit(alpha);
  }
  break;

 }
  }
 break;

 case 4:
 {
  exit(alpha);
 }
 break;
 }

 cout<<"Do you want to continue:(y/n)"<<endl;
 cin >> beta;
system("cls");
 
 }
}
 

Widgets

 

Copyright @ 2014 CPP Fuzz.