-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.cpp
More file actions
1532 lines (1263 loc) · 40.1 KB
/
Copy pathmenu.cpp
File metadata and controls
1532 lines (1263 loc) · 40.1 KB
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
//选课系统 2.0.0 基于1.0.0重写了近50%的代码,重点是改其他部分为普通文件读写,仅对密码部分保留二进制读写
//项目地址:https://github.com/ColdTearsYY/PKUClassSystem
//欢迎提交 issue
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
int sumClass;//有多少节课
char t[1000], t1[1000], name1[100], temp[100]; //通用临时变量
struct account {
char name[100];
char username[100];
char academy[100];
char password[100];
};//存在database.txt的账号元素结构体
struct ke {
char name[100];
char maxnum[100];
char nownum[100];
char tag[50] ;
};//课程库kecheng.txt的元素,存课程信息
struct keUnit {
char name[100];
char tag[50] ;
};//【学号】.txt里面的,每个人选的课的元素,存每个人选的课
struct userUnit {
char name[100];
char username[100];
char academy[100];
char tag[50] ;
};//【课程名】.txt里面的,人元素,属于课,记录所有选这个课的人
int checkClassNum() {//计数函数
ke cshow;
sumClass = 0;//计数器拨回0
ifstream fcin("kecheng.txt");//检查文件是否存在
if (!fcin) {
cout << "暂时还没有课程" << endl;
fcin.close();
//exit(1);
return 0;//不存在就是0课
} else {
while (!fcin.eof()) {
if (fcin >> cshow.name >> cshow.maxnum >> cshow.nownum >> cshow.tag) {
if ((strcmp(cshow.tag, "1") == 0) && (atoi(cshow.maxnum) != 0)) { //课程状态正常+最大人数!=0
sumClass++;//计数器+1
}
}
}
fcin.close();//关闭文件
return sumClass;//返回有多少节课
}
}
int checkUserNum(char s[]) {
userUnit userunit;
ifstream fcin;
fcin.open(s);
int usersum = 0;
while (!fcin.eof()) {
if (fcin >> userunit.name >> userunit.username >> userunit.academy >> userunit.tag) {
if (strcmp(userunit.tag, "1") == 0)
usersum++;
}
}
return usersum;
}
void teacher();//教师一级
void teacherLogin();//教师登录
void student();//学生一级
void studentLogin();//学生登录
void studentReg();//学生注册
void studentMenu();//学生菜单
void mainMenu();//主菜单,同main,用于返回
void teacherMenu();//教师菜单
void addClass();//教师-加课
void delClass();//教师-删课
void modifyClass();//教师-设置课程
void checkAll();//教师-检查某某课的人选
void selectClass();//学生-选课
void quitClass();//学生-退课
void checkMe();//学生-自查
int main() {
int n = 0;
char s[1000];//输入栏
ofstream KECHENG;//创建kecheng库
KECHENG.open("kecheng.txt", ios::app);
KECHENG.close();
while (n != 3) {
system("cls");
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 欢迎使用北京大学 ┃" << endl;
cout << "┃ 选课系统师生统一端 ┃" << endl;
cout << "┃ ┃" << endl;
cout << "┃ 1. 我是教务 ┃" << endl;
cout << "┃ 2. 我是学生 ┃" << endl;
cout << "┃ 3. 退出 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━┛ \n" << endl;
cout << "请输入数字选择功能 1/2/3: " ;
cin >> s;//输入选择
//getchar();
if ((strlen(s) == 1) && isdigit(s[0])) //检查输入是否合法
n = s[0] - '0';//合法则赋值
switch (n) {
case 1:
teacher();//到教师一级
break;
case 2:
student();//到学生一级
break;
case 3:
exit(2);//退出
default:
break;//输入无意义,等待正确输入
}
}
return 0;
}
void mainMenu() {//同上int main,不赘述
int n = 0;
char s[1000];
while (n != 3) {
system("cls");
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 欢迎使用北京大学 ┃" << endl;
cout << "┃ 选课系统师生统一端 ┃" << endl;
cout << "┃ ┃" << endl;
cout << "┃ 1. 我是教务 ┃" << endl;
cout << "┃ 2. 我是学生 ┃" << endl;
cout << "┃ 3. 退出 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━┛ \n" << endl;
cout << "请输入数字选择功能 1/2/3: " ;
cin >> s;
//getchar();
if ((strlen(s) == 1) && isdigit(s[0]))
n = s[0] - '0';
switch (n) {
case 1:
teacher();
break;
case 2:
student();
break;
case 3:
exit(2);
default:
break;
}
}
}
void teacher() {//教师一级
int n = 0;//选择器拨回0
char s[1000];//用于储存输入
while (true) {
system("cls");//清屏
cout << "┍━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 欢迎您,教务!┃" << endl;
cout << "┃ ┃" << endl;
cout << "┃ 1. 登录系统 ┃" << endl;
cout << "┃ 2. 返回上级 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━┛ \n" << endl;
cout << "请输入数字选择功能 1/2: " ;
cin >> s;
getchar();//清理缓冲区
if ((strlen(s) == 1) && isdigit(s[0])) //检查合法
n = s[0] - '0';
switch (n) {
case 1:
teacherLogin();//跳转教师登录
break;
case 2:
mainMenu();//返回主菜单
break;
default:
break;//输入无意义
}
}
}
void teacherLogin() {//教师-登录
char key[] = "@2022";//密码
char keyIn[10000];
char back[] = "back";
char exit0[] = "exit";
while (true) {
system("cls");
cout << "┍━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入密码 ┃" << endl;
cout << "┃ 输入back返回 ┃" << endl;
cout << "┃ 输入exit退出 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━┛ \n" << endl;
cout << "密码:";
cin.getline(keyIn, 10000);//读入输入
if (strcmp(keyIn, key) == 0) {//密码正确
system("cls");
cout << "┍━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 登陆成功! ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━┛ \n" << endl;
system("pause");
teacherMenu();
break;
} else if (strcmp(keyIn, back) == 0) {
break;//返回上级
} else if (strcmp(keyIn, exit0) == 0) {
exit(0);//退出程序
break;
} else {
system("cls");//清屏
cout << "┍━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 密码错误! ┃" << endl;
cout << "┃ 请再次尝试 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━┛ \n" << endl;
system("pause");
}
}
}
void teacherMenu() {//教师菜单
int n = 0;
char s[1000];
while (true) {
system("cls");
cout << "┍━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 教务,您已登录┃" << endl;
cout << "┃ 请选择功能 ┃" << endl;
cout << "┃ 1. 添加课程 ┃" << endl;
cout << "┃ 2. 删除课程 ┃" << endl;
cout << "┃ 3. 修改课程 ┃" << endl;
cout << "┃ 4. 查看结果 ┃ " << endl;
cout << "┃ 5. 退出登录 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━┛ \n" <<
endl;
cout << "本学期开放选择的课程共 " << checkClassNum() << " 门,名称及剩余名额如下:" << endl;
cout << endl;
ifstream fcin;
fcin.open("kecheng.txt");//检查kecheng库是否存在
//附加功能:即刻查询实时人数
int inthismax, inthisnow;//课程最大人数,课程当前人数
ke cshow;
for (int i = 1; i <= checkClassNum(); i++)
cout << "━━━━━━━━━━━";
cout << endl;
while (!fcin.eof()) {//读kecheng库
if (fcin >> cshow.name >> cshow.maxnum >> cshow.nownum >> cshow.tag) { //如果课程状态正常
//cout << cshow.tag[0] << endl;
if (strcmp(cshow.tag, "1") == 0)
printf("%-10s ", cshow.name);
}
}
cout << endl;
fcin.close();
fcin.open("kecheng.txt");
while (!fcin.eof()) {//读kecheng库
if (fcin >> cshow.name >> cshow.maxnum >> cshow.nownum >> cshow.tag) { //如果课程状态正常
//cout << cshow.tag[0] << endl;
if (strcmp(cshow.tag, "1") == 0) {
inthismax = atoi(cshow.maxnum);
inthisnow = atoi(cshow.nownum);
if (inthismax - inthisnow > 0)
printf("%-10d ", inthismax - inthisnow);
else {
printf("已满/");
printf("%-5d ", inthismax);
}
}
}
}
fcin.close();
cout << endl;
for (int i = 1; i <= checkClassNum(); i++)
cout << "━━━━━━━━━━━";
cout << endl;
n = 0;
cout << "请输入数字以选择功能 1/2/3/4/5: ";
cin >> s;//输入功能选择
if ((strlen(s) == 1) && isdigit(s[0]))
n = s[0] - '0';
switch (n) {
case 1:
addClass();//去加课
break;
case 2:
delClass();//去删课
break;
case 3:
modifyClass();//去调课
break;
case 4:
checkAll();//查某某课谁选了
break;
case 5:
cout << "┍━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 安全退出成功 ┃" << endl;
cout << "┃ 欢迎下次使用 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━┛ \n" << endl;
system("pause");
exit(9);//退出程序
break;
default:
break;
}
}
}
char kename[100];//可多次使用的临时变量
void addClass() {
ke c, c1;//声明变量
system("cls");//清屏
cout << "你选择了 1. 添加课程 " << endl;
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入课程名称 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "课程名称:";
cin >> kename;//输入
ofstream fcout;
fcout.open("kecheng.txt", ios::app); //不存在则创建
fcout.close();//结束FILE
ifstream fcin("kecheng.txt", ios::in); //创建读流
int op = 0;//判定变量,判重
while (!fcin.eof()) {
if (fcin >> c1.name >> c1.maxnum >> c1.nownum >> c1.tag) {
if (strcmp(c1.name, kename) == 0 && strcmp(c1.tag, "1") == 0) { //如果课程重复
cout << endl;
cout << "该课程已存在,无法重复添加" << endl;
cout << endl;
op = 1;
system("pause");
break;
}
}
}
fcin.close();//关闭
if (op == 0) {//如果名字没重复
strcpy(c.name, kename);
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入课程计划人数,欲取消添加请输入-1 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "输入计划人数:";
cin >> c.maxnum;//输入计划人数
if (!isdigit(c.maxnum[0])) {//粗略检查输入是否合法
cout << "\n人数输入非法,添加课程取消" << endl;
system("pause");
return;
}
strcpy(c.nownum, "0") ;//新课,当前选择人数当然默认是0
strcpy(c.tag, "1"); //状态为1,正常
fcout.open("kecheng.txt", ios::app); //打开课程库在末尾写入这个课
fcout << c.name << " " << c.maxnum << " " << c.nownum << " " << c.tag << endl; //写
fcout.close();//关闭FILE
cout << "\n课程 " << kename << " 已经成功添加" << endl;//返回信息
system("pause");
}
}
void delClass() {//教师-删课
ke c, c1;
int confirm = 0;//删除前需要确认
system("cls");
cout << "你选择了 2. 删除课程 " << endl;
cout << endl;
if (checkClassNum() == 0) {
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 当前暂无课程,不可删除课程 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
remove("kecheng.txt");
ofstream fcout;
fcout.open("kecheng.txt", ios::app);
fcout.close();
system("pause");
return;
}
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入要删除的课程名称 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "课程名称:";
cin >> kename;
ofstream fcout;
fcout.open("kecheng.txt", ios::app); //检查kecheng库是否存在
fcout.close();//over
ifstream fcin("kecheng.txt"); //创建读流
int op = 0;//判断要删的课是否存在
while (!fcin.eof()) {
if (fcin >> c1.name >> c1.maxnum >> c1.nownum >> c1.tag) {
//cout << c1.name << " " << c1.tag << endl;!!!
if ((strcmp(c1.name, kename) == 0) && (strcmp(c1.tag, "1") == 0)) {
op = 1;//存在
break;
}
}
}
fcin.close();//over
if (op == 0 ) {//不存在
cout << endl;
cout << "该课程不存在,请检查" << endl;
cout << endl;
system("pause");
} else if (op == 1) {//存在
confirm = 0;
cout << endl;
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 确认要删除吗?输入1确认,其他数字返回 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "确认:";
cin >> confirm;//确认是否删
//cout << confirm << endl;
if (confirm == 1) {//想好要删
fcout.open("kecheng.txt", ios::app); //检查kecheng库是否存在
fcout.close();
fstream f;
f.open("kecheng.txt", ios::in | ios::out | ios::binary); //文件输入输出流
while (!f.eof()) {
if (f >> c1.name >> c1.maxnum >> c1.nownum >> c1.tag) {
if ((strcmp(c1.name, kename) == 0) && (strcmp(c1.tag, "1") == 0)) {
f << "0\n";
break;
}
}
}
f.close();//关闭文件
cout << kename << " 删除完成" << endl;
if (checkClassNum() == 0) {
remove("kecheng.txt");
ofstream TEMP1;
TEMP1.open("kecheng.txt", ios::app);
TEMP1.close();
system("pause");
return;
}
system("pause");
}
}
}
void modifyClass() {//教师-改课
ke c, c1;
system("cls");
cout << "你选择了 3. 修改课程 " << endl;
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入要修改的课程名称 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "课程名称:";
cin >> kename;
getchar();
ofstream fcout;
fcout.open("kecheng.txt", ios::app); //若不存在则创建kecheng库
fcout.close();
ifstream fcin;
fcin.open("kecheng.txt");
int op = 0;//判断要修改的课程是否存在
while (!fcin.eof()) {
if (fcin >> c1.name >> c1.maxnum >> c1.nownum >> c1.tag) {
if ((strcmp(c1.name, kename) == 0) && (strcmp(c1.tag, "1") == 0)) {
op = 1;//存在
break;
}
}
}
fcin.close();//over
if (op == 0 ) {//不存在
cout << endl;
cout << "该课程不存在…… " << endl;
cout << endl;
system("pause");
} else if (op == 1) {//存在
cout << endl;
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 您要修改课程名称为? ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "输入新名称:";
cin >> c.name;//输入新名字
getchar();//清理缓冲区
fstream f;//检查课程库是否存在
f.open("kecheng.txt", ios::in | ios::out | ios::binary);
while (!f.eof()) {//读
if (f >> c1.name >> c1.maxnum >> c1.nownum >> c1.tag) { //一个一个找
if ((strcmp(c1.name, c.name) == 0) && (strcmp(kename, c.name) != 0)
&& (strcmp(c1.tag, "1") == 0)) { //保证可以修改自己人数的同时避免出现同名课程
cout << "同名课程已存在,改名失败!" << endl;//返回提示
system("pause");
f.close();//关闭
return;
break;
}
}
}
f.close();//关闭
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 您要修改课程最大人数为?(取消请输入-1) ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "最大人数:";
cin >> c.maxnum;//输入要改的人数,这里允许了最大人数超过已选人数,符合实际使用习惯;在最大人数不大于已选人数时,后续会保证课程可退不可再选
getchar();//清理缓冲区
if (!isdigit(c.maxnum[0])) {//粗略检测输入的是不是合法
cout << "人数输入非法,添加课程取消" << endl;
system("pause");
return;
}
strcpy(c.nownum, c1.nownum);//继承课程已选人数
strcpy(c.tag, "1"); //初始化状态
f.open("kecheng.txt", ios::in | ios::out | ios::binary);
while (!f.eof()) {
if (f >> c1.name >> c1.maxnum >> c1.nownum >> c1.tag) {
if ((strcmp(c1.name, kename) == 0) && (strcmp(c1.tag, "1") == 0) ) { //状态正常
f << "1\n";
break;
}
}
}
f.close();
fcout.open("kecheng.txt", ios::app); //写
fcout << c.name << " " << c.maxnum << " " << c.nownum << " " << c.tag << endl; //文件末尾二进制写入
fcout.close();
if (strcmp(kename, c.name) == 0) {
cout << "已将" << kename << " 修改为 " << c.name << ",课程上限人数为" << c.maxnum << "人。" << endl; //返回信息
system("pause");
return;
}
//fcin
//fstream FILECHECK;
//fcout
strcpy(t, kename);
strcat(t, ".txt");//继续重命名
userUnit userunit;
keUnit keunit;
fcin.open(t);
if (fcin) {
while (!fcin.eof()) {
if (fcin >> userunit.name >> userunit.username >> userunit.academy >> userunit.tag) { //在学生的列表中重命名
if (strcmp(userunit.tag, "1") == 0) {
strcpy(t, userunit.username);
strcat(t, ".txt");
f.open(t, ios::in | ios::out | ios::binary);
while (!f.eof()) {
if (f >> keunit.name >> keunit.tag) {
if ((strcmp(keunit.tag, "1") == 0) && (strcmp(keunit.name, kename) == 0)) {
f << "1\n";
break;
}
}
}
f.close();
strcpy(keunit.name, c.name);
strcpy(keunit.tag, "1");
fcout.open(t, ios::app);
fcout << keunit.name << " " << keunit.tag << endl;
fcout.close();
}
}
}
fcin.close();
strcpy(t, kename);
strcat(t, ".txt");
strcpy(t1, c.name);
strcat(t1, ".txt");
fcout.open(t1, ios::app);
fcout.close();
CopyFile(t, t1, FALSE);
remove(t);
}
fcin.close();
cout << "已将" << kename << " 修改为 " << c.name << ",课程上限人数为" << c.maxnum << "人。" << endl; //返回信息
system("pause");
}
}
void checkAll() {//教师-检查某某课选择情况
system("cls");
char s[1000];
ke c1;
userUnit userunit1;
cout << "你选择了 4. 查看结果 " << endl;
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入您要查的课程名称 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "课程名称:";
cin >> s;
//system("cls");
cout << endl;
char filename[1000];
strcpy(filename, s);
strcat(filename, ".txt");
ofstream fcout;
fcout.open(filename, ios::app); //如不存在则创建
fcout.close();
ifstream fcin;
fcin.open("kecheng.txt");
int op = 0;//判断要查的课是否存在
while (!fcin.eof()) {
if (fcin >> c1.name >> c1.maxnum >> c1.nownum >> c1.tag) {
//cout << c1.name << " " << c1.tag << endl;
if ((strcmp(c1.name, s) == 0) && (strcmp(c1.tag, "1") == 0)) {
op = 1;//存在
break;
}
}
}
fcin.close();//over
if (op == 0 ) {//不存在
cout << endl;
cout << "该课程不存在,请检查" << endl;
cout << endl;
system("pause");
} else if (op == 1) {//存在
fcin.open(filename);
int cnt = 1;
printf("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
printf("序号 学号 姓名 学院 \n");//序号5 学号10 姓名10 学院10
while (!fcin.eof()) {
if (fcin >> userunit1.name >> userunit1.username >> userunit1.academy >> userunit1.tag) {
if ((strcmp(userunit1.tag, "1") == 0)) {
printf("%-5d %-10s %-10s %-10s\n", cnt, userunit1.username, userunit1.name, userunit1.academy);
cnt++;
}
}
}
if (cnt == 1)
cout << "\n#暂时无人选这门课呢#\n\n";
printf("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
cout << endl;
system("pause");
}
}
void student() {//学生一级
int n = 0;
char s[1000];
while (true) {
system("cls");
cout << "┍━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 欢迎您,同学!┃" << endl;
cout << "┃ ┃" << endl;
cout << "┃ 1. 账号登陆 ┃" << endl;
cout << "┃ 2. 新生注册 ┃" << endl;
cout << "┃ 3. 返回上级 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━┛ \n" <<
endl;
cout << "请输入数字选择功能 1/2/3/4: ";
cin >> s;//输入选择
getchar();
if ((strlen(s) == 1) && isdigit(s[0]))
n = s[0] - '0';
switch (n) {
case 1:
system("cls");//提示用户保护隐私
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 即将跳转至北大统一认证系统,请注意隐私安全 ┃" <<
endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
system("pause");
studentLogin();
break;
case 2:
system("cls");//提示用户保护隐私
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 即将跳转至北大统一认证系统,请注意隐私安全 ┃" <<
endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
system("pause");
studentReg();
break;
case 3:
mainMenu();//返回
break;
default:
break;//输入无意义
}
}
}
char username[100];//登录cookie,记录学号
char useracademy[100];//登录cookie,记录学院
char userRealname[100];//登录cookie,记录姓名
void studentLogin() {//学生-登录
account st1;
system("cls");
cout << "你选择了 1. 账号登录 " << endl;
char password[100];
ofstream FILE;
FILE.open("database.txt", ios::app); //如不存在则创建
if (!FILE) {
cout << "无法打开database.txt"
<< endl;
exit(1);
}
FILE.close();//over
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入您的学号,如:2100010101 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "学号:";
cin >> temp;
ifstream FILE1("database.txt");//检查是否存在
if (!FILE1) {
cout << "无法打开database.txt"
<< endl;
FILE1.close();
exit(1);
}
int op = 0;//判断账号是否存在
while (!FILE1.eof()) {
if (FILE1.read((char *)&st1, sizeof(account))) {
if (strcmp(st1.username, temp) == 0) {
op = 1;//存在
break;
}
}
}
FILE1.close();
if (op == 0) {//不存在
cout << "该学号尚未注册,请先注册 " << endl;
system("pause");
} else if (op == 1) {//存在
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入密码 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "密码:";
cin >> password;
getchar();
if (strcmp(st1.password, password) == 0 ) {//密码正确
strcpy(username, temp);
system("cls");
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 登陆成功! ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n";
strcpy(userRealname, st1.name);//记录cookie
strcpy(useracademy, st1.academy);//记录cookie
system("pause");
studentMenu();//跳转至学生菜单
} else {//密码错误
cout << "密码错误,请再次登录 " << endl;
system("pause");
}
}
}
void studentReg() {//学生-注册
account st, st1;
system("cls");
cout << "你选择了 2. 新生注册 " << endl;
cout << endl;
ofstream FILE;
FILE.open("database.txt", ios::app); //如不存在则创建
if (!FILE) {
cout << "无法打开database.txt"
<< endl;
exit(1);
}
FILE.close();//over
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入您的姓名,例如:李华 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "姓名:";
cin.getline(name1, 100);
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入您的学号,例如:2000010101 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "学号:";
cin >> temp;
getchar();
ifstream FILE1("database.txt");//检查是否存在
if (!FILE1) {
cout << "无法打开database.txt"
<< endl;
exit(1);
}
int op = 0;//判断这个学号注册过没
while (!FILE1.eof()) {
if (FILE1.read((char *)&st1, sizeof(account))) {
if (strcmp(st1.username, temp) == 0) {
op = 1;//注册了
cout << "这个学号已经注册了,请直接用密码登录。" << endl;
system("pause");
break;
}
}
}
FILE1.close();//over
if (op == 0) {//没注册
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请新建密码:密码不大于30位,不小于6位。 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "新密码:";
cin.getline(t, 1000);
if (strlen(t) < 6 || strlen(t) > 30) {//基本保护,强制要求用户不使用随意的密码或容易遗忘的密码
cout << "您设置的密码不安全,本次注册取消。" << endl;
system("pause");
} else {//密码合规
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请重复您刚才设置的密码。 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "重复密码:";
cin.getline(t1, 1000);//帮助用户记住自己的密码
if (strcmp(t, t1) != 0) {
cout << "两次密码不一致,注册取消……" << endl;
system("pause");
} else {//记住了
strcpy(st.password, t);//存入st
strcpy(st.name, name1);
strcpy(st.username, temp);
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 请输入您的学院名称,便于核查。 ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;
cout << "学院:";
cin >> st.academy;//记录学院
system("cls");
cout << "┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 注册成功,已为您自动登录…… ┃" << endl;
cout << "┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ \n"
<< endl;//便利用户,注册后直接登录
FILE.open("database.txt", ios::app); //在文件末尾二进制写入
FILE.write((char *)&st, sizeof(account));
FILE.close();//关闭
strcpy(useracademy, st.academy);//cookie
strcpy(userRealname, st.name);//cookie
strcpy(username, st.username);//cookie
system("pause");
studentMenu();
}
}
}
}
void studentMenu() {//学生菜单
int n = 0;
char s[1000];
ke cshow;
ifstream fcin;
fcin.open("kecheng.txt");//检查课程库是否存在
fcin.close();//关
while (true) {
system("cls");
cout << "欢迎来自" << useracademy << "学院的" << userRealname << ",登录学号为" << username << endl;//必要的提示信息
cout << endl;
cout << "┍━━━━━━━━━━━━━━━┓ \n";
cout << "┃ 欢迎您,同学!┃" << endl;