写在前面
目前版本已知缺陷 正文
txt文档Main.cLogin.hRegister.hVerify.hFunction.cFunction.hRead.cStruct.hbase.hBubble_sort.c
写在前面此C语言项目为新人小白作品,无论是在代码层面还是在什么层面,仅靠我个人的知识是做不到尽善尽美的,烦请各位读者们能多多在评论或私信提出意见以便改进。
目前版本已知缺陷在这里感谢项目组中的两位同学,姚同学和刘同学。
项目大部分都是他们完成的,在这里最后呈现出来的版本只是我经过了稍微(笑)的修改和优化
无法实现密码长度范围限制。最初版本的账户密码加密算法是由刘同学实现的MD5加密且有稍微的BUG,所以该版本没有实现账户密码加密。主要是因为我看不懂早期因为缺少沟通, 导致功能分装有些许的混乱,不过并不影响功能的实现。大奖赛系统中修改的功能只是在程序执行中修改数据,实际上并没有对txt文档中的数据进行修改。部分功能的函数实现写在了头文件中。输入的密码一定要在8~16位,否则程序会死
原谅我不会上传项目
百度网盘下载链接:https://pan.baidu.com/s/1cT7i1BEEDV0ONyfw2W65iQ
提取码:2022
正文
本大奖赛系统项目一共由9个文件组成,分别是Main.c 、Login.h 、Register.h 、Verify.h 、Function.c 、Function.h 、Read.c 、Struct.h 、base.h 、Bubble_sort.c 。
有关功能说明大都写在注释中了
#define _CRT_SECURE_NO_WARNINGS 1 #include "Function.h" #include "Login.h" #include "Register.h" #include "base.h" unsigned int status = 0;//等级 int main() { while(1) { read_data();//初始化Struct.h中的结构体 system("color F0"); system("title ------Managing System------(NEED TO LOGIN)"); system("cls");//清屏 Sleep(200); printf("欢迎!您正在使用本次大奖赛的管理系统"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED|BACKGROUND_RED|BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_INTENSITY); Sleep(600); system("cls"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED|BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_INTENSITY); printf("***********请确认您所要执行的 *** 作************n"); printf("* -------------- *n"); Sleep(50); printf("* * 1.登 录 * *n"); Sleep(50); printf("* -------------- *n"); Sleep(50); printf("* * 2.注 册 * *n"); Sleep(50); printf("* -------------- *n"); Sleep(50); printf("*********************************************n"); printf("请输入:>"); CHOICE = getchar(); getchar(); switch(CHOICE) { case '1': status = Login(); break;//登录函数,位于Login.h中,返回账号等级 case '2': Register(); break;//注册函数,位于Register.h中 default: return 1; } if (status != 0) break; } while(1) { if (status == 1) {//运动员 system("title ------Managing system------(LOGINED. ACCESS TIER: 1)"); Sleep(200); system("cls"); printf("***************运动员系统菜单**************n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 1. 选手名单 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 2. 最终得分 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 3. 选手排名 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 4. 选手查询 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 5. 修改个人密码 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 0.退出登录 *n"); Sleep(50); printf("*******************************************n"); CHOICE = getchar(); getchar(); switch(CHOICE) { case '0': { printf("是否退出登录?(Y):"); CHOICE = getchar(); getchar(); if(CHOICE == 'y' || CHOICE == 'Y') return main(); break; } case '1': Sort_name(p); break;//以下四个功能函数位于Function.c中 case '2': Cal_final_score(p); break; case '3': Sort_final_score(p); break; case '4': find_player(p); break; case '5': { RESULT = Password_Change();//修改密码函数,位于Verify.h中 if (RESULT == TRUE) printf("密码修改成功!n"); else if (RESULT == FALSE) printf("密码修改失败!n"); Sleep(1500); break; } } } else if (status == 2) {//评委 system("title ------Managing System------(LOGINED. ACCESS TIER: 2)"); Sleep(200); system("cls"); printf("请选择您要进行的 *** 作。n"); printf("****************评委管理菜单***************n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 1. 选手名单 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 2. 最终得分 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 3. 选手排名 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 4. 选手查询 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 5. 添加选手信息 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 6. 修改选手信息 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 7. 修改个人密码 *n"); Sleep(50); printf("* ------------------ *n"); Sleep(50); printf("* 0.退出登录 *n"); Sleep(50); printf("*******************************************n"); CHOICE = getchar(); getchar(); switch(CHOICE) { case '0': { printf("是否重启系统?(Y):"); scanf("%s", &CHOICE); getchar(); if(CHOICE == 'y' || CHOICE == 'Y') return main(); break; } case '1': Sort_name(p); break;//以下6个功能函数位于Function.c中 case '2': Cal_final_score(p); break; case '3': Sort_final_score(p); break; case '4': find_player(p); break; case '5': add_player(p); break; case '6': revise_player(p); break; case '7': { RESULT = Password_Change(); if (RESULT == TRUE) printf("密码修改成功!n"); else if (RESULT == FALSE) printf("密码修改失败!n"); Sleep(1500); break; } } } else if (status == 3) {//管理员 system("title ------Managing System------(LOGINED. ACCESS TIER: Admin)"); Sleep(200); system("cls"); printf("Please choose your opreation.n"); printf("************Managing System Menu************n"); printf("* ------------------ *n"); printf("* 1. 选手名单 *n"); printf("* ------------------ *n"); printf("* 2. 选手平均得分 *n"); printf("* ------------------ *n"); printf("* 3. 选手总分排名 *n"); printf("* ------------------ *n"); printf("* 4. 评委评判 *n"); printf("* ------------------ *n"); printf("* 5. 添加选手信息 *n"); printf("* ------------------ *n"); printf("* 6. 修改选手信息 *n"); printf("* ------------------ *n"); printf("* 7. 选手查询 *n"); printf("* ------------------ *n"); printf("* 8. 修改账户密码 *n"); printf("* ------------------ *n"); printf("* 0. 退出登录 *n"); printf("********************************************n"); CHOICE = getchar(); getchar(); switch(CHOICE) { case '0': { printf("是否退出登录?(Y):"); scanf("%s", &CHOICE); getchar(); if (CHOICE == 'y' || CHOICE == 'Y') return main(); break; } case '1': Sort_name(p); break; case '2': Cal_final_score(p); break; case '3': Sort_final_score(p); break; case '4': equal_unequal_judger(p); break; case '5': add_player(p); break; case '6': revise_player(p); break; case '7': find_player(p); break; case '8': { RESULT = Password_Change_Admin(); if (RESULT == TRUE) printf("密码修改成功!n"); else if (RESULT == FALSE) printf("密码修改失败!n"); Sleep(1500); break; } } } } return 0; }
Login.h
#define _CRT_SECURE_NO_WARNINGS 1 //此为登录模块 #ifndef _LOGIN_H #define _lOGIN_H #include "base.h" #include "Function.h" #include "Verify.h" //头文件的引用 int Login() {//此为登录主模块,登录查询成功则返回TRUE(1),反则FALSE(0). system("title ------Managing System------(LOGINING...)"); while(1) { system("cls"); printf("************Managing System************n"); Sleep(50); printf("* ------------------- *n"); Sleep(50); printf("* * 1.Login as Admin * *n"); Sleep(50); printf("* ------------------- *n"); Sleep(50); printf("* * 2.作为一般用户登录 * *n"); Sleep(50); printf("* ------------------- *n"); Sleep(50); printf("* * 按任意键退出登陆 * *n"); Sleep(50); printf("* ------------------- *n"); Sleep(50); printf("***************************************n"); CHOICE = getchar(); getchar(); if (CHOICE == '1') {//Login的第一次分支选择,WAY 1将进入Admin的登录 int status = Login_Admin();//进入Admin的登录验证,成功则返回TRUE,反则FALSE. printf("登录中...n"); Sleep(1000); if (status == TRUE) { printf("登录成功,欢迎!%s", Username); Sleep(2000); system("cls"); return 3; } else if (status == FALSE) { system("cls"); printf("用户名或密码出现问题,可能是输入错误,或此账户在该Tier中不存在。n"); printf("若忘记密码或账户已进入黑名单,请致电客服114514。"); Sleep(3000); } } else if (CHOICE == '2') {//WAY 2, 进入普通账户的登录 system("cls"); printf("欢迎!请选择您的账户类型:n"); printf("**************************n"); Sleep(50); printf("* -------- *n"); Sleep(50); printf("* 1.运动员 *n"); Sleep(50); printf("* -------- *n"); Sleep(50); printf("* 2.评委 *n"); Sleep(50); printf("* -------- *n"); Sleep(50); printf("**************************n"); CHOICE = getchar(); getchar(); int status; if (CHOICE == '2') status = Login_Judger();//进入评委的登陆验证,同上 else if (CHOICE == '1') status = Login_Player();//进入运动员的登陆验证,同上 system("cls"); printf("登录中...n"); Sleep(1000); if (status == TRUE) { printf("登录成功,欢迎!%sn", Username); Sleep(1000); system("cls"); if(CHOICE == '1') return 1; if(CHOICE == '2') return 2; } else if (status == FALSE) { system("cls"); printf("用户名或密码出现问题,可能是输入错误,或此账户不存在。n"); printf("若忘记密码或账户已进入黑名单,请致电客服114514。n"); Sleep(3000); } } else return 0; } } int Login_Admin() {//管理员的登录函数 for(int i = 0; i < 2; i++) { system("cls"); printf("Initalizing."); Sleep(200); printf("."); Sleep(200); printf("."); Sleep(200); } printf("nYou are entering console system...n"); Sleep(500); printf("Please enter your username:"); scanf("%s", Username); getchar(); printf("Please enter your password:"); char ch,Code[17]; int i; for (i = 0; i < 17;){ ch = getchar(); if (i > 7 && i <= 16 && ch=='n') break; if (isprint(ch)){ Code[i] = ch; i++; } } Code[i] = ''; return Verification_Admin(3, Username, Code);//进入账户密码验证函数 Verify.h } int Login_Judger() {//评委的验证函数,同理 for(int i = 0; i < 2; i++) { system("cls"); printf("载入中."); Sleep(200); printf("."); Sleep(200); printf("."); Sleep(200); } system("cls"); printf("******************************n"); printf("******************************n"); printf("**|账号: **n"); printf("**--------------------------**n"); printf("**|密码: **n"); printf("******************************n"); printf("******************************n"); gotoxy(8,2); scanf("%s", Username); getchar(); gotoxy(8,4); char ch,Code[17]; int i; for (i = 0; i < 17;){ ch = getchar(); if (i > 7 && i <= 16 && ch=='n') break; if (isprint(ch)){ Code[i] = ch; i++; } } Code[i] = ''; return Verification_Judger(2, Username, Code); } int Login_Player() {//运动员,同上 for(int i = 0; i < 2; i++) { system("cls"); printf("载入中."); Sleep(200); printf("."); Sleep(200); printf("."); Sleep(200); } system("cls"); printf("******************************n"); printf("******************************n"); printf("**|账号: **n"); printf("**--------------------------**n"); printf("**|密码: **n"); printf("******************************n"); printf("******************************n"); gotoxy(8,2); scanf("%s", Username); getchar(); gotoxy(8,4); char ch,Code[17]; int i; for (i = 0; i < 17;){ ch = getchar(); if (i > 7 && i <= 16 && ch=='n') break; if (isprint(ch)){ Code[i] = ch; i++; } } Code[i] = ''; return Verification_Player(1, Username, Code); } #endif
Register.h
//此为注册模块 #ifndef _REGISTER_H #define _REGISTER_H #include "Function.h" #include "base.h" //头文件引用 char Password_New[17]; char Password_/confirm/i[17]; char Password_Admin[17];//变量声明,后可能考虑改为结构体声明. void Register() { system("cls"); system("title ------Managing System------(REGSITERING...)"); FILE *fp = fopen("User&Password.txt", "a"); printf("您选择了注册,现请跟随指示完成 *** 作...n"); Sleep(1500); printf("欢迎,请选择您要注册的账户类型nn"); printf("1.运动员 2.评委nnn"); printf("0.退出注册n"); printf("n//管理员需要联系其他管理者完成人工注册,这是出于安全考虑。//n请输入:>"); CHOICE = getchar();//第一次路径分支 getchar(); if (CHOICE == '0') return ;//任意键退出Register函数的运行,有效性存疑 if (CHOICE == '1') { //WAY 1,运动员的注册,为正常注册步骤 system("cls"); printf("请输入您的姓名拼音,长度不能超过15n"); scanf("%s", Username); getchar(); for(int i = 0; ; i++) { printf("请输入您的新密码,长度须在8~16位n"); scanf("%s", Password); getchar(); if (strlen(Password) < 8 && strlen(Password) > 16) continue; printf("请再输入您的新密码以确认n"); scanf("%s", Password_/confirm/i); getchar(); if (strcmp(Password, Password_/confirm/i)) { printf("两次密码输入不一致!n"); Sleep(1000); continue; } else break;//此段代码仍需优化 --ElectRIC.dll } fprintf(fp, "%d %s %sn", 1, Username, Password);//录入用户密码,位置在文件末尾 printf("欢迎!运动员%s,您已完成注册。n", Username);//至此运动员注册完毕 } else if (CHOICE == '2') { system("cls"); printf("在我们欢迎新评委之前,这个 *** 作需要任意一个管理员的允许n"); Sleep(500); while(1) {//这个循环为管理员的登录步骤套用 printf("请输入任意一个管理员的用户名n请输入:>"); scanf("%s", Username); getchar(); printf("请输入密钥n请输入:>"); char ch,Code[1000]; int i; for (i = 0; i < 17;){ ch = getchar(); if (i > 7 && i <= 16 && ch=='n') break; if (isprint(ch)){ Code[i] = ch; i++; } } Code[i] = ''; if (Verification_Admin(3, Username, Code) == TRUE) break; printf("ACCESS DENIED.nn"); Sleep(1000); }//循环结束,验证为TRUE则跳出 printf("Verify_Successful.nn"); Sleep(1000); printf("请输入您的姓名拼音,长度不能超过15n请输入:>"); scanf("%s", Username); getchar(); for(int i = 0; ; i++) { printf("请输入您的新密码,长度须在8~16位n请输入:>"); scanf("%s", Password); getchar(); if (strlen(Password) < 8 && strlen(Password) > 16) { printf("新密码不符合要求!n"); continue; } printf("请再输入您的新密码以确认n请输入:>"); scanf("%s", Password_/confirm/i); getchar(); if (strcmp(Password, Password_/confirm/i)) { printf("两次密码输入不一致!n"); Sleep(1000); continue; } else break; } fprintf(fp, "%d %s %sn", 2, Username, Password);//Password_Initalize(Password)最初版本的密码加密函数 printf("欢迎!%s,您已完成注册。n", Username);//评委完成注册,中间需要一个管理员的身份验证 } fclose(fp); Sleep(1500); return ; } #endif
Verify.h
#ifndef _VERIFY_H #define _VERIFY_H //此源文件用于密码验证。 #include "Function.h" #include "base.h" int find(int Tier, char* User, char* pasw) { int Tier_FILE; int i = 0; while(!feof(st)) { fscanf(st, "%d %s %s", &Tier_FILE, Username, Password); if (Tier >= Tier_FILE && !strcmp(Username, User) && !strcmp(Password, pasw)) { fclose(st); return TRUE; } } fclose(st); return FALSE; }//此函数负责查找文件中的对应账号数据,未找到则返回FALSE. int Verification_Admin(int Tier, char* User, char* pasw) { st = fopen("User&Password.txt", "r"); //这里以及下面两个函数原为密码认证函数 //后代版本密码加密可以从此处添加 return find(Tier, User, pasw); } int Verification_Judger(int Tier, char* User, char* pasw) { st = fopen("User&Password.txt", "r"); return find(Tier, User, pasw); } int Verification_Player(int Tier, char* User, char* pasw) { st = fopen("User&Password.txt", "r"); return find(Tier, User, pasw); }//此三段函数分别为三种账号类型的验证模块. int Password_Change_Admin() { system("cls"); FILE *fp; fp = fopen("User&Password.txt", "r"); assert(fp); char name[17]; int i = 0, j = 0; printf("请输入需要修改的账户: "); scanf("%s", &name); getchar(); for (i = 0; !feof(fp); i++) { fscanf(fp, "%d %s %s", &people[i].tier, &people[i].username, &people[i].password); if (!strcmp(name, people[i].username)) { printf("请输入新密码: "); scanf("%s", &people[i].password); getchar(); } } fclose(fp); fp = fopen("User&Password.txt", "r+"); for (j = 0; j < i - 1; j++) { fprintf(fp, "%d %s %sn", people[j].tier, people[j].username, people[j].password); } fprintf(fp, "%d %s %sn", people[j].tier, people[j].username, people[j].password); fclose(fp); return TRUE; } int Password_Change() { system("cls"); FILE *fp; fp = fopen("User&Password.txt", "r"); assert(fp); char name[17]; int i = 0 ,j = 0; strcpy(name, Username); for (i = 0; !feof(fp); i++) { fscanf(fp, "%d %s %s", &people[i].tier, &people[i].username, &people[i].password); if (!strcmp(name, people[i].username)) { printf("请输入新密码: "); scanf("%s", &people[i].password); getchar(); break; } } fclose(fp); fp = fopen("User&Password.txt", "r+"); for (j = 0; j < i - 1; j++) { fprintf(fp, "%d %s %sn", people[j].tier, people[j].username, people[j].password); } fprintf(fp, "%d %s %sn", people[j].tier, people[j].username, people[j].password); fclose(fp); return TRUE; } #endif
Function.c
//此处为系统具体功能实现模块 #define _CRT_SECURE_NO_WARNINGS 1 #include "Function.h" #include "base.h" //返回上一级菜单函数 void printf_return() { printf("n返回上一级菜单?(Y)n"); CHOICE = getchar(); getchar(); if (CHOICE == 'y' || CHOICE == 'Y') return; } //1.选手姓名排序并输出 //传参:选手结构体指针;要排序的选手数量;从大到小排key=0、从小到大排key=1 void Sort_name (PI p[]){ system("cls"); char key; int i = 0; int num=read_playerinfo(); int j = 0; printf("请选择排序方式n"); printf("0. 按姓名倒序n"); printf("1. 按姓名正序n"); key=getchar(); getchar(); system("cls"); printf("姓名排序:n"); printf("选手代码 姓名n"); for (i = 0; i < num - 1; i++) { for (j = i + 1; j < num; j++) { //key=0从大到小排序、key=1从小到大排序 if ('0' == key?(strcmp(p[i].name, p[j].name) < 0) :(strcmp(p[i].name, p[j].name)) > 0) { PI t = p[i]; p[i] = p[j]; p[j] = t; } } } for (i = 0; i < num; i++) { printf("%4d %sn", p[i].id, p[i].name); } printf_return(); } //2.计算选手最后得分,并显示所有选手得分情况 //去掉一个最高分、去掉一个最低分,所得的平均分 //传参:选手结构体指针 void Cal_final_score(PI p[]) { system("cls"); int i = 0; int j = 0, num=read_playerinfo(); //i < 选手的数量 printf("选手代码 姓名 平均分n"); for (i = 0; i < num; i++) { int max = 0; int min = 10; int sum = 0; //j < 所得分数的数量 for (j = 0; j < 10; j++) { sum += p[i].i_score[j]; if(max < p[i].i_score[j]) { max = p[i].i_score[j]; } if(min > p[i].i_score[j]) { min = p[i].i_score[j]; } } //" 10 "可修改,即是评分的数量 printf("%4d %s %.1fn", p[i].id, p[i].name, (float)(sum - min - max) / 10); } printf_return(); } //3.按选手最后得分排序,输出 void Sort_final_score(PI p[]) { system("cls"); int num=read_playerinfo(); bubble_sort4(p, num); printf("选手代码 姓名 总分n"); //i < 选手的数量 for (int i = 0; i < num; i++) { printf("%4d %s %dn", p[i].id, p[i].name, p[i].f_score); } printf_return(); } //4.最公平与最不公平裁判 void equal_unequal_judger(PI p[]) { system("cls"); int judger_score[10] = {0}; float ave = 0.0; float tmp[10] = {100.0}; int sum = 0, min = 10000, max = 0, equal = 0, unequal = 0,num=read_playerinfo(); int ret_max = 0, ret_min = 0; int i = 0, j = 0; //i < 10 , 10为裁判人数 for (i = 0; i < 10; i++) { for (j = 0; j < num; j++) { judger_score[i] += p[j].i_score[i]; } } for (i = 0; i < 10; i++) { min = min > judger_score[i] ? ret_min=i, judger_score[i] : min; max = max < judger_score[i] ? ret_max=i, judger_score[i] : max; } for (i = 0; i < 10; i++) { sum += judger_score[i]; } (float)ave = sum / 10.0; for (i = 0; i < 10; i++) { if (ave >= judger_score[i]) { tmp[i] = (float)ave - judger_score[i]; } if (ave < judger_score[i]) { tmp[i] = (float)judger_score[i] - ave; } equal = tmp[equal] < tmp[i] ? equal : i; unequal = tmp[unequal] > tmp[i] ? unequal : i; } printf("给分最低裁判: %s 总分: %dn", Judger[ret_min], judger_score[ret_min]); printf("给分最高裁判: %s 总分:%dn", Judger[ret_max], judger_score[ret_max]); printf("n最公平的裁判: %s 总分:%dn", Judger[equal], judger_score[equal]); printf("最不公平的裁判:%s 总分:%dn", Judger[unequal], judger_score[unequal]); printf("n分差细明n平均分:%.1fn", ave); for (i = 0; i < 10; i++) { printf("%s %d %.1fn", Judger[i], judger_score[i], ave - judger_score[i]); } printf_return(); } //5.添加选手信息 void add_player(PI p[]) { system("cls"); int num = read_playerinfo(), i;//选手总数 i = num; num++; FILE *pi = fopen("Player_Info.txt", "r+"); assert(pi); fseek(pi, 0, SEEK_SET); fprintf(pi,"#开头为注释,"); fprintf(pi, "注释后第一行为总人数,"); fprintf(pi, "第二行开始为以下格式的具体数据n"); fprintf(pi, "#选手代码 姓 名 性别代码 评委1打分 评委2打分 评委3打分 评委4打分 评委5打分 评委6打分 评委7打分 评委8打分 评委9打分 评委10打分n%dn", num); fseek(pi, 0, SEEK_END); printf("请输入姓名:"); scanf("%s", p[i].name); getchar(); printf("请输入性别(女0/男1/保密2):"); scanf("%d", &p[i].s_id); getchar(); printf("请输入10个成绩:"); scanf("%d%d%d%d%d%d%d%d%d%d", &p[i].i_score[0],&p[i].i_score[1], &p[i].i_score[2], &p[i].i_score[3], &p[i].i_score[4], &p[i].i_score[5], &p[i].i_score[6], &p[i].i_score[7], &p[i].i_score[8], &p[i].i_score[9]); getchar(); fprintf(pi," %d %s %d %d %d %d %d %d %d %d %d %d %dn",num, p[i].name, p[i].s_id, p[i].i_score[0], p[i].i_score[1], p[i].i_score[2], p[i].i_score[3], p[i].i_score[4], p[i].i_score[5], p[i].i_score[6], p[i].i_score[7], p[i].i_score[8], p[i].i_score[9]); fclose(pi); } //6. 修改选手信息 void revise_player(PI p[]){ system("cls"); int num, i, tol;//选手编号及评委编号 char ch;//子菜单 tol = read_playerinfo(); printf("请输入要修改的选手代码:"); scanf("%d", &num); getchar(); system("cls"); num--;//数组下标原因,num减一 printf("该选手信息:%s %d %d %d %d %d %d %d %d %d %d %dn", p[num].name, p[num].s_id, p[num].i_score[0], p[num].i_score[1], p[num].i_score[2], p[num].i_score[3], p[num].i_score[4], p[num].i_score[5], p[num].i_score[6], p[num].i_score[7], p[num].i_score[8], p[num].i_score[9]); printf("请选择要修改的信息n"); printf("1. 选手姓名n"); printf("2. 选手性别n"); printf("3. 选手成绩n"); ch=getchar(); getchar(); system("cls"); switch(ch){ case '1': printf("请输入选手名字:"); scanf("%s", p[num].name); getchar(); break; case '2': printf("请输入选手性别:"); scanf("%d", &p[num].s_id); getchar(); break; case '3': printf("请输入想修改的评委分数:"); scanf("%d", &i); getchar(); system("cls"); if(i<=0&&i>10){ printf("未查询到评委信息!!!"); return ; } printf("请修改评委%d的分数:", i); i--; scanf("%d", &p[num].i_score[i]); getchar(); break; default: printf("修改错误,3秒后返回系统"); Sleep(3000); system("cls"); return ; } FILE *pi = fopen("Player_Info.txt", "w"); if (pi == NULL){ printf("修改错误,5秒后返回系统"); Sleep(5000); system("cls"); return ; } rewind(pi); fprintf(pi,"#开头为注释,注释后第一行为总人数,第二行开始为以下格式的具体数据n#选手代码 姓 名 性别代码 评委1打分 评委2打分 评委3打分 评委4打分 评委5打分 评委6打分 评委7打分 评委8打分 评委9打分 评委10打分n%dn", tol); for (int j=0;j"); key=getchar(); getchar(); switch(key) { case '0': printf("请输入要查找的选手编号:>"); scanf("%d", &id); getchar(); for (i = 0;i < 150; i++) { if (id == p[i].id) { printf("n选手编号 姓名 性别 分1 分2 分3 分4 分5 分6 分7 分8 分9 分10 总分n"); printf(" %dt%s %s %d %d %d %d %d %d %d %d %d %d %dn", p[i].id, p[i].name, p[i].sex, p[i].i_score[0], p[i].i_score[1], p[i].i_score[2], p[i].i_score[3], p[i].i_score[4], p[i].i_score[5], p[i].i_score[6], p[i].i_score[7], p[i].i_score[8], p[i].i_score[9], p[i].f_score); printf_return(); } } printf("!!!未找到编号为%d的选手!!!na", id); printf_return(); case '1': printf("请输入要查找的选手姓名:>"); scanf("%s", name); getchar(); int flag = 0; int ret[150] = { 0 }; //i < 选手的数量 for(i = 0; i < num; i++) { if (! strcmp(name, p[i].name)) { flag++; ret[i]++; } } if (flag) { //判断是否有重名选手 if (flag > 1) { printf("tnn!!!找到多个重名选手,建议使用编号进行查找!!!ann"); } printf("n选手编号 姓名 性别 分1 分2 分3 分4 分5 分6 分7 分8 分9 分10 总分n"); while (i--) { if (ret[i]) { printf(" %dt%s %s %d %d %d %d %d %d %d %d %d %d %dn", p[i].id, p[i].name, p[i].sex, p[i].i_score[0], p[i].i_score[1], p[i].i_score[2], p[i].i_score[3], p[i].i_score[4], p[i].i_score[5], p[i].i_score[6], p[i].i_score[7], p[i].i_score[8], p[i].i_score[9], p[i].f_score); } } } else { printf("!!!未找到姓名为%s的选手!!!na", name); } } printf_return(); } void gotoxy(int x, int y) { COORD p; HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); p.X = x; p.Y = y; SetConsoleCursorPosition(handle, p); }
Function.h
#ifndef _FUNCTION_H #define _FUNCTION_H #define _CRT_SECURE_NO_WARNINGS 1 #include#include #include #include #include #include #include #include #include "Struct.h" void gotoxy(int x, int y); void bubble_sort3(PI p[], int len); void bubble_sort2(PI p[], int len); void bubble_sort1(PI p[], int len); int read_annotation(FILE *p); int read_playerinfo(); int read_sexinfo(); int read_judger(); void read_data(); void Sort_name(PI p[]); void Cal_final_score(PI p[]); void Sort_final_score(PI p[]); void equal_unequal_judger(PI p[]); void add_player(PI p[]); void revise_player(PI p[]); void find_player(PI p[]); void printf_return(); int Login_Admin(); int Login_Judger(); int Login_Player(); #endif
Read.c
#include "Function.h" //读文档注释及总数 int read_annotation(FILE *p) { char flag = 0, num, ch; do {//读注释 fscanf(p, "%c", &ch); if (ch == '#') { do { fscanf(p, "%c", &ch); }while (ch != 'n'); } else {//非注释 flag = 1; num = ch - '0'; do { fscanf(p, "%c", &ch); if (ch == ' ') { continue; } if (ch == 'n') { break; } num = num *10 + ch - '0'; }while (1); } }while (0 == flag); return num; } int read_playerinfo() { //打开文档 //fopen打开data的绝对路径 FILE *pi = fopen("Player_Info.txt", "r"); assert(pi); //读取数据 int num = read_annotation(pi); //存储文件内容 for (int i = 0; i < num; i++) { fscanf(pi, "%d%s%d%d%d%d%d%d%d%d%d%d%d", &((p+i)->id), p[i].name, &p[i].s_id, &p[i].i_score[0], &p[i].i_score[1], &p[i].i_score[2], &p[i].i_score[3], &p[i].i_score[4], &p[i].i_score[5], &p[i].i_score[6], &p[i].i_score[7], &p[i].i_score[8], &p[i].i_score[9]); } for (int i = 0; i < 150; i++) { for (int j = 0; j < 10; j++) { p[i].f_score += p[i].i_score[j]; } } for (int i = 0; i < 150; i++) { if(1 == p[i].s_id) { strcpy(p[i].sex, " 男"); } if (0 == p[i].s_id) { strcpy(p[i].sex, " 女"); } if (2 == p[i].s_id) { strcpy(p[i].sex, "保密"); } } //关闭文档 fclose(pi); pi = NULL; return num; } int read_sexinfo() { //打开文档 FILE *si = fopen("S_Info.txt", "r"); assert(si); //读取 int num = read_annotation(si); SI s[3]; for (int i = 0; i < num; i++) { fscanf(si, "%d%s", &((s+i)->code), s[i].sex); //printf("%d %sn", (s+i)->code, s[i].sex); } //关闭文档 fclose(si); si = NULL; return num; } int read_judger() { //打开文档 FILE *jp = fopen("Judger.txt", "r"); assert(jp); //读取数据 int num = read_annotation(jp); for (int i = 0; i < num; i++) { fscanf(jp, "%s", Judger[i]); //printf("%sn", Judger[i]); } //关闭文档 fclose(jp); jp = NULL; return num; } void read_data() { int ret1 = read_playerinfo(); int ret2 = read_sexinfo(); int ret3 = read_judger(); return ; }
Struct.h
#define _CRT_SECURE_NO_WARNINGS 1 #ifndef _STRUCT_H #define _STRUCT_H //此文件为文件结构体存放处 //数据类型名与文件名对应 typedef struct Player_Info { int id;//选手编号 char name[32];// 姓名 int s_id;//性别代码 char sex[12]; int i_score[10];//裁判打分的10个成绩 int f_score;//个人总成绩 }PI; PI p[150];//150人,考虑追加选手信息,并设置为全部变量 typedef struct S_Info { int code;//性别代码 char sex[6];//性别名称 }SI; SI s[3];//3种情况,不考虑追加性别,设置为全局变量 char Judger[10][32];//各裁判姓名 //打分裁判人数已固定,不考虑追加打分裁判 #endif
base.h
//此为基础常量的声明 #ifndef _base_H #define _base_H #define TRUE 1 #define FALSE 0 char CHOICE;//此为每次选择时记录选项代号的全局变量 int RESULT; struct Inputstream{ char Username_Input[17]; char Password_Input[17]; char Password_Encryptecd[33]; }; struct Outputstream{ char Username_Output[17]; }; typedef struct a { int tier; char username[17]; char password[33]; }STU; char Username[17]; char Password[17]; STU people[150]; FILE* st; #endif
Bubble_sort.c
#define _CRT_SECURE_NO_WARNINGS 1 #include "function.h" //鸡尾酒双向冒泡排序 void bubble_sort4(PI p[], int len) { int last_exchange = 0; int sort_border = len - 1; for (int i = 0; i < len - 1; i++) { int flag = 1; for (int j = 0; j < sort_border; j++) { if (p[j].f_score < p[j+1].f_score) { PI temp; temp = p[j]; p[j] = p[j+1]; p[j+1] = temp; flag = 0; last_exchange = j; } } sort_border = last_exchange; if (flag) { break; } } return ; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)