-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
1858 lines (1771 loc) · 62.2 KB
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <string.h>
#include <time.h>
#define STUSIDE 9 //学生端
#define TEACHSIDE 11 //教师端
#define INTRODUCTION 13 //规则
#define DECLARE 15 //介绍
#define LEAVE 17 //退出
#define ACCOUNT_IN 5 // 登录账户
#define PSWD_IN 8 // 登录密码
#define _OK 11 // 按钮“登录”
#define SIGN_UP 14 //注册
#define FORGET_PSWD 17 //忘记密码
#define _CANCEL 20// 按钮“取消”
#define WINDOW_X 80 //控制台窗口宽度
#define WINDOW_Y 25 //控制台窗口高度
#define DOWN 80 //键盘上键
#define UP 72 //键盘下键
#define ENTER 13 //键盘回车
#define _INPUT 3 //输入密码
#define MAKE_SURE 6 //确认密码
#define _QUESTION 9 //密保
#define _ANSWER 12 //答案
#define _YES 15 // 确认
#define _NO 18 //取消;
#define VIEW 7 //查看成绩
#define INCREASE 9 //增加成绩
#define MODIFY 11 //修改成绩
#define DELETE_GRADE 13//删除成绩
#define MODIFY_PSWD 15//修改密码
#define MODIFY_STU_PSWD 17//修改学生密码
#define LEAVE_TEACH_SIDE 19//退出教师端
typedef struct Student{
int id; //学生学号
char pswd[11]; //密码
char name[20]; //姓名
int c_grade; //C语言成绩
int math_grade;//数学成绩
int english_grade;//英语成绩
}Student;
typedef struct node{//定义节点,数据域是一个Student类型的变量
Student stu;
struct node *next;
}Node;
////////////////////////////////////////////////////////链表和文件操作函数
void myExchange(Node * ,Node *); //将两个节点的数据域交换
Node* listSort(Node *head,const char *grade_file_name);//将文件的数据排序(从高到低)
Node* readAndWrite(Node *head,const char *file_name);//读文件到指定链表
Node* writeAndRead(Node *head,const char *file_name);//从指定链表写进文件
Node* getMinNode(Node* head); //返回一个链表中的数据域最小的节点指针
Node* creatList(const char* file); //创建链表
void printList(Node *head);//打印
void deleteList(Node *head);//删除整个链表
//void deleteNode(Node* head, int n);//删除单个节点
void insertNode(Node* , const char* );//插入单个节点
/**遍历链表的函数**/
Node* searchStudentNode(Node* head ,int id); //查找对应id的节点
Node* modifyStudentInfo(Node* head ,const char *file_name);// 修改学生信息
Node* deleteNode(Node* head, const char* file_name);
void modifyTeacherPswd( const char *account);//修改老师密码
void searchCgrade(Node* head ,int id, int grade);//查找C语言成绩
void searchMgrade(Node* head ,int id, int grade);//查找数学成绩
void studentOpUI(); //学生端登录后页面
void studentOPImplement(int id,char *class_mesg);
void stuUserInputInterface();//学生登录页面
void stuUserUI(); //学生端登录具体实现
////////////////////////////////////////////登录前函数
typedef struct teacherMesg Teacher;
struct teacherMesg{// 定义结构体:教师账号信息
char account[11] ;//账号
char pswd[11] ; //密码
char question[50]; //密保
char answer[30]; //答案
}teacher_mesg;
typedef struct teacherNode{
Teacher teach;
struct teacherNode *next;
}tNode;
void noticeCopyright();// 版权声明
void setConsoleSize();// 设置控制台大小
void printCorlor(int corlor);// 控制字体或背景颜色
void cursorGoto(int x , int y);// 控制光标
void isCursorActive(int state);// 光标是否可见
void outputContents();// 玩家登录游戏内界面
void gameUI(int color); // 游戏装饰花边
void funnyThing();// 一些有趣的东西
int warningDialog(const char *text , const char *title ,const char *opResult);// 弹窗提示 参数:内容、标题、操作成功打印内容
void printArrow(int x , int y);// 游戏操作箭头(代替鼠标)
int choiceReact();// 一个接口 玩家在选择后处理
void moveNotice(int x,int y,const char* text);// 一个箭头操作的提示
void gameBuffer();// 仿真动态游戏界面加载
void inputAccountFace();// 打印显示用户登录界面
void signUpFace();//打印用户注册界面
void forgetPswdFace();//打印忘记密码界面
void userUI();// 用户登录账号页面及接口实现
void goToAccount();//用来输入账号及显示与否
void goToPswd();// 用来输入密码及显示与否
void saveOrNot(int is_not);//是否显示账号密码
void WelcomeUI();//玩家登录后界面
void creatAccountFace();//玩家注册页面
void creatAccount();//注册账号接口
void findPswd();// 找回密码接口
void drawItem(int face_x , int face_y,const char*);
void creatImplement(int number);
void repeatPrintPswd();//重新打印注册页面输入框内信息
void clearList(char *list,int index);//清除字符串,赋值为空串
///////////////////////////////////////登录后操作函数
void teacherOpUI();//教师端登录后操作页面框架
void teacherOPImplement();//教师操作具体实现函数
FILE *teacher_file = NULL; //用来读写老师信息文件的指针
FILE *student_file = NULL;//指向存储学生信息的文件
char pswd1[11]; //注册框两个密码
char pswd2[11];
char question[41]; //密保
char answer[21]; //答案
int press_times;
/*游戏中有一两个小的bug影响到了美观性,但是为了不影响到其他模块正常作用,不再进行修补*/
///////////////////////////////////////////主函数
int main()
{
Node *head = NULL;
srand(time(0));
//int i = rand()%9;
//printf("%d",i);
setConsoleSize();//设置控制台大小
isCursorActive(0);//光标不可见
printCorlor(14);//字体为黄色
funnyThing();//佛祖保佑..
system("cls");
gameBuffer();
system("cls");
//userUI();//用户登录账号密码界面
WelcomeUI();//用户游戏内界面
///deleteList(head);//清除分配的链表内存
///teacherOpUI();
///teacherOPImplement("1779249225");
///listSort(head,"6985924183.txt");
///deleteList(head);
///modifyTeacherPswd("8277543898");
///deleteList(head);
///studentOpUI();
///studentOPImplement("2019","177");
//stuUserInputInterface();
//stuUserUI();
deleteList(head);
return 0;
}
///////////////////////////////////////////登录前函数
void WelcomeUI(){// WelcomeUI() 打开系统后选择页面
while(1){
int i;
outputContents();
i = choiceReact(32,9,2,STUSIDE,LEAVE,outputContents);
switch(i){
case STUSIDE : ///学生端
stuUserInputInterface();
break;
case TEACHSIDE : ///教师端
Sleep(1000);
userUI();
break;
case INTRODUCTION : ///功能介绍
cursorGoto(10,5);
printf("小破程序,没啥特点,容易上手。");
system("pause");
system("cls");
break;
case DECLARE : ///声明
system("cls");
noticeCopyright();
break;
case LEAVE : ///退出
if(warningDialog("您确定要退出系统吗?","退出提醒","您已退出系统")){
exit(1);
}
break;
}
}
}
void drawItem(int face_x , int face_y,const char* item){// drawItem() 在坐标(face_x,face_y)处打印一个指定字符串常量
cursorGoto(face_x , face_y);
printf("%s",item);
}
void noticeCopyright(){// noticeCopyright() 输出版权信息声明及要求
//printf("\n\n");
gameUI(0x02);
printCorlor(12);
cursorGoto(2,3);
printf("该程序原创自19级软工专业问题求解程序设计课堂实践,禁止用于一切商业用途。\n");
cursorGoto(2,4);
printf("如需转载请附上此声明并注明出处:\n\n");
cursorGoto(2,5);
printf("https://github.com/prograper/-C-\n\n");
cursorGoto(2,8);
isCursorActive(0);
printf("虽然这个程序又小又烂,但是我们一定要尊重版权。^_^");
cursorGoto(2,10);
system("pause");
system("cls");
}
void printCorlor(int corlor){// PrintCorlor() 接口: 输入控制控制台background和foreground颜色,以及text颜色
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hOut,corlor);
//CloseHandle(hOut);
/**下面是一些参数**/
/*
*SetConsoleTextAttribute函数是靠一个字节的低四位来控制前景色,高四位来控制背景色
*FOREGROUND_BLUE 字体:蓝 对应值:0X01
*FOREGROUND_GREEN 字体:绿 对应值:0X02
*FOREGROUND_RED 字体:红 对应值:0X04
*FOREGROUND_INTENSITY 前景高亮 对应值:0X08
*BACKGROUND_BLUE 背景:蓝 对应值:0X10
*BACKGROUND_GREEN 背景:绿 对应值:0X20
*BACKGROUND_RED 背景:红 对应值:0X40
*BACKGROUND_INTENSITY 背景高亮 对应值:0X80
*12 为橙色 9 为靛蓝色 14 为黄色 13 为紫色 7 为系统色(以上均是文字颜色)
*/
}
void setConsoleSize(){// setConsoleSize() 初始化控制台尺寸为宽80 高25
system("mode con cols=80 lines=25");
}
void cursorGoto(int x , int y){// cursorGoto() 接口:输入控制控制台光标移动到坐标点x,y
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD myCoord;
myCoord.X = x;
myCoord.Y = y;
SetConsoleCursorPosition(hOut,myCoord);
/****/
//CloseHandle(hOut);
}
void isCursorActive(int state){// isCursorActive() 接口: 输入一个值来决定光标是否隐藏,0隐藏,1显示
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor;
GetConsoleCursorInfo(hOut,&cursor);
cursor.bVisible = state;
SetConsoleCursorInfo(hOut,&cursor);
}
void outputContents(){// outputContents() 游戏目录 接口:玩家选择目录的数字输入
isCursorActive(0);
//gameUI(14);
printCorlor(13);
cursorGoto(14,1);
printf(" ╔════════════════╗ ");
cursorGoto(14,2);
printf("****************║学生成绩管理系统║ ***************");
cursorGoto(14,3);
printf(" ╚════════════════╝ ");
cursorGoto(35,9);
printf("学生端");
cursorGoto(35,11);
printf("教师端");
cursorGoto(35,13);
printf("功能介绍");
cursorGoto(35,15);
printf("版权声明");
cursorGoto(35,17);
printf("退出系统");
moveNotice(10,23,"Tips:请用键盘上下键来控制箭头上下移动,按回车进行选择。");
}
//choiceReact() 五个参数分别是目录第一行的x,y坐标;目录间隔gap,上下端目录值(sorry 函数耦合严重),要打印的框架函数
int choiceReact(int content_x,int content_y,int gap,int up_lim,int down_lim, void (*fOut)()){// choicReact()
/***函数有六个参数,1、2是首行目录坐标,参数3是目录间隔,参数4、5是上、下端纵坐标,参数6是指针函数***/
//content_x = 30; //退三格 // 在开始目录输出箭头指定玩家下一步操作,返回一个玩家的选择int值
//content_y = 11;
int sub = down_lim - up_lim;
int user_keyboard; //用户操作键盘键位值
int user_choice = up_lim;
printCorlor(14);
printArrow(content_x , content_y);
printCorlor(12);
moveNotice(10,23,"Tips:请用键盘上下键来控制箭头上下移动,按回车进行选择。");
while(1){
fOut();
if((user_keyboard = getch())){
switch(user_keyboard){
case UP: if(user_choice == up_lim){
system("cls");
fOut();
printCorlor(14);
printArrow(content_x , content_y + sub);
user_choice = down_lim;
content_y = down_lim;
}
else{
system("cls");
fOut();
printCorlor(14);
printArrow(content_x , content_y - gap);
content_y -= gap;
user_choice -= gap;
}
break;
case DOWN: if(user_choice == down_lim){
system("cls");
fOut();
printCorlor(14);
printArrow(content_x , content_y - sub);
user_choice = up_lim;
content_y = up_lim;
}
else{
system("cls");
fOut();
printCorlor(14);
printArrow(content_x , content_y + gap);
content_y += gap;
user_choice += gap;
}
break;
case ENTER: Sleep(400);
system("cls");
return user_choice;
break;
}
}
}
}
void printArrow(int x , int y){// printArrow() 这个函数输出箭头,相当于鼠标(sorry,严重耦合)
cursorGoto(x,y);
printf(">>>");
}
void moveNotice(int x,int y,const char* text){// moveNotice() 用来提示文本信息
isCursorActive(0);
printCorlor(0x02);
cursorGoto(x,y);
printf("%s",text);
}
void gameUI(int color){// gameUI() 为控制台打印出花边 参数代表颜色
int i,j;
printCorlor(color);
for(i=0;i<79;i++){// 打印出一圈小花花
for(j=0;j<=24;j++){
if(i==0||i==78){
drawItem(i,j,"■");
}
if(j==24){
drawItem(i,j,"■");
}
}
}
printCorlor(7);
}
int warningDialog(const char *text , const char *title , const char *opResult){// warningDialog() 退出游戏进行提示
int result =
MessageBox(NULL,text,TEXT(title),MB_ICONINFORMATION|MB_OKCANCEL);
if(result == IDOK){
printCorlor(7);
system("cls");
printf("\n\n%s\n\n\n\n",opResult);
return 1;
}
//else if(result == IDCANCEL){}
return 0;
}
void funnyThing(){// funnyThing() 在首页打印出一些有趣的东西
cursorGoto(15,0);
printf(" _ooOoo_\n");
cursorGoto(15,1);
printf(" o8888888o\n");
cursorGoto(15,2);
printf(" 88\" . \"88\n");
cursorGoto(15,3);
printf(" (| -_- |)\n");
cursorGoto(15,4);
printf(" O\\ = /O\n");
cursorGoto(15,5);
printf(" ____/`---'\\____\n");
cursorGoto(15,6);
printf(" .' \\\\| |// `.\n");
cursorGoto(15,7);
printf(" / \\\\||| : |||// \\\n");
cursorGoto(15,8);
printf(" / _||||| -:- |||||- \\\n");
cursorGoto(15,9);
printf(" | | \\\\\\ - /// | |\n");
cursorGoto(15,10);
printf(" | \\_| ''\\---/'' | |\n");
cursorGoto(15,11);
printf(" \\ .-\\__ `-` ___/-. /\n");
cursorGoto(15,12);
printf(" ___`. .' /--.--\\ `. . __\n");
cursorGoto(15,13);
printf(" .\"\" '< `.___\\_<|>_/___.' >'\"\".\n");
cursorGoto(15,14);
printf(" | | : `- \\`.;`\\ _ /`;.`/ - ` : | |\n");
cursorGoto(15,15);
printf(" \\ \\ `-. \\_ __\\ /__ _/ .-` / /\n");
cursorGoto(15,16);
printf("======`-.____`-.___\\_____/___.-`____.-'======\n");
cursorGoto(15,17);
printf(" `=---='\n");
cursorGoto(15,18);
printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
cursorGoto(15,19);
printf(" 佛祖保佑 永无BUG\n");
cursorGoto(15,23);
system("pause");
}
void gameBuffer(){// gameBuffer() 自制 模拟进入游戏界面的缓冲效果
int i;
system("cls");
gameUI(7);
cursorGoto(7,7);
printf("____________________________________________________________");
cursorGoto(6,8);
printf("||");
cursorGoto(66,8);
printf("||");
cursorGoto(7,9);
printf(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
printCorlor(9);
cursorGoto(25,10);
printf("加载中...加载过程不耗费流量");
cursorGoto(7,8);
printCorlor(12);
Sleep(1000);
for(i = 0; i < 30; i++){
if(i == 2){
Sleep(1000);
}
if(i > 10 && i < 24){
Sleep(200);
}
if(i > 25) {
Sleep(1500);
}
printf("■");
}
Sleep(800);
printCorlor(9);
cursorGoto(25,10);
printf("加载完成。 ");
Sleep(2000);
printCorlor(7);
system("cls");
}
void userUI(){// userUI() 用户登录界面的操作过程
char verify_account[11];
char verify_pswd[11];
char verify_question[41];
char verify_answer[21];
int break1 = 1;//用于跳出while,标志变量
int break2 = 1;
int break3 = 1;
/*int i ;
for(i = 0; i < 10; i ++){
teacher_mesg.account[i] = ' ';
teacher_mesg.pswd[i] = ' ';
}*/
strcpy(teacher_mesg.account,"");
strcpy(teacher_mesg.pswd,"");
while(break1){
int to_achieve;
to_achieve = choiceReact(21,5,3,ACCOUNT_IN,_CANCEL,inputAccountFace);
press_times = 0;
switch(to_achieve){
case ACCOUNT_IN: inputAccountFace();
goToAccount();
break;
case PSWD_IN : inputAccountFace();
goToPswd();
break;
case _OK : if(strcmp(teacher_mesg.account,"")==0){
inputAccountFace();
cursorGoto(52,5);
printCorlor(0x04);
printf("!请输入账号");
}else if(strcmp(teacher_mesg.pswd,"")==0){
inputAccountFace();
printCorlor(0x04);
cursorGoto(52,8);
printf("!请输入密码");
}else{/**一个文件操作,用来判断账号密码是否正确**/
teacher_file = fopen("Teacher.txt","r");
if(teacher_file == NULL){
warningDialog("登录失败,文件操作失误","登录失败","");
}else{
while((fscanf(teacher_file,"%s\t%s\t%s\t%s\n",verify_account,verify_pswd,verify_question,verify_answer)) != EOF){
if(strcmp(teacher_mesg.account,verify_account) == 0){
break2 = 0;
if(strcmp(teacher_mesg.pswd,verify_pswd) == 0){
// printf("%s\n%s\n%s",verify_account,verify_pswd,teacher_mesg.pswd);
//system("pause");
/**/ teacherOPImplement(verify_account);
//cursorGoto(31,5);
//printf("登录成功");
break3 = 0;
break;
}
}
}
fclose(teacher_file);
if(break2){
warningDialog("此账号还未注册","登录失败","");
/***/ //printf("%s\n%s\n%s",verify_account,verify_pswd,teacher_mesg.pswd);
break;
}else{
if(break3){
warningDialog("密码错误,请重新检查密码","登录失败","");
/***/ //printf("%s\n%s\n%s",verify_account,verify_pswd,teacher_mesg.pswd);
break;
}
}
}
//gameBuffer();
break1 = 0;
}
/*cursorGoto(10,21);
printf("%styu",teacher_mesg.account);
cursorGoto(10,22);
printf("%swer",teacher_mesg.pswd);*/
break;
case _CANCEL: if(warningDialog("您要放弃登录吗?","放弃登录提醒","")){
break1 = 0;
}
break;
case SIGN_UP : creatAccount();
break;
case FORGET_PSWD : findPswd();
break;
}
}
}
void inputAccountFace(){// inputAccountFace() 打印教师用户登录界面
printCorlor(14);
isCursorActive(0);
//gameUI(14);
printCorlor(0x02);
cursorGoto(18,1);
printf("tips:账号为10位数字,密码由字母和数字组成");
printCorlor(9);
cursorGoto(24,5);
printf("账号:");
cursorGoto(31,4);
printf("____________________");
cursorGoto(30,5);
printf("|");
cursorGoto(51,5);
printf("|");
cursorGoto(31,6);
printf(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
cursorGoto(24,8);
printf("密码:");
cursorGoto(31,7);
printf("____________________");
cursorGoto(30,8);
printf("|");
cursorGoto(51,8);
printf("|");
cursorGoto(31,9);
printf(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
cursorGoto(24,11);
printf("登录");
printCorlor(12);
cursorGoto(24,14);
printf("还没有账户吗,创建一个。");
cursorGoto(24,17);
printCorlor(13);
printf("忘记密码?");
printCorlor(7);
cursorGoto(24,20);
printf("取消");
moveNotice(10,23,"Tips:请用键盘上下键来控制箭头上下移动,按回车进行选择。");
saveOrNot(1);
}
void findPswd(){/**该框架还没有实现**/
cursorGoto(38,8);
printf("该功能尚未开放\n");
printf("读取存取老师的文件里的密保问题和密保答案,然后进行判断以及修改。");
system("pause");
system("cls");
}
void creatAccount(){// creatAccount() 实现注册账号的接口
int mark = 1; //用来跳出循环的标记变量
strcpy(pswd1,""); //每次都清空字符
strcpy(pswd2,"");
strcpy(question,"");
strcpy(answer,"");
while(mark){
int reciever;
printCorlor(7);
reciever = choiceReact(17,3,3,_INPUT,_NO,creatAccountFace);
switch(reciever){
case _INPUT : creatAccountFace();
creatImplement(1);
break;
case MAKE_SURE : creatAccountFace();
creatImplement(2);
break;
case _QUESTION : creatAccountFace();
creatImplement(4);
break;
case _ANSWER : creatAccountFace();
creatImplement(5);
break;
case _YES : creatAccountFace();
creatImplement(3);
/*cursorGoto(10,21);
printf("%sqwe %s[[",pswd1,question);
cursorGoto(10,22);
printf("%syui %s[[",pswd2,answer);*/
break;
case _NO : if(warningDialog("您确定要放弃注册了吗?","放弃提醒","")){
strcpy(pswd1,"");
strcpy(pswd2,"");
mark = 0;
}
break;
}
}
}
void creatAccountFace(){// creatAccountFace() 打印一个注册账号页面
printCorlor(7);
cursorGoto(18,1);
printCorlor(12);
printf("密码须设为字母和数字混合型,且不大于10位。");
printCorlor(7);
cursorGoto(20,3);
printf("输入密码:");
cursorGoto(31,2);
printf("____________________");
cursorGoto(30,3);
printf("|");
cursorGoto(51,3);
printf("|");
cursorGoto(31,4);
printf(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
cursorGoto(20,6);
printf("确认密码:");
cursorGoto(31,5);
printf("____________________");
cursorGoto(30,6);
printf("|");
cursorGoto(51,6);
printf("|");
cursorGoto(31,7);
printf(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
repeatPrintPswd();
cursorGoto(20,9);
printf("设置密保:");
cursorGoto(31,8);
printf("________________________________");
cursorGoto(30,9);
printf("|");
cursorGoto(63,9);
printf("|");
cursorGoto(31,10);
printf(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
cursorGoto(20,12);
printf("设置答案:");
cursorGoto(31,11);
printf("____________________");
cursorGoto(30,12);
printf("|");
cursorGoto(51,12);
printf("|");
cursorGoto(31,13);
printf(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
cursorGoto(20,15);
printf("确认");
cursorGoto(20,18);
printf("取消");
printCorlor(0x02);
cursorGoto(28,15);
printf("Tips:");
cursorGoto(28,17);
printf("密保问题和答案尽量简短且用英文。");
printCorlor(7);
cursorGoto(28,19);
printf("例如:what's your QQ number? : 177****225");
moveNotice(10,23,"Tips:请用键盘上下键来控制箭头上下移动,按回车进行选择。");
}
void saveOrNot(int is_not){// saveOrNot() 是否显示账号密码
int i = 0;
if(is_not){
cursorGoto(31,5);
printf("%s",teacher_mesg.account);
if(*teacher_mesg.pswd != ' '){
cursorGoto(31,8);
for(;i < press_times; i ++){
printf("*");
}
cursorGoto(41,5);
printf(" ");
}
}
}
void goToAccount(){// goToAccount() 输入账号接口实现函数
int i = 0;
int j = 31;
char str;
isCursorActive(1);
strcpy(teacher_mesg.account,"");
cursorGoto(31,5);
printf(" ");
while(1){
if(i == 10){
break;
}
cursorGoto(j,5);
str = getch();
if( str >= '0' && str <= '9'){
teacher_mesg.account[i] = str;
printf("%c",teacher_mesg.account[i]);
i ++;
j ++;
}
else{
cursorGoto(52,5);
printCorlor(0x04);
printf("!请输入有效数字");
printCorlor(0x02);
}
}
}
void goToPswd(){// goToPswd() 输入密码接口实现函数
int i = 0;
int j = 31;
char str;
press_times = 0;
isCursorActive(1);
strcpy(teacher_mesg.pswd,"");
cursorGoto(31,8);
printf(" ");
while(1){
if(i == 10){
break;
}
cursorGoto(j,8);
str = getch();
if(str == ENTER){
//strcpy(teacher_mesg.account,temp);
/*strcpy(temp,teacher_mesg.account);
int k = 0;
for(;k < 10; k ++){
teacher_mesg.account[k] = temp[k];
}*/
break;
}
if((str>='0' && str<='9') || ((str>='A' && str<='Z') || (str>='a' && str<='z'))){
teacher_mesg.pswd[i] = str;
printf("%c",teacher_mesg.pswd[i]);
i ++;
j ++;
++ press_times;
}
else{
cursorGoto(52,8);
printCorlor(0x04);
printf("!请输入有效数字");
printCorlor(0x02);
}
}
}
void creatImplement(int number){// creatPswd() 注册时输入密码接口
int i = 0;
int j = 31;
char str;
//strcpy(pswd1,""); //每次都清空字符
//strcpy(pswd2,"");
isCursorActive(1);
if(number == 1){
cursorGoto(31,3);
//strcpy(pswd1,"");/**字符重复赋值问题bug**/
//pswd1[2] = '\0';
clearList(pswd1,11);
printf(" ");
while(1){
if(i == 10){
if((strcmp(pswd2,"") != 0) && (strcmp(pswd1,pswd2) != 0)){
cursorGoto(52,3);
printCorlor(0x04);
printf("!两次输入不一致");
printCorlor(0x02);
}
break;
}
cursorGoto(j,3);
str = getch();
if(str == ENTER){
if((strcmp(pswd2,"") != 0) && (strcmp(pswd1,pswd2) != 0)){
cursorGoto(52,3);
printCorlor(0x04);
printf("!两次输入不一致");
printCorlor(0x02);
}
break;
}
if((str>='0' && str<='9') || ((str>='A' && str<='Z') || (str>='a' && str<='z'))){
*(pswd1 + i) = str;
printf("%c",*(pswd1 + i));
i ++;
j ++;
}
else{
cursorGoto(52,3);
printCorlor(0x04);
printf("!请输入有效数字");
printCorlor(0x02);
}
}
}
if(number == 2){
cursorGoto(31,6);
clearList(pswd2,11);
printf(" ");
while(1){
if(i == 10){
if(strcmp(pswd1,"") == 0){
cursorGoto(52,3);
printCorlor(0x04);
printf("!输入框为空");
printCorlor(0x02);
}else if(strcmp(pswd2,pswd1) != 0){
cursorGoto(52,6);
printCorlor(0x04);
printf("!两次输入不一致");
printCorlor(0x02);
}
break;
}
cursorGoto(j,6);
str = getch();
if(str == ENTER){
if(strcmp(pswd1,"") == 0){
cursorGoto(52,3);
printf("!输入框为空");
}else if(strcmp(pswd2,pswd1) != 0){
cursorGoto(52,6);
printCorlor(0x04);
printf("!两次输入不一致");
printCorlor(0x02);
}
break;
}
if((str>='0' && str<='9') || ((str>='A' && str<='Z') || (str>='a' && str<='z'))){
*(pswd2 + i) = str;
printf("%c",*(pswd2 + i));
i ++;
j ++;
}
else{
cursorGoto(52,6);
printCorlor(0x04);
printf("!请输入有效数字");
printCorlor(0x02);
}
}
}
if(number == 3){
int isTrue = 1;
int times = 0;
char temp_account[11];//随机抽取0~9数字十个
char file_account[11];//从文件中读出的临时账号
char file_pswd[11];//从文件中读取的临时密码
char file_question[21];
char file_answer[11];
if(strcmp(pswd1,"")==0){
isTrue = 0;
cursorGoto(52,3);
printCorlor(0X04);
printf("!输入为空");
printCorlor(0X02);
}
if(strcmp(pswd2,"")==0){
isTrue = 0;
cursorGoto(52,6);
printCorlor(0X04);
printf("!输入为空");
printCorlor(0X02);
}
if((strcmp(question,"")==0) != (strcmp(answer,"")==0)){
isTrue = 0;
cursorGoto(64,9);
printCorlor(0X04);
printf("!问题答案不匹配");
cursorGoto(52,12);
printf("!问题答案不匹配");
printCorlor(0X02);
}
if(strcmp(pswd1,pswd2) != 0){
isTrue = 0;
cursorGoto(52,3);
printCorlor(0X04);
printf("!两次输入不一致");
cursorGoto(52,6);
printf("!两次输入不一致");
printCorlor(0X02);
}
if(isTrue){
teacher_file = fopen("Teacher.txt","r+");
if(teacher_file == NULL){
warningDialog("注册失败,文件操作失误。","注册失败","");
clearList(pswd1,11);
clearList(pswd2,11);
clearList(question,41);
clearList(answer,21);
}else{
int temp_mark = 1;
while(temp_mark){
for(; times < 10; times ++){
temp_account[times] = rand()%9 + 49;
}
temp_account[10] = '\0';
temp_mark = 0;
while(fscanf(teacher_file,"%s\t%s\t%s\t%s\n",file_account,file_pswd,file_question,file_answer) != EOF){
if(strcmp(file_account,temp_account)==0){
temp_mark = 1;
break;
}
}
}
rewind(teacher_file);
fseek(teacher_file,0,SEEK_END);
fprintf(teacher_file,"%s\t%s\t%s\t%s\n",temp_account,pswd1,question,answer);
clearList(pswd1,11);
clearList(pswd2,11);
clearList(question,41);
clearList(answer,21);
char temp_list[35] = "Account:";
int de = 0;
int now = 8;
for(;de < 10,now < 19; de ++,now ++){
temp_list[now] = temp_account[de];
}
warningDialog(temp_list,"注册成功!请记牢账号","");
}
fclose(teacher_file);
}
}
if(number == 4){
clearList(question,21);
cursorGoto(31,9);
printf(" ");
cursorGoto(31,9);
gets(question);
}
if(number == 5){
clearList(answer,11);
cursorGoto(31,12);
printf(" ");
cursorGoto(31,12);