服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C/C++ - C语言实现点餐系统

C语言实现点餐系统

2021-08-05 13:54或跃在渊i C/C++

这篇文章主要为大家详细介绍了C语言实现点餐系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了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

延伸 · 阅读

精彩推荐
  • C/C++C语言实现双人五子棋游戏

    C语言实现双人五子棋游戏

    这篇文章主要为大家详细介绍了C语言实现双人五子棋游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    两片空白7312021-11-12
  • C/C++c/c++内存分配大小实例讲解

    c/c++内存分配大小实例讲解

    在本篇文章里小编给大家整理了一篇关于c/c++内存分配大小实例讲解内容,有需要的朋友们可以跟着学习参考下。...

    jihite5172022-02-22
  • C/C++OpenCV实现拼接图像的简单方法

    OpenCV实现拼接图像的简单方法

    这篇文章主要为大家详细介绍了OpenCV实现拼接图像的简单方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    iteye_183805102021-07-29
  • C/C++C语言main函数的三种形式实例详解

    C语言main函数的三种形式实例详解

    这篇文章主要介绍了 C语言main函数的三种形式实例详解的相关资料,需要的朋友可以参考下...

    ieearth6912021-05-16
  • C/C++c/c++实现获取域名的IP地址

    c/c++实现获取域名的IP地址

    本文给大家汇总介绍了使用c/c++实现获取域名的IP地址的几种方法以及这些方法的核心函数gethostbyname的详细用法,非常的实用,有需要的小伙伴可以参考下...

    C++教程网10262021-03-16
  • C/C++关于C语言中E-R图的详解

    关于C语言中E-R图的详解

    今天小编就为大家分享一篇关于关于C语言中E-R图的详解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看...

    Struggler095962021-07-12
  • C/C++使用C++制作简单的web服务器(续)

    使用C++制作简单的web服务器(续)

    本文承接上文《使用C++制作简单的web服务器》,把web服务器做的功能稍微强大些,主要增加的功能是从文件中读取网页并返回给客户端,而不是把网页代码...

    C++教程网5492021-02-22
  • C/C++深入C++拷贝构造函数的总结详解

    深入C++拷贝构造函数的总结详解

    本篇文章是对C++中拷贝构造函数进行了总结与介绍。需要的朋友参考下...

    C++教程网5182020-11-30