本文实例为大家分享了C语言点餐系统的具体代码,供大家参考,具体内容如下
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
#include<iostream>
#include<fstream>
#include<string>
#include<conio.h>
using namespace std;
class shiwu
{
public :
string mingzi;
int price;
shiwu(){}
shiwu(string n, int p):mingzi(n),price(p){}
};
shiwu zhucan[3]={shiwu( "大汉堡" ,13),shiwu( "烤肉饭" ,13),shiwu( "鸡肉卷" ,11)};
shiwu fushi[3]={shiwu( "麻辣鸡钉" ,9),shiwu( "劲爆鸡米花" ,9),shiwu( "大薯条" ,6)};
shiwu drink[3]={shiwu( "可口可乐" ,5),shiwu( "拿铁咖啡" ,6),shiwu( "热牛奶" ,6)};
class Taocan
{
public :
string mingzi;
shiwu tc[3];
int price;
Taocan(){}
Taocan(string n,shiwu a,shiwu b,shiwu c)
{
mingzi=n;
tc[0]=a;
tc[1]=b;
tc[2]=c;
price=a.price+b.price+c.price-10;
}
};
Taocan taocan[3]={Taocan( "鸡腿鸡翅套餐" ,zhucan[0],fushi[0],drink[0]),Taocan( "鳕鱼鸡米花套餐" ,zhucan[1],fushi[1],drink[0]),Taocan( "鸡肉卷薯条套餐" ,zhucan[2],fushi[2],drink[0])};
shiwu myshiwu[13];
int mymoney;
int mynum=0;
void write()
{
ofstream f( "list.txuant" );
int i;
f << "KFC消费清单\n" ;
for (i=0;i<mynum;i++)
f<<i+1<< "、" <<myshiwu[i].mingzi<< " 价格:" <<myshiwu[i].price<<endl;
f<< "总价格、" <<mymoney<<endl;
f<<endl<<endl;
f.close();
system ( "list.txuant" );
}
void xuanzhucan()
{
void Menu();
void Diancan();
system ( "cls" );
cout<< "1、" <<zhucan[0].mingzi<< " 价格:" <<zhucan[0].price<<endl;
cout<< "2、" <<zhucan[1].mingzi<< " 价格:" <<zhucan[1].price<<endl;
cout<< "3、" <<zhucan[2].mingzi<< " 价格:" <<zhucan[2].price<<endl;
cout<< "4、返回" <<endl;
char c;
c=getch();
switch (c)
{
case '1' : myshiwu[mynum]=zhucan[0];mymoney+=zhucan[0].price;mynum++; break ;
case '2' : myshiwu[mynum]=zhucan[1];mymoney+=zhucan[1].price;mynum++; break ;
case '3' : myshiwu[mynum]=zhucan[2];mymoney+=zhucan[2].price;mynum++; break ;
case '4' : Diancan(); break ;
default :
printf ( "\n您的按键有误,按任意键重新选择!\n" );
getch();
xuanzhucan();
}
printf ( "\n点餐成功!请按任意键继续点餐或者返回!\n" );
getch();
if (mynum>10)
{
cout<< "您本次点餐已经达到上限!如果需要!请结算后继续点餐!" <<endl;
printf ( "\n按任意键进入菜单!\n" );
getch();
Menu();
}
else xuanzhucan();
}
void xuanfushi()
{
void Menu();
void Diancan();
system ( "cls" );
cout<< "1、" <<fushi[0].mingzi<< " 价格:" <<fushi[0].price<<endl;
cout<< "2、" <<fushi[1].mingzi<< " 价格:" <<fushi[1].price<<endl;
cout<< "3、" <<fushi[2].mingzi<< " 价格:" <<fushi[2].price<<endl;
cout<< "4、返回" <<endl;
char c;
c=getch();
switch (c)
{
case '1' : myshiwu[mynum]=fushi[0];mymoney+=fushi[0].price;mynum++; break ;
case '2' : myshiwu[mynum]=fushi[1];mymoney+=fushi[1].price;mynum++; break ;
case '3' : myshiwu[mynum]=fushi[2];mymoney+=fushi[2].price;mynum++; break ;
case '4' : Diancan(); break ;
default :
printf ( "\n您的按键有误,按任意键重新选择!\n" );
getch();
xuanfushi();
}
printf ( "\n点餐成功!请按任意键继续点餐或者返回!\n" );
getch();
if (mynum>10)
{
cout<< "您本次点餐已经达到上限!如果需要!请结算后继续点餐!" <<endl;
printf ( "\n按任意键进入菜单!\n" );
getch();
Menu();
}
else xuanfushi();
}
void xuandrink()
{
void Menu();
void Diancan();
system ( "cls" );
cout<< "1、" <<drink[0].mingzi<< " 价格:" <<drink[0].price<<endl;
cout<< "2、" <<drink[1].mingzi<< " 价格:" <<drink[1].price<<endl;
cout<< "3、" <<drink[2].mingzi<< " 价格:" <<drink[2].price<<endl;
cout<< "4、返回" <<endl;
char c;
c=getch();
switch (c)
{
case '1' : myshiwu[mynum]=drink[0];mymoney+=drink[0].price;mynum++; break ;
case '2' : myshiwu[mynum]=drink[1];mymoney+=drink[1].price;mynum++; break ;
case '3' : myshiwu[mynum]=drink[2];mymoney+=drink[2].price;mynum++; break ;
case '4' : Diancan(); break ;
default :
printf ( "\n您的按键有误,按任意键重新选择!\n" );
getch();
xuandrink();
}
printf ( "\n点餐成功!请按任意键继续点餐或者返回!\n" );
getch();
if (mynum>10)
{
cout<< "您本次点餐已经达到上限!如果需要!请结算后继续点餐!" <<endl;
printf ( "\n按任意键进入菜单!\n" );
getch();
Menu();
}
else xuandrink();
}
void Taocan()
{
void Menu();
void Diancan();
system ( "cls" );
cout<< "1、" <<taocan[0].mingzi<< " 价格:" <<taocan[0].price<<endl;
cout<< "2、" <<taocan[1].mingzi<< " 价格:" <<taocan[1].price<<endl;
cout<< "3、" <<taocan[2].mingzi<< " 价格:" <<taocan[2].price<<endl;
cout<< "4、返回" <<endl;
char c;
c=getch();
switch (c)
{
case '1' : mymoney+=taocan[0].price;myshiwu[mynum]=taocan[0].tc[0];mynum++;myshiwu[mynum]=taocan[0].tc[1];mynum++;myshiwu[mynum]=taocan[0].tc[2];mynum++; break ;
case '2' : mymoney+=taocan[1].price;myshiwu[mynum]=taocan[1].tc[0];mynum++;myshiwu[mynum]=taocan[1].tc[1];mynum++;myshiwu[mynum]=taocan[1].tc[2];mynum++; break ;
case '3' : mymoney+=taocan[2].price;myshiwu[mynum]=taocan[2].tc[0];mynum++;myshiwu[mynum]=taocan[2].tc[1];mynum++;myshiwu[mynum]=taocan[2].tc[2];mynum++; break ;
case '4' : Diancan(); break ;
default :
printf ( "\n您的按键有误,按任意键重新选择!\n" );
getch();
Taocan();
}
printf ( "\n点餐成功!请按任意键继续点餐或者返回!\n" );
getch();
if (mynum>10)
{
cout<< "您本次点餐已经达到上限!如果需要!请结算后继续点餐!" <<endl;
printf ( "\n按任意键进入菜单!\n" );
getch();
Menu();
}
else Taocan();
}
void Diancan()
{
void Menu();
system ( "cls" );
cout<< "1、主食" <<endl;
cout<< "2、小吃" <<endl;
cout<< "3、饮料" <<endl;
cout<< "4、套餐" <<endl;
cout<< "5、返回" <<endl;
char c;
c=getch();
switch (c)
{
case '1' : xuanzhucan(); break ;
case '2' : xuanfushi(); break ;
case '3' : xuandrink(); break ;
case '4' : Taocan(); break ;
case '5' : Menu(); break ;
default :
printf ( "\n您的按键有误,按任意键重新选择!\n" );
getch();
Diancan();
}
}
void Zhifu()
{
void Menu();
system ( "cls" );
cout<< "您本次消费" <<mymoney<< "元!请支付现金!" <<endl;
int m,s;
cin>>m;
s=m-mymoney;
while (s<0)
{
cout<< "您给的现金不足,还需要" <<0-s<< "元!请继续支付现金!" <<endl;
cin>>m;
s=m+s;
}
cout<< "支付成功!找零" <<s<< "元!祝您生活愉快!" <<endl;
write();
printf ( "\n按任意键返回菜单!\n" );
getch();
Menu();
}
void Youhuiquan()
{
void Menu();
system ( "cls" );
printf ( "\n请输入您的优惠券!\n" );
string yhq;
cin>>yhq;
if (yhq== "156157158" )
{
cout<< "您已成功使用5元优惠券!" <<endl;
mymoney=mymoney-5;
}
else
{
cout<< "对不起!您的优惠券无效!" <<endl;
getch();
Menu();
}
getch();
Zhifu();
}
void Jiesuan()
{
void Menu();
system ( "cls" );
cout<< "1、使用优惠券" <<endl;
cout<< "2、直接支付" <<endl;
cout<< "4、返回" <<endl;
char c;
c=getch();
switch (c)
{
case '1' : Youhuiquan(); break ;
case '2' : Zhifu(); break ;
case '4' : Menu(); break ;
default :
printf ( "\n您的按键有误,按任意键重新选择!\n" );
getch();
Diancan();
}
}
void Show()
{
void Menu();
system ( "cls" );
int i;
for (i=0;i<mynum;i++)
cout<<i+1<< "、" <<myshiwu[i].mingzi<< " 价格:" <<myshiwu[i].price<<endl;
cout<< "总价格、" <<mymoney<<endl;
printf ( "\n按任意键返回菜单!\n" );
getch();
Menu();
}
void Clean()
{
void Menu();
system ( "cls" );
mynum=0;
mymoney=0;
printf ( "\n清空成功!\n按任意键返回菜单!\n" );
getch();
Menu();
}
void Menu()
{
system ( "cls" );
cout<<endl<<endl<< "欢迎进入!" <<endl<<endl;
cout<< "请选择服务:" <<endl;
cout<< "1、点餐" <<endl;
cout<< "2、查看已点" <<endl;
cout<< "3、清空已点" <<endl;
cout<< "4、结算" <<endl;
cout<< "5、退出" <<endl;
char c;
c=getch();
switch (c)
{
case '1' : Diancan(); break ;
case '2' : Show(); break ;
case '3' : Clean(); break ;
case '4' : Jiesuan(); break ;
case '5' : exit (0);
default :
printf ( "\n您的按键有误,按任意键重新选择!\n" );
getch();
Menu();
}
}
void main()
{
Menu();
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/FOREVERbb2/article/details/78511543