C语言实现外卖管理系统

时间:2021-10-31 03:36:47

本文为大家分享了C语言外卖管理系统的具体代码,供大家参考,具体内容如下

内容

说明(废话):上学期写的课程设计,主题是外卖管理系统,希望可以模拟网上订餐,店家工作,专人管理的过程。并实现注册与登录以及基本信息的输出,因为个人比较懒,一直没有整理上去,今天得空,要是得到大家的宝贵意见的话,会不胜荣幸。

重点内容

  三端登录 :分别为管理员,用户以及店主;两端注册,分别为用户以及店铺,其中店铺的注册成功需要得到管理员的审核。

  •   管理员端可以查看店铺信息,店铺信息修改(分为增删改查),处理申请店铺,和修改本人信息。
  •   用户端分为用户相关(为用户本人对自己信息的操作),查看订单,查看菜品,购买菜品,以及订单排序。
  •   管理员端为增添菜品,删除菜品,修改菜品,查看菜品以及业绩查看(统计总订单与总收入)。

另外:

1. 店家注册需要的到管理员的认证,认证通过之后才可登录
2. 密码修改需要输入旧的密码,三次错误可以找回密码,输入手机号,若手机号匹配得当,则可产生三位数的随机验证码,输入验证码即可修改。
3. 对于已超过三分钟的订单不能修改,因为已经配送
4. 限制了用户的余额,当购买时余额不足时,需要进行账户的充值,而购买结束后,账户的余额也会相应的减少

以下为功能模块图:

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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include<time.h>
#include<conio.h>
void choose();
//建立关于店铺的结构体
typedef struct shop
{
  char name[20];
  char phone[20];
  char address[30];
  char password[20];
  struct shop *next;
}shop,*link_shop;
//建立关于订单的结构体
typedef struct food
{
  char name[20];
  int type;
  int amount;
  int price;
  int total;
  char shop[20];
  char yonghu[20];
  char leibie[20];
  struct food *next;
}food,*link_food;
//建立关于用户的结构体
typedef struct user
{
  char name[20];
  char delivery[39];
  char password[15];
  char number[15];
  int score;
  struct user *next;
}user,*link_user;
typedef struct money
{
  char person[20];
  char card[25];
  char mima[20];
  struct money *next;
}money,*link_money;
char yh[20];//用户设置全局变量
char dp[20];//店铺设置全局变量
time_t start,end;
//函数声明
void foodwrite(link_food LF);
void shopwrite1(link_shop LS);
void dingdanwrite(link_food LF);
void user_moneywrite(link_user LM);
void welcome()
{
  int i=0;
  char a[52]="▲▼WELCOME TO RESTAURANT MANAGEMENT SYSTEM▲▼";
  //system("color 0a");
  printf("\n\n\n\n\t\t");
  while(a[i])
  {
    printf("%c",a[i]);
    Sleep(50);
    i++;
  }
  printf("\n\n\n\n\t\t");
}
void Exit()
{
  int i=0;
  system("cls");
  char a[20]="LOVE you,byebye^_^";
  system("color 03");
  printf("\n\n\n\t\t\t");
  while(a[i])
  {
    printf("%c",a[i]);
    Sleep(100);
    i++;
  }
}
void ME()
{
  system("color 0b");
  printf("\n\n\n\t\t☆★ W E L C O M E ☆★\n\n\t这里是外卖管理系统,请选择接下来的操作:");
  printf("\n\n\t\t\t1.登陆");
  printf("\t\t\t2.注册\t\t\t0.退出\n");
}
//主菜单(登陆或者注册) 
void MENU()
{
  printf("\n\n\n\n\t\t\t\t\t================================\n");
  printf("\t\t\t\t\t   外 卖 管 理 系 统   \n");
  printf("\t\t\t\t\t     1.管理员登陆     \n");
  printf("\t\t\t\t\t     2.用户登录      \n");
  printf("\t\t\t\t\t     3.店家登陆      \n");
  printf("\t\t\t\t\t     0.返回上一级     \n");
  printf("\t\t\t\t\t================================\n");
}
//管理员选项
void MENU1()
{
  system("color 0f");
  printf("                                     温馨小提示:按5可以清屏哦^-^\n");
  printf("\n\n\t\t\t\t\t1.查看店铺信息▲\n");
  printf("\t\t\t\t\t--------------\n");
  printf("\t\t\t\t\t2.店铺信息修改▼\n");
  printf("\t\t\t\t\t--------------\n");
  printf("\t\t\t\t\t3.处理申请店铺▲\n");
  printf("\t\t\t\t\t--------------\n");
  printf("\t\t\t\t\t4.修改本人信息▼\n");
  printf("\t\t\t\t\t--------------\n");
  printf("\t\t\t\t\t0.返回上一级 ▲\n");
}
//用户选项
void MENU2()
{
  system("color 0f");
  printf("\n\n\t\t\t\t 1.用户相关 ▲\t\t\t 5.购买菜品 ▼\n");
  printf("\t\t\t\t---------------\t\t\t---------------\n");
  printf("\t\t\t\t 2.查看订单 ▲\t\t\t 6.订单排序▼\n");
  printf("\t\t\t\t---------------\t\t\t---------------\n");
  printf("\t\t\t\t 3.查看菜品 ▲\t\t\t 0.返回上级 ▼\n");
  printf("\t\t\t\t---------------\t\t\t---------------\n");
  printf("\t\t\t\t 4.修改订单 ▲\n");
}
//店主选项
void MENU3()
{
  system("color 0f");
  printf("\n\n\n\t\t\t ________ Shop Version _______\n");
  printf("\t\t\t|               |\n");
  printf("\t\t\t|     1.添加菜品     |\n");
  printf("\t\t\t|     2.修改菜品     |\n");
  printf("\t\t\t|     3.删除菜品     |\n");
  printf("\t\t\t|     4.查看菜品     |\n");
  printf("\t\t\t|     5.查看业绩     |\n");
  printf("\t\t\t|     0.返回上一级    |\n");
  printf("\t\t\t|_____________________________|\n");
}
//建立关于单链表
void *creatf()
{
  int i=0,n;
  link_food LF;
  food *s,*r;
  char a[10];
  //srand((unsigned)time(NULL));//产生随机数的种子
  LF=(food *)malloc(sizeof(food));
  LF->next=NULL;
  r=LF;
  while(1)
  {
    printf("请输入菜的名称:");
    scanf("%s",a);
    if(strcmp(a,"0")!=0)
    {
      s=(food *)malloc(sizeof(food));
      printf("请输入菜的单价:");
      scanf("%d",&s->price);
      printf("请输入菜的类别");
      scanf("%s",s->leibie);
      strcpy(s->name,a);
      s->total=(s->amount)*(s->price);
      r->next=s;
      s->next=NULL;
      r=s;
    }
    else
      break;
  }
  foodwrite(LF);
}
shop *creats()
{
  char a[30],b[20],c[15],d[20];
  link_shop LS;
  shop *s,*r;
  LS=r=(shop *)malloc(sizeof(shop));
  LS->next=NULL;
  r=LS;
  while(1)
  {
    printf("请输入店铺信息:\n");
    printf("\t\t●  店铺名称:");
    scanf("%s",a);
    printf("\n\t\t●  店铺电话:");
    scanf("%s",b);
    if(strcmp(b,"0")!=0)
    {
      printf("\n\t\t●  店铺地址:");
      scanf("%s",c);
      printf("\n\t\t●  店铺密码:");
      scanf("%s",d);
      s=(shop *)malloc(sizeof(shop));
      strcpy(s->name,a);
      strcpy(s->phone,b);
      strcpy(s->address,c);
      strcpy(s->password,d);
      r->next=s;
      s->next=NULL;
      r=s;
    }
    else
      break;
  }
  return LS;
}
void Outputshop(link_shop Ls)
{
  int n=0;
  shop *p,*u;
  p=Ls->next;
  system("cls");
  printf("入驻的商家如下:\n");
  printf("\t\t\t\t-------------------------------------------\n");
  printf("\t\t\t\t店铺名称\t店铺电话\t店铺地址\n");
  printf("\t\t\t\t-------------------------------------------\n");
  while(p)
  {
    printf("\t\t\t\t%8s\t%8s\t%7s\n",p->name,p->phone,p->address);
    printf("\t\t\t\t-------------------------------------------\n");
    p=p->next;
  }
  for(u =Ls->next; u != NULL;u = u->next)
    n++;
  printf("\t\t\t\t合计\t\t\t\t%d个\n",n);
  printf("\t\t\t\t-------------------------------------------\n");
}
void Outputfood(link_food LF)
{
  food *s;
  s=LF->next;
  int sum=0;
  printf("订单如下:\n");
  printf("\t----------------------------------------------------------------------------------------------------\n");
  printf("\t菜名\t\t数量/份\t\t单价/元\t\t总价/元\t\t店铺\t\t订单号\t\t用户名\n");
  printf("\t----------------------------------------------------------------------------------------------------\n");
  for(s=LF->next;s!=NULL;s=s->next)
  {
    if(strcmp(s->yonghu,yh)==0)
    {
      printf("\t%-8s\t%-8d\t%-8d\t%-8d\t%-10s\t%-10d\t%s\n",s->name,s->amount,s->price,s->total,s->shop,s->type,s->yonghu);
      printf("\t----------------------------------------------------------------------------------------------------\n");
      sum=sum+s->total;
    }
  }
  printf("\t累计输出/元\t\t\t\t\t\t\t%d\n",sum);
  printf("\t----------------------------------------------------------------------------------------------------\n");
  if(sum==0)
  {
    printf("○  您还没有订单呢,快去购买吧 φ(>ω<*) ");
    printf("\n\t\t\t\t\t->");
    Sleep(1000);
    printf("->");
    Sleep(1000);
    printf("->");
    Sleep(1000);
    system("cls");
    MENU2();
    return;
  }
}
void outputfood(link_food LF)
{
  food *p;
  p=LF->next;
  printf("\n\t\t\t         菜    谱            ");
  printf("\n\t\t\t--------------------------------------------------\n");
  printf("\t\t\t菜名    菜价     店铺      菜系\n");
  printf("\t\t\t---------------------------------------------------\n");
  while(p)
  {
    printf("\t\t\t%-13s%-12d%-14s%s\n",p->name,p->price,p->shop,p->leibie);
    printf("\t\t\t---------------------------------------------------\n");
    p=p->next;
  }
}
//充值
user* addmoney(user *u)
{
  int n;
  char y;
  char a[20];
  FILE *fp;
  link_money LY;
  money *p,*r;
  printf("您账户里的余额为:%d",u->score);
  printf("是否充值?Y/else");
  fflush(stdin);//清除缓存
  y=getchar();
  if(y=='Y')
  {
    fp=fopen("yue.txt","rt");
    LY=r=(money *)malloc(sizeof(money));
    LY->next=NULL;
    while(!feof(fp))
    {
      p=(money *)malloc(sizeof(money));
      fscanf(fp,"%s %s %s\n",p->person,p->card,p->mima);
      p->next=NULL;
      r->next=p;
      r=p;
    }   
    fclose(fp);
    p=LY->next;
    while(1)
    {
      if(strcmp(yh,p->person)==0)
      {
        break;
      }
      else
        p=p->next;
    }
    printf("充值的钱数?");
    scanf("%d",&n);
    printf("请输入支付密码:");
    scanf("%s",a);
    if(strcmp(p->mima,a)==0)
    {
      u->score=(u->score+n);
      printf("已充值");
    }
    else
      printf("\t\t×  密码错误,充值失败");
  }
  else
    printf("已放弃充值");
  return u;
}         
//按工号排序
void name_sort(link_shop LS)
{
  int i,j,n;
  n = 0; //记录店铺总数;
  shop *u,*q,*p;
  for(u =LS->next; u != NULL;u = u->next)
    n++;
//采用冒泡法对各个节点按姓名升序
  for(i=1;i<=n;i++)
  {
    u =LS;
    for(j=0;j<n-i;j++)
    {
      p = u->next;
      q = p->next;
      if(strcmp(p->name,q->name) > 0 || strcmp(p->name,q->name) == 0)
      {
        u->next = q;
        p->next = q->next;
        q->next = p;
      }
      u = u->next;
    }
  }
  printf("\t排序后店铺信息\n");
  Outputshop(LS);
  return;
}
void address_sort(link_shop LS)
{
  int i,j,n;
  n = 0; //记录店铺总数;
  shop *u,*q,*p;
  for(u =LS->next; u != NULL;u = u->next)
    n++;
//采用冒泡法对各个节点按地址升序
  for(i=1;i<=n;i++)
  {
    u =LS;
    for(j=0;j<n-i;j++)
    {
      p = u->next;
      q = p->next;
      if(strcmp(p->address,q->address) > 0 || strcmp(p->address,q->address) == 0)
      {
        u->next = q;
        p->next = q->next;
        q->next = p;
      }
      u = u->next;
    }
  }
  printf("\t\t\t\t地址排序后店铺信息\n");
  Outputshop(LS);
  return;
}
void dingdan_name_sort(link_food LF) //按订单食物名称排序
{
  int i,j,n;
  n = 0; //记录店铺总数;
  food *u,*q,*p;
  for(u =LF->next; u != NULL;u = u->next)
    n++;
//采用冒泡法对各个节点按姓名升序
  for(i=1;i<=n;i++)
  {
    u =LF;
    for(j=0;j<n-i;j++)
    {
      p = u->next;
      q = p->next;
      if(strcmp(p->name,q->name) > 0 || strcmp(p->name,q->name) == 0)
      {
        u->next = q;
        p->next = q->next;
        q->next = p;
      }
      u = u->next;
    }
  }
  Outputfood(LF);
  return;
}
void dingdan_total_sort(link_food LF) //按订单总价从高到低排序
{
  int i,j,n;
  n = 0; //记录店铺总数;
  food *u,*q,*p;
  for(u =LF->next; u != NULL;u = u->next)
    n++;
//采用冒泡法对各个节点按姓名升序
  for(i=1;i<=n;i++)
  {
    u =LF;
    for(j=0;j<n-i;j++)
    {
      p = u->next;
      q = p->next;
      if(p->total>q->total)
      {
        u->next = q;
        p->next = q->next;
        q->next = p;
      }
      u = u->next;
    }
  }
  Outputfood(LF);
  return;
}
void dingdandelete(link_food Lf)
{
  food *p,*n;
  p=Lf;
  n=p->next;
  int m;
  char a;
  printf("请输入你所想删除的订单序号:");
  scanf("%d",&m);
  while(n)
  {
    if(m==n->type)
    {
      if(strcmp(n->shop,dp)==0)
      {
        p->next=n->next;
        //foodwrite(Lf);
        dingdanwrite(Lf);
        break;
      }
      else
        printf("不好意思,您没有权限删除\n");
      break;
    }
    else
    {
      p=p->next;
      n=n->next;
    }
  }
}
food *dingdanread()
{
  FILE *fp;
  link_food LF,r,s;
  fp=fopen("dingdan.txt","rt");
  if(fp==NULL)
  {
    printf("查看订单失败");
    return 0;
  }
  LF=r=(food *)malloc(sizeof(food));
  r->next=NULL;
  while(!feof(fp))
  {
    s=(food *)malloc(sizeof(food));
    fscanf(fp,"%s %d %d %d %s %d %s\n",s->name,&s->amount,&s->price,&s->total,s->shop,&s->type,s->yonghu);
    r->next=s;
    s->next=NULL;
    r=s;
  }
  return LF;
}
void scorefind(link_food LF)
{
  int sum=0;
  food *p;
  p=LF->next;
  system("cls");
  printf("\n\n\n\t\t\t产生的订单如下:\n");
  printf("   ----------------------------------------------------------------------------------------------------\n");
  printf("   菜品名称 \t菜品数量\t菜品单价\t菜品总价\t店铺名称\t订单号 \t\t用户名\n");
  printf("   ----------------------------------------------------------------------------------------------------\n");
  while(p)
  {
    if(strcmp(p->shop,dp)==0)
    {
    printf("  %7s%14d%15d%16d%16s%15d%18s\n",p->name,p->amount,p->price,p->total,p->shop,p->type,p->yonghu);
    printf("   ----------------------------------------------------------------------------------------------------\n");
    sum=sum+p->total;
    }
    p=p->next;
  }
  printf("   合计/元:\t\t\t\t\t\t\t累计收入%d\n",sum);
  printf("   ----------------------------------------------------------------------------------------------------\n");
  if(sum==0)
    printf("\t\t●  您店里的菜还没有人购买哦,应该反思啦\n");
}
food * foodread()//读取
{
  link_food LF;
  food *s,*r;
  LF=r=(food *)malloc(sizeof(food));
  LF->next=NULL;
  FILE *fp;
  fp=fopen("food.txt","rt");
  if(fp==NULL)
  {
    printf("不能打开此文件");
    exit(1);
  }
  while(!feof(fp))//判断文件指针是否处于文件结束位置,若是,返回1,非,返回0
  {
    s=(food *)malloc(sizeof(food));
    fscanf(fp,"%s %d %s %s\n",s->name,&s->price,s->shop,s->leibie);
    r->next=s;
    s->next=NULL;
    r=s;
  }
  fclose(fp);
  return LF;
 }
money * moneyread()//读取
{
  link_money LM;
  money *s,*r;
  LM=r=(money *)malloc(sizeof(money));
  LM->next=NULL;
  FILE *fp;
  fp=fopen("yue.txt","rt");
  if(fp==NULL)
  {
    printf("不能打开此文件");
    exit(1);
  }
  while(!feof(fp))//判断文件指针是否处于文件结束位置,若是,返回1,非,返回0
  {
    s=(money *)malloc(sizeof(money)); 
    fscanf(fp,"%s %s %s\n",s->person,s->card,s->mima);
    r->next=s;
    s->next=NULL;
    r=s;
  }
  fclose(fp);
  return LM;
 }
shop * shopread()
{
  link_shop LS;
  shop *s,*r;
  LS=r=(shop *)malloc(sizeof(shop));
  r->next=NULL;
  FILE *fp;
  fp=fopen("shop.txt","rt");
  if(fp==NULL)
  {
    printf("不能打开此文件");
    exit(1);
  }
  while(!feof(fp))//判断文件指针是否处于文件结束位置,若是,返回1,非,返回0
  {
    s=(shop *)malloc(sizeof(shop));
    s->next=NULL;
    fscanf(fp,"%s %s %s %s\n",s->name,s->phone,s->address,s->password);
    r->next=s;
    r=s;
  }
  fclose(fp);
  return LS;
 }
user * userread()
{
  link_user LU;
  user *s,*r;
  LU=r=(user *)malloc(sizeof(user));
  r->next=NULL;
  FILE *fp;
  fp=fopen("users.txt","rt");
  if(fp==NULL)
  {
    printf("不能打开此文件");
    exit(1);
  }
  while(!feof(fp))//判断文件指针是否处于文件结束位置,若是,返回1,非,返回0
  {
    s=(user *)malloc(sizeof(user));
    s->next=NULL;
    fscanf(fp,"%s %s %s %s %d\n",s->name,s->delivery,s->password,s->number,&s->score);
    r->next=s;
    r=s;
  }
  fclose(fp);
  return LU;
 }
void deleteshop(link_shop LS)
{
  int i=0;
  shop *p,*q;
  p=LS;
  q=p->next;
  char m[20];
  char a;
  printf("请输入你所想删除的店铺名称或者电话:");
  scanf("%s",m);
  while(q)
  {
    if(strcmp(m,q->name)==0||strcmp(m,q->phone)==0)
    {
      i++;
      p->next=q->next;
      shopwrite1(LS);
      return;
    }
    else
    {
      p=p->next;
      q=q->next;
    }
  }
  if(i==0)
  {
    printf("没有此店铺,无法删除\n");
    return;
  }
}
void deletedingdan(link_food Lf)
{
  food *p,*n;
  p=Lf;
  n=p->next;
  int m,i=0;
  char a;
  printf("请输入你所想删除的订单号:");
  scanf("%d",&m);
  while(n)
  {
    if(n->type==m)
    {
      if(strcmp(n->yonghu,yh)==0)
      {
        p->next=n->next;
        i++;
        foodwrite(Lf);
      }
      else
        printf("不好意思,您没有权限删除\n");
      break;
    }
    else
    {
      p=p->next;
      n=n->next;
    }
  }
  if(i==0)
  {
    printf("\t没有此订单,无法删除\n");
    return;
  }
}
void purchase()
{
  link_food Lf;
  money *LM,*mo;
  user *lu,*us;
  FILE *fp;
  char a[20],b[20],mi[20];
  char y;
  int i=0;
  printf("\t\t◇您想吃啥呢?");
  scanf("%s",a);
  Lf=foodread();
  food *p;
  p=Lf->next;
  srand((unsigned)time(NULL));//订单号的种子
  while(p!=NULL)
  {
    if(strcmp(p->name,a)==0||strcmp(p->leibie,a)==0)
    {
    // printf("%s\t%d\t%s\n",p->name,p->price,p->shop);
      i++;
    
    p=p->next;
  }
  if(i==0)
  {
    printf("\t\t\t×不好意思,还没有此菜呢\n");
    system("pause");
    system("cls");
    MENU2();
    return;
  }
  else
  {
    p=Lf->next;
    printf("\n\t\t\t--------------------------------------------------\n");
    printf("\t\t\t菜名    菜价     店铺      菜系\n");
    printf("\t\t\t---------------------------------------------------\n");
    while(p)
    {
      if(strcmp(p->leibie,a)==0||strcmp(p->name,a)==0)
      {
        printf("\t\t\t%-13s%-12d%-14s%s\n",p->name,p->price,p->shop,p->leibie);
        printf("\t\t\t---------------------------------------------------\n");
      }
 
      p=p->next;
    }
  }
  printf("\t\t◇请输入要购买的店铺:");
  scanf("%s",b);
  lu=userread();
  us=lu->next;
  while(us)
  {
    if(strcmp(yh,us->name)==0)
      break;
    else
      us=us->next;
  }//找出要购买的用户信息
  LM=moneyread();
  mo=LM->next;
  i=0;
  while(mo)
  {
    if(strcmp(yh,mo->person)==0)
    {
      i++;
      break;
    }
 
    else
      mo=mo->next;
  }//找出用户的银行卡信息
  if(i==0)
  {
    printf("\t\t×  您还没有绑定银行卡哦,不能购买的");
    return;
  }
  p=Lf->next;
  i=0;
  while(p)
  {
    if(strcmp(p->name,a)==0||strcmp(p->leibie,a)==0)
    {
      if(strcmp(p->shop,b)==0)
      {
        printf("\t\t◇请输入要购买的数量");
        scanf("%d",&p->amount);
        if(p->amount!=0)
        {
          i++;
          p->total=(p->amount)*(p->price);
          p->type=rand()%900+100;
          if((us->score)<p->total)
          {
            printf("\t\t×  您的账号余额不足,请先充值\n");
            system("pause");
            system("cls");
            MENU2();
            return;
          }
          printf("\t\t●确认购买?Y/else");
          fflush(stdin);
          y=getchar();
          if(y=='Y')
          {
            printf("请输入支付密码:");
            scanf("%s",mi);
            if(strcmp(mi,mo->mima)==0)
            {
              fp=fopen("dingdan.txt","at");
              if(fp==NULL)
                printf("\t\t\t\t×购买失败\n");//因文件无法打开而失败
              else
              {
                fprintf(fp,"%s %d %d %d %s %d %s\n",p->name,p->amount,p->price,p->total,p->shop,p->type,yh);
                fclose(fp);
                us->score=(us->score)-(p->total);
                user_moneywrite(lu);
                printf("\t\t\t\t√购买成功,请耐心等待配送\n");
                start = time(NULL);//计时
                system("pause");
                system("cls");
                MENU2();
                return;
              }   
            }
            else
            {
              printf("\t\t×  密码错误,购买失败");
              system("pause");
              system("cls");
              MENU2();
              return;
            }   
          }
          else
          {
            printf("\t\t\t×已放弃购买");
            system("pause");
            system("cls");
            MENU2();
            return;
          }
        }
        else
        {
          printf("\t\t\t×请输入正确的数量");
          system("pause");
          system("cls");
          MENU2();
          return;
        }
      }
    }
    p=p->next;
  }
  if(i==0)
  {
    printf("\t\t×请输入表中的店铺名称哦\n");
    system("pause");
    system("cls");
    MENU2();
  }
}
void foodwrite(link_food LF)//保存
 {
  FILE *fp;
  food *p;
  char a;
  printf("确认保存?(Y/else)");
  scanf("%*c%c",&a);
  if(a=='Y')
  {
    fp=fopen("food.txt","at");
    if(fp==NULL)
      printf("错误!无法打开");
    for(p=LF->next;p!=NULL;p=p->next)
      fprintf(fp,"%s %d %s %s\n",p->name,p->price,dp,p->leibie);
    printf("修改成功\n");
    fclose(fp);
    return;
  }
  else
    printf("已放弃修改");
 }
 void foodwrite1(link_food LF)
 {
  FILE *fp;
  food *p;
  char a;
  printf("确认保存?(Y/else)");
  scanf("%*c%c",&a);
  if(a=='Y')
  {
    fp=fopen("food.txt","wt");
    if(fp==NULL)
      printf("错误!无法打开");
    for(p=LF->next;p!=NULL;p=p->next)
      fprintf(fp,"%s %d %s %s\n",p->name,p->price,p->shop,p->leibie);
    printf("修改成功\n");
    fclose(fp);
    return;
  }
  else
    printf("已放弃修改");
 }
// void foodwrite2(link_food LF)
// {
// FILE *fp;
// food *p;
// char a;
// printf("确认保存?(Y/else)");
// scanf("%*c%c",&a);
// if(a=='Y')
// {
//   fp=fopen("food.txt","wt");
//   if(fp==NULL)
//     printf("错误!无法打开");
//   for(p=LF->next;p!=NULL;p=p->next)
//     fprintf(fp,"%s %d %s %s\n",p->name,p->price,p->shop,p->leibie);
//   printf("修改成功\n");
//   fclose(fp);
//   return;
// }
// else
//   printf("已放弃修改");
// }
 void dingdanwrite(link_food LF)
 {
  FILE *fp;
  food *p;
  char a;
  printf("确认保存?(Y/else)");
  scanf("%*c%c",&a);
  if(a=='Y')
  {
    fp=fopen("dingdan.txt","wt");
    if(fp==NULL)
      printf("错误!无法打开");
    for(p=LF->next;p!=NULL;p=p->next)
      fprintf(fp,"%s %d %d %d %s %d %s\n",p->name,p->amount,p->price,p->total,p->shop,p->type,p->yonghu);
    printf("修改成功\n");
    fclose(fp);
    return;
  }
  else
    printf("已放弃修改");
 }
void shopwrite1(link_shop LS)
 {
  FILE *fp;
  shop *p;
  char a;
  printf("确认保存?(Y/else)");
  scanf("%*c%c",&a);
  if(a=='Y')
  {
    fp=fopen("shop.txt","wt");
    if(fp==NULL)
      printf("错误!无法打开");
    for(p=LS->next;p!=NULL;p=p->next)
      fprintf(fp,"%s %s %s %s\n",p->name,p->phone,p->address,p->password);
    printf("保存成功\n");
    fclose(fp);
    return;
  }
  else
    printf("已放弃");
 }
 void shopwrite2(link_shop LS)
 {
  FILE *fp;
  shop *p;
  char a;
  printf("是否将信息保存至文件里?(Y/else)");
  scanf("%*c%c",&a);
  if(a=='Y')
  {
    fp=fopen("shop.txt","at");
    if(fp==NULL)
      printf("错误!无法打开");
    for(p=LS->next;p!=NULL;p=p->next)
    fprintf(fp,"%s %s %s\n",p->name,p->phone,p->address);
    printf("修改成功\n");
    fclose(fp);
    return;
  }
  else
    printf("已放弃修改");
 
 }
 void userwrite(link_user LU)
 {
  FILE *fp;
  user *p;
  char a;
// printf("请确认?(Y/else)");
// scanf("%*c%c",&a);
// if(a=='Y')
// {
    fp=fopen("users.txt","wt");
    if(fp==NULL)
      printf("错误!无法打开");
    for(p=LU->next;p!=NULL;p=p->next)
      fprintf(fp,"%s %s %s %s %d\n",p->name,p->delivery,p->password,p->number,p->score);
    printf("操作成功\n");
    fclose(fp);
    return;
// }
  //else
    //printf("已放弃注册");
 }
 void user_moneywrite(link_user LM)
 {
  FILE *fp;
  user *p;
  char a;
// printf("是否将信息保存至文件里?(Y/else)");
// scanf("%*c%c",&a);
// if(a=='Y')
// {
    fp=fopen("users.txt","wt");
    if(fp==NULL)
      printf("错误!无法打开");
    for(p=LM->next;p!=NULL;p=p->next)
      fprintf(fp,"%s %s %s %s %d\n",p->name,p->delivery,p->password,p->number,p->score);
    //printf("注册成功\n");
    fclose(fp);
    //return;
// }
  //else
    //printf("已放弃注册");
 }
 void userwrite2(link_user LU)
 {
  FILE *fp;
  user *p;
  char a;
  printf("是否将信息保存至文件里?(Y/else)");
  scanf("%*c%c",&a);
  if(a=='Y')
  {
    fp=fopen("users.txt","at");
    if(fp==NULL)
      printf("错误!无法打开");
    for(p=LU->next;p!=NULL;p=p->next)
      fprintf(fp,"%s %s %s %s %d\n",p->name,p->delivery,p->password,p->number,p->score);
    printf("注册成功\n");
    fclose(fp);
    return;
  }
  else
    printf("已放弃注册");
 }
void increaseshop(link_shop LS)
{
  char a[30],b[20],c[15],d[20];
  shop *s;
  printf("请输入你所想加入的店铺信息:\n");
  printf("\t\t●  店铺名称:");
  scanf("%s",a);
  printf("\n\t\t●  店铺电话:");
  scanf("%s",b);
  printf("\n\t\t●  店铺地址:");
  scanf("%s",c);
  printf("\n\t\t●  店铺密码:");
  scanf("%s",d);
  if(strcmp(a,"0")!=0)
  {
    s=(shop *)malloc(sizeof(shop));
    strcpy(s->name,a);
    strcpy(s->phone,b);
    strcpy(s->address,c);
    strcpy(s->password,d);
  }
  s->next=LS->next;
  LS->next=s;
  shopwrite1(LS);
 }
void shopfind(link_shop LS)
{
  shop *p;
  char E[20];
  p=LS->next;
  printf("请输入店铺的名称:");
  scanf("%s",E);
  while(strcmp(p->name,E)!=0&&(p->next)!=NULL)
  {
    p=p->next;
  }
  if((p->next)==NULL)
  {
    printf("没有此店铺");
    return;
  
  printf("您所查询的店铺信息为:\n名称\t电话\t地址\n");
  printf("%s %s %s",p->name,p->phone,p->address);
}
void registerdeal()
{
  int q;
  FILE *fp;
  char y;
  link_shop head;
  shop *r,*p;
  head=r=(shop *)malloc(sizeof(shop));
  r->next=NULL;
  fp=fopen("shenqing.txt","rt");
  if(fp==NULL)
  {
    printf("发生错误,无法打开文件");
    return;
  }
  if((y=fgetc(fp))==EOF)
  {
    printf("目前没有需要处理的信息\n");
    system("pause");
    system("cls");
    MENU1();
    return;
  }
  else
  {
    while(!feof(fp))
    {
      p=(shop *)malloc(sizeof(shop));
      fscanf(fp," %s %s %s %s \n",p->name,p->phone,p->address,p->password);
      r->next=p;
      p->next=NULL;
      r=p;
    }
    for(p=head->next;p!=NULL;p=p->next)
      printf("%s %s %s\n",p->name,p->phone,p->address);
    printf("是否同意注册?Y/else");
    scanf("%*c%c",&y);
    if(y=='Y')
    {
      fp=fopen("shop.txt","at");
      if(fp==NULL)
        printf("文件不存在,打开错误\n");
      for(p=head->next;p!=NULL;p=p->next)
        fprintf(fp,"% s %s %s %s \n",p->name,p->phone,p->address,p->password);
      fclose(fp);
    }
 
  }
  printf("处理成功");
  fp=fopen("shenqing.txt","wt");
  fclose(fp);
}
void MENU1_choose()
{
  int n,m,q;
  char a[20],b[20],c[20],d[20];
  char y;
  FILE *fp,*fa;
  shop *p;
  shop sq;
  link_shop LS;
  link_user LU;
  LS=shopread();
  while(1)
  {
    printf("请选择你想所想进行的选项:\n");
    scanf("%d",&n);
    if(n==1)
    {
      Outputshop(LS);
      printf("是否进行排序?Y/else");
      fflush(stdin);
      y=getchar();
      if(y=='Y')
      {
        system("cls");
        printf("\n\n\n\t\t\t●1.按店铺名称排序\n");
        printf("\t\t\t●2.按店铺地址排序\n");
        scanf("%d",&m);
        if(m==1)
          name_sort(LS);
        if(m==2)
          address_sort(LS);
        printf("1.退出\t2.返回");
        scanf("%d",&m);
        if(m==1)
          exit(0);
        else
        {
          system("cls");
          MENU1();
          continue;
        }
      }
      else
      {
        printf("已放弃排序\n");
        system("cls");
        MENU1();
      }
 
    }
    if(n==2)
    {
      system("cls");
      printf("\n\n\n\t\t\t☆【1】删除店铺\n");
      printf("\t\t\t☆【2】增加店铺\n");
      printf("\t\t\t☆【3】输入店铺\n");
      printf("\t\t\t☆【0】返回上一级\n");
      printf("\n\t\t请选择将要进行的操作:\n"); //二级
      while(1)
      {
        scanf("%d",&m);
        if(m==1)
          deleteshop(LS);
        if(m==2)
          increaseshop(LS);
        if(m==3)
        {
          LS=creats();
          shopwrite1(LS);
        }
        if(m==4)
          shopfind(LS); 
        if(m==0)
        {
          system("cls");
          MENU1();
          break;
        }
      }   
    }
    if(n==3)
      registerdeal();//注册处理以及投诉处理函数
    if(n==4)
    {
      //LU=userread();
      system("cls");
      printf("\n\t请选择所想进行的选项:\n\n");
      printf("\t● ○ ● ○ ● ○ ●\n");
      printf("\t  1.查看个人信息  \n");
      printf("\t○ 2.修改个人信息 ○\n");
      printf("\t  0.返回上一级   \n");//二级
      printf("\t● ○ ● ○ ● ○ ●\n");
      while(1)
      {
        scanf("%d",&m);
        if(m==1)
        {
          char d[20];
          fa=fopen("admin.txt","rt");
          fscanf(fa,"%s %s %s %s",a,b,c,d);
          fclose(fa);
          printf("\n\t\t地区\t姓名\t电话号码\n");
          printf("\t\t%s\t%s\t%s\n",a,b,d);
        }
        if(m==2)
        {
          system("cls");
          printf("\n                             温馨提示,按0返回哦(〃'▽'〃)\n");
          printf("\n\t\t● ○ ● ○ ● ○ ●\n");
          printf("\t\t   1.修改姓名   \n");
          printf("\t\t○  2.修改地址  ○\n");
          printf("\t\t   3.修改密码   \n");//三级
          printf("\t\t● ○ ● ○ ● ○ ●\n");
          scanf("%d",&q);
          if(q==1)
          {
            printf("请输入新的姓名:\n");
            scanf("%s",b);
          }
          if(q==2)
          {
            printf("请输新的地址:\n");
            scanf("%s",a);
          }
          if(q==3)//修改密码,含找回密码
          {
            int j=0,h;
            char f[20],e[20];
            fa=fopen("admin.txt","rt");
            fscanf(fa,"%s %s %s %s",a,b,c,d);
            printf("您需要输入旧的密码:\n");
            scanf("%s",f);
            while(strcmp(f,c)!=0)
            {
              j++;
              printf("\t\t×您的密码有误,请重新输入:");
              scanf("%s",f);
              if(j==2)
              {
                printf("\t\t×您已经连续输错三次,按1找回密码,其他数字键返回:");
                scanf("%d",&j);
                if(j==1)
                {
                  printf("请输入您的电话号码:");
                  scanf("%s",e);
                  if(strcmp(e,d)==0)
                  {
                    srand((unsigned)time(NULL));
                    j=rand()%900+100;
                    fp=fopen("yanzheng.txt","wt");
                    //fscanf(fp,"%d\n",&j);
                    fprintf(fp,"%d\n",j);
                    fclose(fp);
                    printf("我们已经发送验证码到您的手机,请输入:");
                    scanf("%d",&h);
                    if(h==j)
                    {
                      printf("\t\t√请重新设置您的密码:");
                      scanf("%s",c);
                      break;
                    }
                    else
                    {
                      printf("\t\t×验证码错误\n");
                      break;
                    }
                  }
                  else
                  {
                    printf("\t\t×找回密码失败\n");
                    break;
                  }
                }
                else
                {
                  system("cls");
                  MENU();
                  return;
                }
 
              }
            }
            if(strcmp(c,f)==0)
            {
              printf("请输入新的密码:\n");
              scanf("%s",c);
            }
          }
          if(q==1||q==2||q==3)
          {
            printf("是否保存?Y/else");
            fflush(stdin);
            y=getchar();
            if(y=='Y')
            {
              fa=fopen("admin.txt","wt");
              fprintf(fa,"%s %s %s %s",a,b,c,d);
              fclose(fa);
              printf("\t\t√保存成功");
            }
            else
              printf("\t\t×已放弃修改");
            system("pause");
            system("cls");
            printf("\n\t请选择所想进行的选项:\n\n");
            printf("\t● ○ ● ○ ● ○ ●\n");
            printf("\t  1.查看个人信息  \n");
            printf("\t○ 2.修改个人信息 ○\n");
            printf("\t  0.返回上一级   \n");//二级
            printf("\t● ○ ● ○ ● ○ ●\n");
            continue;
          }
          if(q==0)
          {
            system("cls");
            printf("\n\t请选择所想进行的选项:\n\n");
            printf("\t● ○ ● ○ ● ○ ●\n");
            printf("\t  1.查看个人信息  \n");
            printf("\t○ 2.修改个人信息 ○\n");
            printf("\t  0.返回上一级   \n");//二级
            printf("\t● ○ ● ○ ● ○ ●\n");
            continue;
          }
        }
        if(m==0)
        {
          system("cls");
          MENU1();
          break;
        }
      }
    }
    if(n==5)
    {
      system("cls");
      MENU1();
    }
    if(n==0)
    {
      system("cls");
      MENU();
      break;
    }
    if(n!=1&&n!=2&&n!=3&&n!=4&&n!=5&&n!=0)
    {
      printf("\t\t∷");
      Sleep(400);
      printf("∷");
      Sleep(400);
      printf("∷");
      Sleep(400);
      printf("您需要输入菜单上的数字哦\n");
    
  }
}
void MENU2_choose()
{
  int n,m,q,i=0;
  char a[20],b[20];
  char y;
  FILE *fp;
  user *u;
  food *p,*s,*r;
  link_food LF,Lf;
  LF=foodread();
  link_user LU;
// user user;
  while(1)
  {
    scanf("%d",&n);
    switch(n)
    {
      case 1:
          system("cls");
          printf("\n\n\t\t\t请选择需要进行的选项:\n\n");
          printf("\t\t\t--------------------\n");
          printf("\t\t\t  用 户 相 关\n");
          printf("\t\t\t--------------------\n");
          printf("\t\t\t●  1.修改用户名\n");
          printf("\t\t\t●  2.修改密码\n");
          printf("\t\t\t●  3.修改收货地址\n");
          printf("\t\t\t●  4.修改电话号\n");
          printf("\t\t\t●  5.查看个人信息\n");
          printf("\t\t\t●  6.充值钱包\n");
          printf("\t\t\t●  0.返回上一级\n");
          LU=userread();
          u=LU->next;
          while(1)
          {
            if(strcmp(yh,u->name)==0)
              break;
            else
              u=u->next;
          }
          while(1)
          {
            scanf("%d",&m);
            if(m==1)
            {
              printf("请输入新的用户名:\n");
              scanf("%s",u->name);
            }
            if(m==2)
            {
              printf("您需要输入旧的密码:\n");
              scanf("%s",b);
              while(strcmp(u->password,b)!=0)
              {
                printf("密码错误,请重新输入\n");
 
                scanf("%s",b);
                i++;
                if(i==2)
                {
                  printf("您已经输错三次,请5分钟后再试");
                  continue;
                }
              }
              printf("请输入新的密码:");
              scanf("%s",u->password);
            }
            if(m==3)
            {
              printf("请输入新的收货地址:");
              scanf("%s",u->delivery);
            }
            if(m==4)
            {
              printf("请输入新的收货地址");
              scanf("%s",u->number);
            }
            if(m==1||m==2||m==3||m==4)
              userwrite(LU);
            if(m==5)
            {
              printf("您的信息为:\n");
              printf("姓名\t收获地址\t联系方式\n");
              printf("%s\t%s\t%s\n",u->name,u->delivery,u->number);
            }
            if(m==6)
            {
              u=addmoney(u);
              userwrite(LU);
            }
            if(m==0)
            {
              system("cls");
              MENU2();
              break;
            }
 
          }
          break;
      case 2:
        LF=dingdanread();
        Outputfood(LF);
        break;
      case 3:
        LF=foodread();
        system("cls");
        outputfood(LF);
        p=LF->next;
        printf("\t●  按1购买,其他数字返回\t");
        scanf("%d",&q);
        if(q==1)
        {
          purchase();
        }
        else
        {
          system("cls");
          MENU2();
          continue;
        }
        break;
      case 4:
        LF=dingdanread();
        p=LF->next;
        i=0;    
        printf("请输入所想修改的订单号:");
        scanf("%d",&n);
        while(p)
        {
          if(n==p->type)
          {
            if(strcmp(p->yonghu,yh)==0)
            {
              i=1;
              system("cls");
              printf("\n订单信息如下:\n");
              printf("\t菜名\t单价\t数量\t总价\t店铺\t用户名\t\n");
              printf("\t%s\t%d\t%d\t%d\t%s\t%s\n\n",p->name,p->price,p->amount,p->total,p->shop,p->yonghu);
              printf("\t\t○  1.修改数量\n");
              printf("\t\t○  2.删除订单\n");
              printf("\t\t○  其他数字键返回\n");
              scanf("%d",&n);
              if(n==1)
              {
                end = time(NULL);
                if((difftime(end,start))<180)
                {
                  printf("还没有超过三分钟,请尽快修改哦\n");
                  printf("您只能修改菜的数量:");
                  scanf("%d",&m);
                  p->amount=m;
                  p->total=(p->amount)*(p->price);
                  dingdanwrite(LF);
                  printf("\t\t√已成功修改");
                }
                else
                {
                  printf("时间超过三分钟,已配送\n");
                  system("pause");
                  system("cls");
                  MENU2();
                  break;
                }
              }
              if(n==2)
              {
                deletedingdan(LF);
                dingdanwrite(LF);
              }
              else
              {
                system("pause");
                system("cls");
                MENU2();
                break;
              }
            }
            if(strcmp(p->yonghu,yh)!=0)
            {
              printf("\t\t×  不好意思,该订单您没有权限修改\n");
              i=2;
              system("pause");
              system("cls");
              MENU2();
              break;
            }
          }
          else
            p=p->next;
        
        if(i==0)
        {
          printf("\t\t×没有改订单\n");
          system("pause");
          system("cls");
          MENU2();
          continue;
        
        break;
      case 5:
        purchase();
        break;
      case 6:
        system("cls");
        printf("\n\n\n\t\t\t---------------\n");
        printf("\t\t\t 订 单 排 序\n");
        printf("\t\t\t---------------\n");
        printf("\t\t\t△ 1.按菜名排序:\n");
        printf("\t\t\t△ 2.按总价排序:\n");
        printf("\t\t\t△ 0.返回\n");
        scanf("%d",&m);
        {
          LF=dingdanread();
          if(m==1)
            dingdan_name_sort(LF);
          if(m==2)
            dingdan_total_sort(LF);
          if(m==0)
          {
            system("cls");
            MENU2();
            continue;
          }
          system("pause");
          system("cls");
          MENU2();
          continue;
 
        }
        break;
        //dindan_name_sort(LF);
      case 0:
        system("cls");
        MENU();
        return;
        break;
      }
    }
}
void deletefood(link_food Lf)
{
  int i=0;
  food *p,*n;
  p=Lf;
  n=p->next;
  char m[20];
  char a;
  printf("请输入你所想删除的菜名:");
  scanf("%s",m);
  while(n)
  {
    if(strcmp(m,n->name)==0)
    {
      if(strcmp(n->shop,dp)==0)
      {
        i++;
        p->next=n->next;
        foodwrite1(Lf);
      }
      else
 
        printf("不好意思,您没有权限删除\n");
      break;
    }
    else
    {
      p=p->next;
      n=n->next;
    }
  }
  if(i==0)
  {
    printf("没有此菜,无法删除\n");
    return;
  }
}
void MENU3_choose()
{
  int x,y;
  char a[20];
  link_food LF,Lf;
  LF=foodread();
  food *p;
  while(1)
  {
    printf("请选择:");
    scanf("%d",&x);
    if(x==1)
    {
      creatf();
      //foodwrite(LF);
    }
    if(x==2)
    {
      int i=0;
      printf("请输入要修改的菜的名称:");
      scanf("%s",a);
      //LF=foodread();
      p=LF->next;
      while(p!=NULL)
      {
        if(strcmp(a,p->name)==0)
        {
          i++;
          if(strcmp(dp,p->shop)==0)
          {
            printf("请重新输入菜的信息:\n");
            printf("\t\t\t△新菜名:");
            scanf("%s",p->name);
            printf("\t\t\t△新菜价:");
            scanf("%d",&p->price);
            foodwrite1(LF);
          }
          else
            printf("不好意思,您没有权限修改\n");
          break;
        }
        p=p->next;
      }
      if(i==0)
        printf("\t\t×  没有此菜的信息\n");
    }
    if(x==3)
    {
      deletefood(LF);
    }
    if(x==4)
    {
      int sum=0;
      Lf=foodread();
      p=Lf->next;
      system("cls");
      printf("\n\n\t\t您家的食物如下:");
      printf("\n\t\t----------------------------------------\n");
      printf("\t\t菜名\t   菜价\t店铺\t  菜系\n");
      printf("\t\t----------------------------------------\n");
      while(p)
      {
        if(strcmp(p->shop,dp)==0)
        {
          printf("\t\t%-14s%-10d%-12s%s\n",p->name,p->price,p->shop,p->leibie);
          printf("\t\t----------------------------------------\n");
          sum=sum+1;
        }
        p=p->next;
      }
      printf("\t\t合计/个:\t\t\t%d个菜\n",sum);
      printf("\t\t----------------------------------------\n");
      if(sum==0)
        printf("\t\t\t●  怪不得没订单,您还没添加菜品呢\n");
      system("pause");
      system("cls");
      MENU3();
    }
    if(x==5)
    {
      LF=dingdanread();
      scorefind(LF);//查看业绩函数
      system("pause");
      system("cls");
      MENU3();
    }   
    if(x==0)
    {
      system("cls");
      MENU();
      break;
    
  }
}
//登陆
void login()
{
  int n,i=0,j=0;
  char a[10],c[10];
  char b[15],d[15],f[10],e[20];
  FILE *fp;
  char ch;
  system("cls");
  MENU();
  printf("请选择:");
  while(1)
  {
    scanf("%d",&n);
    //管理员登陆
    if(n==1)
    {
      printf("请输入用户名:");
      scanf("%s",a);
      printf("请输入密码:");
      while((ch=getch())!=13){
      if(ch==8){
        printf("\b \b");
        i--;
        continue;
      }
      b[i++]=ch;
      putchar('*');
      }
      b[i]='\0';
      fp=fopen("admin.txt","rt");
        if(fp==NULL)
          printf("没有此文件,无法打开");
      fscanf(fp,"%s %s %s %s",f,c,d,e);
      fclose(fp);
      while(strcmp(a,c)!=0||strcmp(b,d)!=0)
      {
        printf("\n账号或密码错误,请重新输入:\n");
        printf("请输入用户名:");
        scanf("%s",a);
        printf("请输入密码:");
        i=0;
        while((ch=getch())!=13){
        if(ch==8){
          printf("\b \b");
          i--;
          continue;
        }
        b[i++]=ch;
        putchar('*');
        }
        b[i]='\0';
        j++;
        if(j==2)
        {
          printf("\n密码错误已达三次,将自动退回主菜单\n");
          system("pause");
          system("cls");
          MENU();
          return;
        }
      }
      system("cls");
      //system("color 03");
      welcome();
      printf("\n");
      system("pause");
      system("cls");
      MENU1();
      MENU1_choose();
    }
  //用户登录
    if(n==2)
    {
      link_user LU;
      user *p;
      LU=userread();
      p=LU->next;
      printf("请输入账号或名称");
      scanf("%s",yh);
      printf("请输入密码:");
      i=0;
      while((ch=getch())!=13){
      if(ch==8){
        printf("\b \b");
        i--;
        continue;
      }
      b[i++]=ch;
      putchar('*');
      }
      b[i]='\0';
      int i=0;
      while(p!=NULL)
      {
        if(strcmp(yh,p->name)==0&&strcmp(b,p->password)==0)
        {
          system("cls");
          //system("color 0a");
          //welcome();
          printf("\n");
          system("pause");
          system("cls");
          i++;
          MENU2();
          MENU2_choose();
          break;
        }
        p=p->next;
      }
      if(i==0)
      {
        printf("密码或者账号错误\n");
        system("pause");
        system("cls");
        ME();
        return;
      }
    }
    if(n==3)
    {
      link_shop LS;
      shop *p;
      j=0;
      LS=shopread();
      p=LS->next;
      printf("请输入店铺名称或者账号:");
      scanf("%s",dp);
      printf("请输入密码");
      i=0;
      while((ch=getch())!=13)
      {
        if(ch==8)
        {
          printf("\b \b");
          i--;
          continue;
        }   
        putchar('*');
        b[i++]=ch;
      }
      b[i]='\0';
      while(p!=NULL)
      {
        if(strcmp(dp,p->name)==0&&strcmp(b,p->password)==0)
        {
          system("cls");
          //system("color 0a");
          //welcome();
          j++;
          printf("\n");
          system("pause");
          system("cls");
          MENU3();
          MENU3_choose();
          break;
        }
        else
          p=p->next;
      }
      if(j==0)
      {
        printf("\t\t\n×  密码或者账号错误\n");
        system("pause");
        system("cls");
        ME();
        return;
      }
    }
    if(n==0)
    {
      system("cls");
      ME();
      break;
    
  }
}
user * creatu()
{
  char a[30],b[20],c[15],d[20];
  char ca[20],mi1[20],mi2[20];
  link_user LU,lu;
  FILE *fp;
  user *s,*r,*p;
  int x,y,i,h;
  LU=r=(user *)malloc(sizeof(user));
  LU->next=NULL;
  printf("请输入姓名:");
  scanf("%s",a);
  lu=userread();
  while(1)
  {
    i=0;
    p=lu->next;
    while(p)
    {
      if(strcmp(a,p->name)==0)
      {
        i++;
        printf("\t\t×此用户已经有人注册过,请重新输入:");
        scanf("%s",a);
        break;
      }
      else
        p=p->next;
    }
    if(i==0)
      break;
  }
  printf("请输入收货地址:");
  scanf("%s",b);
  printf("请输入密码:");
  scanf("%s",c);
  printf("请输入电话号码:");
  scanf("%s",d);
  x=strlen(c);
  while(x<8)
  {
    printf("\t\t●  您的密码小于8位,安全指数为低\n");
    printf("按1修改,其他键放弃修改:");
    scanf("%d",&y);
    if(y==1)
    {
      scanf("%s",c);
      x=strlen(c); 
    }
    else
      break;
  }
  if(strcmp(b,"0")!=0)
  {
    s=(user *)malloc(sizeof(user));
    s->score=0;
    strcpy(s->name,a);
    strcpy(s->delivery,b);
    strcpy(s->password,c);
    strcpy(s->number,d);
    r->next=s;
    s->next=NULL;
    r=s;
    printf("为了方便充值钱包,请绑定您的银行卡:");
    scanf("%s",ca);
    h=strlen(ca);
    while(h<15)
    {
      printf("\t\t●  您的银行卡不足15位,请重新输入:");
      scanf("%s",ca);
      h=strlen(ca);
    }
    i=0;
    printf("请设置您的支付密码");
    scanf("%s",mi1);
    printf("请确认密码");
    scanf("%s",mi2);
    if(strcmp(mi1,mi2)!=0)
    {
      printf("\t\t×注册失败,两次密码不同");
      return 0;
    }
    fp=fopen("yue.txt","at");
    fprintf(fp,"%s %s %s\n",a,ca,mi1);
    fclose(fp);
  }
  else
  {
    printf("\t\t×注册失败,请输入正确的收货信息:");
    return 0;
  }
  return LU; 
}
void Register()
{
  int y;
  char a;
  FILE *fp;
  shop sq;//申请
  system("cls");
  printf("\n\n\n\t\t\t\t1.注册用户\t\t\t2.申请店铺\n");
  printf("\t\t\t\t0.返回上一级");
  while(1)
  {
    printf("\t\t▲ 请选择要进行的选项:");
    scanf("%d",&y);
    if(y==1)//用户注册
    {
      link_user LU;
      LU=creatu();
      userwrite2(LU);
    }
    if(y==2)
    {
      printf("请输入店铺名称:");
      scanf("%s",sq.name);
      printf("请输入店铺电话:");
      scanf("%s",sq.phone);
      printf("请输入店铺地址:");
      scanf("%s",sq.address);
      printf("请输入店铺密码:");
      scanf("%s",sq.password);
      fp=fopen("shenqing.txt","at");
      if(fp==NULL)
      {
        printf("发生错误,无法打开文件");
        return;
      }
      printf("是否保存?Y/else");
      scanf("%*c%c",&a);
      if(a=='Y')
      
        fprintf(fp," %s %s %s %s \n",sq.name,sq.phone,sq.address,sq.password);
        fclose(fp);
        printf("\t\t√  申请成功,等待上级审核");
      }
      else
      {
        printf("\t\t×  已放弃申请");
        fclose(fp);
      }
    }
    if(y==0)
    {
      system("cls");
      printf("\t\tWELCOME\n这里是外卖管理系统,请选择接下来的操作:");
      printf("\n\n\t\t\t\t1.登陆");
      printf("\t\t\t\t2.注册\n");
      break;  
    }
  }
}
void choose()
{
  int x;
  ME();
  while(1)
  {
    scanf("%d",&x);
    if(x==1)
      login();
    if(x==0)
    {
      Exit();
      return;
    }
 
    if(x==2)
      Register();
  }
}
int main()
{
  choose();
}

代码有些多,因为要用到文件以及文件交互,因此这里有整个的文件外卖管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/kiddingstreet/article/details/78258787