本文实例为大家分享了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
|
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include"windows.h"
struct cai /*cai结构体 实现对菜品 已点份数、名称、原材料 的记录*/
{
int fenshu;
char name[50];
int use;
int price;
};
typedef int ElemType;
struct List /*该线性表实现对菜品原材料的剩余量的记录,线性表【i】对应菜品的点餐菜单编码*/
{
ElemType* list;
int size;
int MaxSize;
};
/*以下为线性表的函数*/
void InitList( struct List* L, int ms)
{
if (ms<=0){ printf ( "ms 值非法!\n" ); exit (1);}
L->MaxSize=ms;
L->list= malloc (ms* sizeof (ElemType));
if (!L->list)
{
printf ( "动态存储分配失败!" );
exit (1);
}
L->size=0;
}
void againMalloc( struct List *L)
{
ElemType *p= realloc (L->list,2*L->MaxSize* sizeof (ElemType));
if (!p){
printf ( "分配存储空间失败!" );
exit (1);
}
L->list=p;
L->MaxSize=2*L->MaxSize;
}
void InsertLastList( struct List *L,ElemType x)
{
if (L->size==L->MaxSize)
againMalloc(L);
L->list[L->size]=x;
L->size++;
}
/*表格函数*/
void cddayin( struct cai a[])
{
int i=0,j=0,s=0;
for (i=0;i<30;i++)
{ if (a[i].fenshu>0) j++;}
if (j!=0)
{
printf ( "已点菜/酒品编号 已点菜品名称 已点份数/瓶数 价格\n" );
for (i=0;i<30;i++)
if (a[i].fenshu>0)
{ printf ( " %5d %10s%14d %d¥ \n" ,i,a[i].name,a[i].fenshu,a[i].fenshu*a[i].price);
s=s+a[i].fenshu*a[i].price;
}
printf ( " 您好,您点餐价格合计=%d¥\n" ,s);
}
if (j==0)
printf ( "顾客尚未点餐,无法进行菜单打印!\n" );
}
void ycliao( struct List *yuan, struct cai a[])
{
int i=1,p=0,k=0;
for (i=0;i<30;i++)
{
do {
p=a[i].use%100;
yuan->list[p]=yuan->list[p]-a[i].fenshu;
a[i].use=a[i].use/100;
} while (a[i].use!=0);
}
printf ( "|-------------------------------------------------------|--------------------|\n" );
printf ( "|------------------原材料余量---------------------------|-----酒品余量-------|\n" );
printf ( "|-------------------------------------------------------|--------------------|\n" );
printf ( "| 10.鸡肉=%3d 11.猪肉=%3d 12.鱼肉=%3d | 50.雪花啤酒=%3d |\n" ,yuan->list[10],yuan->list[11],yuan->list[12],yuan->list[50]);
printf ( "| 13.黄瓜=%3d 14.土豆=%3d 15.豆腐=%3d | 51.燕京啤酒=%3d |\n" ,yuan->list[13],yuan->list[14],yuan->list[15],yuan->list[51]);
printf ( "| 16.茄子=%3d 17.青椒=%3d 18.牛肉=%3d | 52.二锅头=%3d |\n" ,yuan->list[16],yuan->list[17],yuan->list[18],yuan->list[52]);
printf ( "| 19.大葱=%3d 20.鲜鸭血=%3d 21.花生=%3d | |\n" ,yuan->list[19],yuan->list[20],yuan->list[21]);
printf ( "| 22.花椒=%3d 23.酱=%3d 24.胡萝卜=%3d | |\n" ,yuan->list[22],yuan->list[23],yuan->list[24]);
printf ( "| 25.辣椒=%3d 26.芹菜=%3d 27.豆皮=%3d | |\n" ,yuan->list[25],yuan->list[26],yuan->list[27]);
printf ( "|-------------------------------------------------------|--------------------|\n" );
printf ( "|-------------------------------------------------------|--------------------|\n" );
}
void diancai( struct cai a[])
{
int p=0,wep=0;
do {
printf ( " |----------------------------------------------|-------------------|\n" );
printf ( " |----------菜品(输入-1确认并结束点餐)----------|-------酒品--------|\n" );
printf ( " |----------------------------------------------|-------------------|\n" );
printf ( " | 1.宫爆鸡丁 2.鱼香肉丝 3.京酱肉丝 | 21.雪花啤酒 |\n" );
printf ( " | 4.地三鲜 5.水煮鱼 6.麻婆豆腐 | 22.燕京啤酒 |\n" );
printf ( " | 7.夫妻肺片 8.拍黄瓜 9.鲜鸭血 | 23.二锅头 |\n" );
printf ( " |----------------------------------------------|-------------------|\n" );
printf ( " |----------------------------------------------|-------------------|\n" );
scanf ( "%d" ,&p);
system ( "CLS" );
if (p>=1&&p<=9)
{
printf ( " |------------------------------------------|\n" );
printf ( " |------------------份数--------------------|\n" );
printf ( " |------------------------------------------|\n" );
printf ( " | 1.一份 2.两份 |\n" );
printf ( " | 3.三份 4.其他请直接输入 |\n" );
printf ( " |------------------------------------------|\n" );
printf ( " |------------------------------------------|\n" );
scanf ( "%d" ,&wep);
if (wep>50)
{ system ( "CLS" ); printf ( "您输入的值异常或过大,请您检查输入的值!\n" ); continue ;} /*防止误输入*/
else if (wep<=50)
{a[p].fenshu+=wep;
system ( "CLS" );
}
}
else if (p>=21&&p<=23)
{
printf ( " |--------------------------------------------------------|\n" );
printf ( " |-------------------------酒品数量-----------------------|\n" );
printf ( " |--------------------------------------------------------|\n" );
printf ( " | 1.一瓶 2.两瓶 3.三瓶 4.其他瓶数请直接输入 |\n" );
printf ( " |--------------------------------------------------------|\n" );
printf ( " |--------------------------------------------------------|\n" );
scanf ( "%d" ,&wep);
if (wep>50)
{ system ( "CLS" ); printf ( "您输入的值异常或过大,请您检查输入的值!\n" ); continue ;} /*防止误输入*/
else if (wep<=50)
{
a[p].fenshu+=wep;
system ( "CLS" );
}
}
else if (p!=-1)
printf ( "对不起,你输入的编码没有对应菜品,请重新输入!\n" );
} while (p!=-1);
system ( "CLS" );
cddayin(a);
}
void ycldayin( struct List yuan, struct cai a[])
{
char l= '\0' ;
printf ( "显示原材料余量?(Y/N)\n" );
l=getch();
if (l== 'Y' ||l== 'y' )
{ system ( "CLS" );
ycliao(&yuan,a);}
else
{ system ( "CLS" );
printf ( "\n\n\n\n" );}
}
main()
{
int i=0;
char l= '\0' ;
struct List yuan; /* yuan前不用加“*” */
struct cai a[30]={
{0, "\0" ,0},
{0, "宫爆鸡丁" ,10131421,15},{0, "鱼香肉丝" ,1124,14},{0, "京酱肉丝" ,112327,16},
{0, "地三鲜" ,141617,10},{0, "水煮鱼" ,122225,50},{0, "麻婆豆腐" ,152225,11},
{0, "夫妻肺片" ,18212625,17},{0, "拍黄瓜" ,13252223,8},{0, "鲜鸭血" ,20,20},
{0, "\0" ,0},{0, "\0" ,0},{0, "\0" ,0},
{0, "\0" ,0},{0, "\0" ,0},{0, "\0" ,0},
{0, "\0" ,0},{0, "\0" ,0},{0, "\0" ,0},
{0, "\0" ,0},{0, "\0" ,0},
{0, "雪花啤酒" ,50,5},{0, "燕京啤酒" ,51,6},{0, "二锅头" ,52,4},
{0, "\0" ,0},{0, "\0" ,0},{0, "\0" ,0},
{0, "\0" ,0},{0, "\0" ,0},{0, "\0" ,0}};
InitList(&yuan,60);
for (i=0;i<60;i++)
InsertLastList(&yuan,100); //+rand()%50
printf ( "\n\n\n\n\n\n\n\n" );
printf ( " |--------------------------------------------------------|\n" );
printf ( " |---------------- 欢迎来到春晓点餐系统! -----------------|\n" );
printf ( " |--------------------------------------------------------|\n" );
Sleep(2500);
system ( "CLS" );
diancai(a); /*点餐函数,开始点餐吧!*/
ycldayin(yuan,a);
printf ( "\n\n\n\n" );
printf ( " |--------------------------------------------------------|\n" );
printf ( " |-------------- 欢迎再次使用春晓点餐系统! ---------------|\n" );
printf ( " |--------------------------------------------------------|\n" );
printf ( "\n\n\n\n\n\n" );
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。