Feedjit

Articles for you

Tuesday, December 31, 2013

Switch/Case in C++ easiest Implementation, C++ Burger Stand Program

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include<iostream>
using namespace std;
void ast();
class stand
{
private:
 int bun,shami,b,s;
public:


 
void init()
 {
  cout<<"Enter the total No. of burgers "<<endl;
  cin>>bun;
  cout<<endl;
  cout<<"Enter the total No. of shami   "<<endl;
  cin>>shami;
  cout<<endl;
 }
void sale()
 {
 if(bun<=0)
   cout<<"Sorry, no stock for burger"<<endl;
 else
  {cout<<"No. of burgers sold "<<endl;
  cin>>b;
  cout<<endl;
  bun=bun-b;
  }

 if(shami<=0)
   cout<<"Sorry, no stock for shami"<<endl;
 else
  {
  cout<<"No. of shami sold "<<endl;
  cin>>s;
  cout<<endl;
  
  shami=shami-s;
  }
 }
void disp()
 {
  if(bun<=0)
   cout<<"There is no stock for burger"<<endl;
  else
  cout<<"No. of burgers left "<<bun<<endl;

  if(shami<=0)
   cout<<"There is no stock for shami"<<endl;
  else
   cout<<"No. of shami left "<<shami<<endl;}
};
void ast()
 {
  for(int i=1;i<=9;i++)
  {cout<<"*";}
 }


void main()

{
 stand s1,s2,s3,s4;
 int ch,sl;
 char c;

  
  cout<<endl;
  cout<<"welcome to the burger shop"<<endl;
  ast();
do{cout<<endl;
  cout<<"Press 1 for stand# 01."<<endl;
  cout<<"Press 2 for stand# 02."<<endl;
  cout<<"Press 3 for stand# 03."<<endl;
  cout<<"Press 4 for stand# 04."<<endl;
  cout<<"Press 5 for exit"<<endl;
  cin>>ch;
  

switch(ch)
{
  case 1:
  cout<<"Stand no 1"<<endl;
   cout<<"Press 1 for initialization"<<endl;
   cout<<"Press 2 for sale"<<endl;
   cout<<"Press 3 for display"<<endl;
   cout<<"Press 4 for main menu"<<endl;

   cin>>sl;
   switch(sl)
   {
    case 1:
    s1.init();
    break;
    case 2:
    s1.sale();break;
    case 3:
    s1.disp();break;
       default:
     cout<<"Sorry! You have enterd an Invalid Choice"<<endl;break;

   } 
   break;
   

  case 2:
   cout<<"Stand no 2"<<endl;
   cout<<"Press 1 for initialization"<<endl;
   cout<<"Press 2 for sale"<<endl;
   cout<<"Press 3 for display"<<endl;
   cout<<"Press 4 for main menu"<<endl;
   cin>>sl;
   switch(sl)
   {
    case 1:
    s2.init();break;
    case 2:
    s2.sale();break;
    case 3:
    s2.disp();break;
    
    default:
     cout<<"Sorry! You have enterd an Invalid Choice"<<endl;break;
   } 
   break;
  case 3:
   cout<<"Stand no 3"<<endl;
   cout<<"Press 1 for initialization"<<endl;
   cout<<"Press 2 for sale"<<endl;
   cout<<"Press 3 for display"<<endl;
   cout<<"Press 4 for main menu"<<endl;
   cin>>sl;
   switch(sl)
   {
    case 1:
    s3.init();break;
    case 2:
    s3.sale();break;
    case 3:
    s3.disp();break;
    
     default:
     cout<<"Sorry! You have enterd an Invalid Choice"<<endl;break;
   }
   break;
  case 4:
   cout<<"Stand no 4"<<endl;
   cout<<"Press 1 for initialization"<<endl;
   cout<<"Press 2 for sale"<<endl;
   cout<<"Press 3 for display"<<endl;
   cout<<"Press 4 for main menu"<<endl;
   cin>>sl;
   switch(sl)
   {
    case 1:
    s4.init();break;
    case 2:
    s4.sale();break;
    case 3:
    s4.disp();break;
    
   }
   break;

   case 5:
    exit(0);break;
   default: 
    {cout<<endl<<"Sorry! You have enterd an Invalid Choice";break;}

}
cout<<endl;
cout<<"Do you want to continue: (Y/N)"<<endl;
   cin>>c;
  }while(c!='n' && c!='N');
}

Read More

Articles for you