commit 3a65cbab8ec470275137c922a19fb6c302d35fe4 Author: Fangnan Date: Wed Sep 28 16:24:43 2022 +0800 finished work diff --git a/README.md b/README.md new file mode 100644 index 0000000..023b8cd --- /dev/null +++ b/README.md @@ -0,0 +1,137 @@ +# 学生信息管理系统 + +## 概述 + +本套系统是我大一程序设计进阶课的结课作业,实现了登录、文件读写,以及对数据的查询、排序等操作。 + +1、单人完成代码的编写(本以为几百行能解决的系统,前前后后写了两千多行,虽然很多是注释...) + +2、本套系统基于Windows系统,执行C11标准。 + +3、项目使用Clion集成环境开发。 + +4、项目模块化,将不同功能写在不同的源文件中,通过头文件集中管理和调用。 + +5、用户输入检测,只允许用户输入规则内的数据,不合法的数据一律提示重新输入。 + +**相关文件的解释:** + +| 文件 | 解释 | +| ----------------------------------------- | -------------------------------------------- | +| for_main.h | 包含主函数所需的所有头文件 | +| user.h | 定义登录用户的相关信息结构体 | +| stu_info.h | 定义用于存储学生信息的结构体 | +| for_function_module.h | 包含每个模块函数所需的头文件以及主函数的声明 | +| main.c | 主函数 | +| main_menu.h & main_menu.c | 主菜单模块 | +| secondary_menu.h & secondary_menu.c | 二级菜单模块 | +| login_module.h & login_module.c | 登录模块 | +| registered_module.h & registered_module.c | 用户注册模块 | +| add_module.h & add_module.c | 学生信息添加模块 | +| query_module.h & query_module.c | 学生信息查询模块 | +| modify_module.h & modify.c | 学生信息修改模块 | +| delete_module.h & delete_module.c | 学生信息删除模块 | +| statistic_module.h & statistic_module.c | 成绩统计模块 | + + + +## 系统结构 + +- 主菜单 +- 二级菜单 +- 登录模块 +- 注册模块 +- 学生信息添加模块 +- 学生信息查询模块 +- 学生信息修改模块 +- 学生信息删除模块 +- 成绩统计 + +## 功能详解 + +### 一、主菜单 + +本系统设置有权限,只有注册账号后输入正确的账号密码才能进入。 + +主菜单设置有输入内容的控制功能,即检测输入内容是否合法: + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E4%B8%BB%E8%8F%9C%E5%8D%951.png) + +### 二、登录模块 + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E7%99%BB%E5%BD%95%E6%A8%A1%E5%9D%97.png) + +输入正确的账号密码即可进入系统。 + +### 三、二级菜单 + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E4%BA%8C%E7%BA%A7%E8%8F%9C%E5%8D%95.png) + +二级菜单中提供5个功能,输入代码即可跳转至对应功能。 + +二级菜单设置有输入内容的控制功能,即检测输入内容是否合法: + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E4%BA%8C%E7%BA%A7%E8%8F%9C%E5%8D%95%E6%A3%80%E6%B5%8B%E8%BE%93%E5%85%A5.png) + +### 四、学生信息添加模块 + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E6%B7%BB%E5%8A%A0%E6%A8%A1%E5%9D%97.png) + +在此模块中,需依次输入学生的学号、姓名、性别、年龄、语文成绩、数学成绩、英语成绩。 + +输入结束后,学生信息被保存在stu_info目录下的stu_info.txt文件中: + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E4%BF%9D%E5%AD%98.png) + +输入结束后,提示是否继续添加,选择”是“则当前界面清除,进入下一轮的输入,否则返回二级菜单。 + +本模块同样设置有输入内容检测功能,非法输入无效。 + +### 五、学生信息查询模块 + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E6%9F%A5%E8%AF%A2%E6%A8%A1%E5%9D%97.png) + +本系统支持按学号、姓名和性别查询学生信息,输入要查询的学生的学号、姓名或性别均可查询。 + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E6%9F%A5%E8%AF%A21.png) + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E6%9F%A5%E8%AF%A22.png) + +若系统中没有要查询的学生信息,则提示: + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E6%9F%A5%E8%AF%A23.png) + +### 六、学生信息修改模块 + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E4%BF%AE%E6%94%B9%E6%A8%A1%E5%9D%97.png) + +本系统支持按学号、姓名查询学生信息并修改。 + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E4%BF%AE%E6%94%B91.png) + +依次输入修改后的学生学号、姓名、性别、年龄及各科成绩即可。 + +### 七、学生信息删除模块 + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E5%88%A0%E9%99%A4%E6%A8%A1%E5%9D%97.png) + +本系统支持按学号、姓名和性别删除学生信息,输入学生的学号、姓名或性别均可删除相关信息。 + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E5%88%A0%E9%99%A41.png) + +### 八、成绩统计模块 + +本系统支持对单科成绩的查询,包括升序、降序查询和分数段查询,同时显示该科目的平均分。 + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E6%88%90%E7%BB%A9%E7%BB%9F%E8%AE%A1%E6%A8%A1%E5%9D%97.png) + +按语文成绩升序查询: + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E6%88%90%E7%BB%A9%E7%BB%9F%E8%AE%A12.png) + +按数学成绩降序查询: + +![](https://yvling-blog-image-1257337367.cos.ap-shanghai.myqcloud.com/%E5%8D%9A%E5%AE%A2/%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/2022-04-23/%E6%88%90%E7%BB%A9%E7%BB%9F%E8%AE%A13.png) + + + diff --git a/function_module/add_module.c b/function_module/add_module.c new file mode 100644 index 0000000..39291d1 --- /dev/null +++ b/function_module/add_module.c @@ -0,0 +1,68 @@ +#include "../heads/for_function_module.h" +#include "../heads/secondary_menu.h" +#include "stdio.h" +#include "windows.h" + + +void add_module(){ + continue_add: + //˵ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢ\n"); + + char stu_num[20]; + char name[20]; + char gender[10]; + int age; + float chinese,math,english; + + //ȡûѧϢдļ + printf("->ѧѧţ"); + scanf("%s",&stu_num); + printf("->ѧ"); + scanf("%s",&name); + printf("->ѧԱ"); + scanf("%s",&gender); + printf("->ѧ䣺"); + scanf("%d",&age); + printf("->ѧijɼ"); + scanf("%f",&chinese); + printf("->ѧѧɼ"); + scanf("%f",&math); + printf("->ѧӢɼ"); + scanf("%f",&english); + + FILE *fp= fopen("../stu_info/stu_info.txt","a"); + fprintf(fp,"%-20s %-20s %-20s %-20d %-20f %-20f %-20f\n",stu_num,name,gender,age,chinese,math,english); + fclose(fp); + printf("\n->ѧϢӳɹ\n\n"); + Sleep(2000); + + re_input_add_menu_choice: + //ѯûһ + printf("->ǷҪѧϢy/n"); + char whether_continue_add; + fflush(stdin); + scanf("%c",&whether_continue_add); + switch (whether_continue_add) { + // + case 'y':{ + goto continue_add; + break; + } + // + case 'n':{ + secondary_menu(); + break; + } + //벻Ϸ + default:{ + printf("->벻Ϸ룡\n\n"); + fflush(stdin); + goto re_input_add_menu_choice; + break; + } + } +} \ No newline at end of file diff --git a/function_module/delete_module.c b/function_module/delete_module.c new file mode 100644 index 0000000..0a0a1fd --- /dev/null +++ b/function_module/delete_module.c @@ -0,0 +1,232 @@ +#include "../heads/for_function_module.h" +#include "../heads/secondary_menu.h" +#include "stdlib.h" +#include "stdio.h" +#include "windows.h" + +void delete_module(){ + char stu_num[20]; + char name[20]; + char gender[10]; + int age; + float chinese,math,english; + continue_query: + //˵ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢɾ\n\n"); + printf("->1ѧŲѯɾ\n"); + printf("->2ѯɾ\n"); + printf("->3Աѯɾ\n"); + printf("->4ϼ˵\n"); + + //ѧϢڴ + FILE *fp=fopen("../stu_info/stu_info.txt","r"); + struct stu *head,*p,*q,*t; + head=(struct stu *) malloc(sizeof(struct stu)); + head->prev=NULL; + q=head; + int count=0; + while (!feof(fp)){ + p=(struct stu *) malloc(sizeof(struct stu)); + fscanf(fp,"%s %s %s %d %f %f %f",&p->stu_num,&p->name,&p->gender,&p->age,&p->chinese,&p->math,&p->english); + p->prev=q; + q->next=p; + q=p; + count++; + } + fclose(fp); + //ݱһΪУһڵΪ + p->next=NULL; + + t=head->next; + + int whether_find=0; + //ȡû룬жִз + char query_menu_input; + printf("\n->ѡ1/2/3/4"); + fflush(stdin); + scanf("%c",&query_menu_input); + switch (query_menu_input) { + //ѧŲѯ + case '1':{ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢɾ\n\n"); + printf("->ѧѧţ"); + scanf("%s",&stu_num); + t=head->next; + while (t!=NULL){ + if(strcmp(stu_num,t->stu_num)==0){ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢɾ\n\n"); + p=t; + t->prev->next=t->next; + t->next->prev=t->prev; + whether_find+=1; + } + t=t->next; + + } + printf("ɾ%d¼\n\n",whether_find); + //޸ĺϢдļ + t=head->next; + fp= fopen("../stu_info/stu_info.txt","w"); + + for (int i = 1; i < count-1; i++) { + fprintf(fp,"%-20s %-20s %-20s %-20d %-20f %-20f %-20f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + +// while (t!=NULL){ +// fprintf(fp,"%-20s %-20s %-20s %-20d %-20f %-20f %-20f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); +// t=t->next; +// } + fclose(fp); + count=0; + + if(whether_find==0){ + printf("->ϵͳûиѧϢ\n"); + Sleep(2000); + whether_find=0; + goto continue_query; + } + break; + } + //ѯ + case '2':{ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢɾ\n\n"); + printf("->ѧ"); + scanf("%s",&name); + t=head->next; + while (t!=NULL){ + if(strcmp(name,t->name)==0){ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢɾ\n\n"); + p=t; + t->prev->next=t->next; + t->next->prev=t->prev; + whether_find+=1; + } + t=t->next; + + } + printf("ɾ%d¼\n\n",whether_find); + //޸ĺϢдļ + t=head->next; + fp= fopen("../stu_info/stu_info.txt","w"); + + for (int i = 1; i < count-1; i++) { + fprintf(fp,"%-20s %-20s %-20s %-20d %-20f %-20f %-20f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } +// while (t!=NULL){ +// fprintf(fp,"%-20s %-20s %-20s %-20d %-20f %-20f %-20f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); +// t=t->next; +// } + fclose(fp); + count=0; + + if(whether_find==0){ + printf("->ϵͳûиѧϢ\n"); + Sleep(2000); + whether_find=0; + goto continue_query; + } + break; + } + //Աѯ + case '3':{ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢɾ\n\n"); + printf("->ѧԱ"); + scanf("%s",&gender); + t=head->next; + while (t!=NULL){ + if(strcmp(gender,t->gender)==0){ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢɾ\n\n"); + p=t; + t->prev->next=t->next; + t->next->prev=t->prev; + whether_find+=1; + count--; + } + t=t->next; + + } + printf("ɾ%d¼\n\n",whether_find); + + //޸ĺϢдļ + t=head->next; + fp=fopen("../stu_info/stu_info.txt","w"); + + for (int i = 1; i < count; i++) { + fprintf(fp,"%-20s %-20s %-20s %-20d %-20f %-20f %-20f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } +// while (t!=NULL){ +// fprintf(fp,"%-20s %-20s %-20s %-20d %-20f %-20f %-20f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); +// t=t->next; +// } + fclose(fp); + count=0; + + if(whether_find==0){ + printf("->ϵͳûиѧϢ\n"); + Sleep(2000); + whether_find=0; + goto continue_query; + } + break; + } + //ϼ˵ + case '4':{ + secondary_menu(); + } + //벻Ϸ + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto continue_query; + } + } + //ȡû룬жִз + char whether_continue_query; + printf("Ƿɾy/n"); + scanf("%c",&whether_continue_query); + switch (whether_continue_query) { + //ɾ + case 'y':{ + goto continue_query; + break; + } + //ɾ + case 'n':{ + secondary_menu(); + break; + } + //벻Ϸ + default:{ + printf("->벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto continue_query; + break; + } + } +} \ No newline at end of file diff --git a/function_module/login_module.c b/function_module/login_module.c new file mode 100644 index 0000000..477a989 --- /dev/null +++ b/function_module/login_module.c @@ -0,0 +1,102 @@ +#include "stdio.h" +#include "string.h" +#include "windows.h" +#include "stdlib.h" +#include "../heads/for_function_module.h" +#include "../heads/users.h" +#include "../heads/secondary_menu.h" +#include "../heads/registered_module.h" + +void login_module(){ + //¼ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n\n"); + printf("-> ǰλã¼\n\n"); + printf("-> ˺ţ"); + + //ȡû˺ + char account_input[20]; + fflush(stdin); + scanf("%s",&account_input); + + struct user *head,*p,*q; + head=(struct user *) malloc(sizeof(struct user)); + q=head; + + //˺ļڴ + FILE *fp; + fp = fopen("../users/users.txt", "r"); + while (!feof(fp)){ + p=(struct user *)malloc(sizeof(struct user)); + fscanf(fp,"%s %s",&p->account,&p->password); + q->next=p; + q=p; + } + fclose(fp); + p->next=NULL; + + //ж˺Ƿ + int account_exist=0; + p=head->next; + while (p!=NULL){ + //˺Ŵ + if(strcmp(account_input,p->account)==0){ + //ȡû + char password[20]; + int password_input_count=0; + re_input_password: + printf("-> 룺"); + fflush(stdin); + scanf("%s",&password); + //ȷ + if(strcmp(password,p->password)==0){ + //ת˵ + account_exist=1; + secondary_menu(); + break; + } + // + else{ + password_input_count++; + if(password_input_count<3){ + printf("->ԣ\n"); + fflush(stdin); + goto re_input_password; + } + else{ + printf("->࣬Ժԡ\n"); + fflush(stdin); + Sleep(2000); + main(); + } + } + } + p=p->next; + } + //˺Ų + if(account_exist!=1){ + re_input_whether_registered: + printf("->˺ŲڣǷע᣿y/n"); + char whether_registered; + fflush(stdin); + scanf("%c",&whether_registered); + switch (whether_registered) { + //תעģ + case 'y':{ + registered_module(); + break; + } + //˵ + case 'n':{ + main(); + } + //벻Ϸ + default:{ + printf("->벻Ϸ룡\n"); + fflush(stdin); + goto re_input_whether_registered; + } + } + } +} \ No newline at end of file diff --git a/function_module/main_menu.c b/function_module/main_menu.c new file mode 100644 index 0000000..2249146 --- /dev/null +++ b/function_module/main_menu.c @@ -0,0 +1,43 @@ +#include "stdio.h" +#include "windows.h" + +void main_menu(){ + system("cls"); + fflush(stdin); + printf("|-----------------------------------ѧϢϵͳ---------------------------------|\n"); + printf("| + + |\n"); + printf("| ة ة++ |\n"); + printf("| |\n"); + printf("| ++ + + + |\n"); + printf("| + |\n"); + printf("| + |\n"); + printf("| ة |\n"); + printf("| |\n"); + printf("| |\n"); + printf("| |\n"); + printf("| + + |\n"); + printf("| |\n"); + printf("| |\n"); + printf("| |\n"); + printf("| |\n"); + printf("| |\n"); + printf("| |\n"); + printf("| Щ + + + + |\n"); + printf("| |\n"); + printf("| ة ة + + + + |\n"); + printf("|------------------------------------------------------------------------------------|\n"); + + printf("|-> 1¼ -> 2ע -> 3˳ |\n"); + printf("|------------------------------------------------------------------------------------|\n\n"); +} + + + + + + + + + + + diff --git a/function_module/modify_module.c b/function_module/modify_module.c new file mode 100644 index 0000000..377a988 --- /dev/null +++ b/function_module/modify_module.c @@ -0,0 +1,226 @@ +#include "../heads/for_function_module.h" +#include "../heads/secondary_menu.h" +#include "stdio.h" +#include "windows.h" + +void modify_module(){ + char stu_num[20]; + char name[20]; + + continue_modify: + //ѧϢ޸IJ˵ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢ޸\n\n"); + printf("->1ѧŲѯ޸\n"); + printf("->2ѯ޸\n"); + printf("->3ϼ˵\n"); + + //ѧϢڴ + FILE *fp=fopen("../stu_info/stu_info.txt","r"); + struct stu *head,*p,*q,*t; + head=(struct stu *) malloc(sizeof(struct stu)); + head->prev=NULL; + q=head; + int count=0; + while (!feof(fp)){ + p=(struct stu *) malloc(sizeof(struct stu)); + fscanf(fp,"%s %s %s %d %f %f %f",&p->stu_num,&p->name,&p->gender,&p->age,&p->chinese,&p->math,&p->english); + p->prev=q; + q->next=p; + q=p; + count++; + } + fclose(fp); + //ݱһΪУһڵΪ + p->next=NULL; + + //ȡû룬жִз + char modify_menu_input; + printf("\n->ѡ1/2/3"); + fflush(stdin); + scanf("%c",&modify_menu_input); + switch (modify_menu_input) { + //ѧŲѯɾ + case '1':{ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢ޸\n\n"); + printf("->ѧѧţ"); + scanf("%s",&stu_num); + t=head->next; + + t=head->next; + int whether_find=0; + while (t!=NULL){ + if(strcmp(stu_num,t->stu_num)==0){ + whether_find=1; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢ޸\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + printf("޸ĺѧѧţ"); + fflush(stdin); + scanf("%s",&t->stu_num); + printf("޸ĺѧ"); + fflush(stdin); + scanf("%s",&t->name); + printf("޸ĺѧԱ"); + fflush(stdin); + scanf("%s",&t->gender); + printf("޸ĺѧ䣺"); + fflush(stdin); + scanf("%d",&t->age); + printf("޸ĺijɼ"); + fflush(stdin); + scanf("%f",&t->chinese); + printf("޸ĺѧɼ"); + fflush(stdin); + scanf("%f",&t->math); + printf("޸ĺӢɼ"); + fflush(stdin); + scanf("%f",&t->english); + } + t=t->next; + } + if(whether_find==0){ + printf("δѯѧϢ\n"); + Sleep(2000); + goto continue_modify; + } + else{ + //޸ĺϢдļ + t=head->next; + fp= fopen("../stu_info/stu_info.txt","w"); + + for (int i = 1; i < count; i++) { + fprintf(fp,"%-20s %-20s %-20s %-20d %-20f %-20f %-20f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + printf("޸ijɹ\n"); + Sleep(2000); + modify_menu_re1: + printf("Ƿ޸ģy/n"); + char whether_continue_modify; + fflush(stdin); + scanf("%c",&whether_continue_modify); + switch (whether_continue_modify) { + case 'y':{ + goto continue_modify; + } + case 'n':{ + secondary_menu(); + } + default: { + printf("벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto modify_menu_re1; + } + } + } + break; + } + + //ѯɾ + case '2':{ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢ޸\n\n"); + printf("->ѧ"); + scanf("%s",&name); + + t=head->next; + int whether_find=0; + while (t!=NULL){ + if(strcmp(name,t->name)==0){ + whether_find=1; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢ޸\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + printf("޸ĺѧѧţ"); + fflush(stdin); + scanf("%s",&t->stu_num); + printf("޸ĺѧ"); + fflush(stdin); + scanf("%s",&t->name); + printf("޸ĺѧԱ"); + fflush(stdin); + scanf("%s",&t->gender); + printf("޸ĺѧ䣺"); + fflush(stdin); + scanf("%d",&t->age); + printf("޸ĺijɼ"); + fflush(stdin); + scanf("%f",&t->chinese); + printf("޸ĺѧɼ"); + fflush(stdin); + scanf("%f",&t->math); + printf("޸ĺӢɼ"); + fflush(stdin); + scanf("%f",&t->english); + } + t=t->next; + } + if(whether_find==0){ + printf("δѯѧϢ\n"); + Sleep(2000); + goto continue_modify; + } + else{ + //޸ĺϢдļ + t=head->next; + fp= fopen("../stu_info/stu_info.txt","w"); + + for (int i = 1; i < count; i++) { + fprintf(fp,"%-20s %-20s %-20s %-20d %-20f %-20f %-20f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + printf("޸ijɹ\n"); + Sleep(2000); + modify_menu_re2: + printf("Ƿ޸ģy/n"); + char whether_continue_modify; + fflush(stdin); + scanf("%c",&whether_continue_modify); + switch (whether_continue_modify) { + case 'y':{ + goto continue_modify; + } + case 'n':{ + secondary_menu(); + } + default: { + printf("벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto modify_menu_re2; + } + } + } + break; + } + + //ϼ˵ + case '3':{ + secondary_menu(); + break; + } + + default: { + printf("벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto continue_modify; + } + } + +} \ No newline at end of file diff --git a/function_module/query_module.c b/function_module/query_module.c new file mode 100644 index 0000000..bc54dd6 --- /dev/null +++ b/function_module/query_module.c @@ -0,0 +1,173 @@ +#include "../heads/for_function_module.h" +#include "../heads/secondary_menu.h" +#include "stdlib.h" +#include "stdio.h" +#include "windows.h" + +void query_module(){ + char stu_num[20]; + char name[20]; + char gender[10]; + int age; + float chinese,math,english; + continue_query: + //ѯ˵ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("->1ѧŲѯ\n"); + printf("->2ѯ\n"); + printf("->3Աѯ\n"); + printf("->4ϼ˵\n"); + + //ѧϢڴ + FILE *fp=fopen("../stu_info/stu_info.txt","r"); + struct stu *head,*p,*q,*t; + head=(struct stu *) malloc(sizeof(struct stu)); + head->prev=NULL; + q=head; + while (!feof(fp)){ + p=(struct stu *) malloc(sizeof(struct stu)); + fscanf(fp,"%s %s %s %d %f %f %f",&p->stu_num,&p->name,&p->gender,&p->age,&p->chinese,&p->math,&p->english); + p->prev=q; + q->next=p; + q=p; + } + fclose(fp); + //ݱһΪУһڵΪ + p->prev->next=NULL; + + t=head->next; + + int whether_find=0; + //ȡû룬жִз + char query_menu_input; + printf("\n->ѡ1/2/3/4"); + fflush(stdin); + scanf("%c",&query_menu_input); + switch (query_menu_input) { + //ѧŲѯ + case '1':{ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("->ѧѧţ"); + scanf("%s",&stu_num); + t=head->next; + while (t!=NULL){ + if(strcmp(stu_num,t->stu_num)==0){ + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + whether_find=1; + } + t=t->next; + } + if(whether_find==0){ + printf("->ϵͳûиѧϢ\n"); + Sleep(2000); + whether_find=0; + goto continue_query; + } + break; + } + //ѯ + case '2':{ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("->ѧ"); + scanf("%s",&name); + t=head->next; + while (t!=NULL){ + if(strcmp(name,t->name)==0){ + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + whether_find=1; + } + t=t->next; + } + if(whether_find==0){ + printf("->ϵͳûиѧϢ\n"); + Sleep(2000); + whether_find=0; + goto continue_query; + } + break; + } + //Աѯ + case '3':{ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("->ѧԱ"); + scanf("%s",&gender); + t=head->next; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + while (t!=NULL){ + if(strcmp(gender,t->gender)==0){ + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + whether_find=1; + } + t=t->next; + } + if(whether_find==0){ + printf("->ϵͳûиѧϢ\n"); + Sleep(2000); + whether_find=0; + goto continue_query; + } + break; + } + //ϼ˵ + case '4':{ + secondary_menu(); + } + //벻Ϸ + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto continue_query; + } + } + //ȡû룬жִз + char whether_continue_query; + printf("Ƿѯy/n"); + scanf("%c",&whether_continue_query); + switch (whether_continue_query) { + // + case 'y':{ + goto continue_query; + break; + } + // + case 'n':{ + secondary_menu(); + break; + } + //벻Ϸ + default:{ + printf("->벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto continue_query; + break; + } + } +} \ No newline at end of file diff --git a/function_module/registered_module.c b/function_module/registered_module.c new file mode 100644 index 0000000..c231d1d --- /dev/null +++ b/function_module/registered_module.c @@ -0,0 +1,72 @@ +#include "stdio.h" +#include "string.h" +#include "windows.h" +#include "../heads/for_function_module.h" +#include "../heads/users.h" + +void registered_module() { + re_registered: + //ע + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n\n"); + printf("->ǰλãע\n\n"); + + char account[20]; + char password1[20]; + char password2[20]; + printf("->˺ţ"); + fflush(stdin); + scanf("%s",&account); + + //ûǷѾ + struct user *head,*p,*q; + head=(struct user *) malloc(sizeof(struct user)); + q=head; + + //˺ļڴ + FILE *fp; + fp = fopen("../users/users.txt", "r"); + while (!feof(fp)){ + p=(struct user *)malloc(sizeof(struct user)); + fscanf(fp,"%s %s",&p->account,&p->password); + q->next=p; + q=p; + } + fclose(fp); + p->next=NULL; + + //ж˺Ƿ + p=head->next; + while (p!=NULL){ + //˺Ŵ + if(strcmp(account,p->account)==0){ + printf("˺Ѿڣ뻻һ˺ţ\n\n"); + Sleep(2000); + goto re_registered; + } + p=p->next; + } + + //˺Ų + printf("룺"); + scanf("%s",&password1); + printf("ȷ룺"); + scanf("%s",&password2); + + //жǷһ + if(strcmp(password1,password2)==0){ + FILE *fp; + fp = fopen("../users/users.txt", "a"); + fprintf(fp,"%-20s %-20s",account,password1); + fclose(fp); + printf("עɹ\n"); + Sleep(2000); + main(); + } + else{ + printf("벻һ£ԣ\n\n"); + Sleep(2000); + goto re_registered; + } +} diff --git a/function_module/secondary_menu.c b/function_module/secondary_menu.c new file mode 100644 index 0000000..f000095 --- /dev/null +++ b/function_module/secondary_menu.c @@ -0,0 +1,66 @@ +#include "../heads/for_function_module.h" +#include "../heads/add_module.h" +#include "../heads/query_module.h" +#include "../heads/delete_module.h" +#include "../heads/statistic_module.h" +#include "../heads/modify_module.h" +#include "stdio.h" +#include "windows.h" + +void secondary_menu(){ + //˵ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n\n"); + printf("->ǰλãѧϢ\n\n"); + printf("-> 1ѧϢ\n"); + printf("-> 2ѯѧϢ\n"); + printf("-> 3޸ѧϢ\n"); + printf("-> 4ɾѧϢ\n"); + printf("-> 5ɼͳ\n"); + printf("-> 6˵\n"); + + //ȡû룬жִз + char secondary_menu_input; + re_input_secondary_menu_choice: + printf("\n->ѡ1/2/3/4/5/6"); + fflush(stdin); + scanf("%c",&secondary_menu_input); + switch (secondary_menu_input) { + //ѧϢ + case '1':{ + add_module(); + break; + } + //ѯѧϢ + case '2':{ + query_module(); + break; + } + //޸ѧϢ + case '3':{ + modify_module(); + break; + } + //ɾѧϢ + case '4':{ + delete_module(); + break; + } + //ɼͳ + case '5':{ + statistic_module(); + break; + } + //˵ + case '6':{ + main(); + } + //벻Ϸ + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto re_input_secondary_menu_choice; + } + } +} \ No newline at end of file diff --git a/function_module/statistic_module.c b/function_module/statistic_module.c new file mode 100644 index 0000000..c13b330 --- /dev/null +++ b/function_module/statistic_module.c @@ -0,0 +1,848 @@ +#include "../heads/for_function_module.h" +#include "../heads/secondary_menu.h" +#include "stdio.h" +#include "windows.h" + +void statistic_module(){ + + float chinese_av(); + float math_av(); + float english_av(); + + continue_statistic: + //ɼͳƲ˵ + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧɼͳ\n\n"); + printf("->1ijɼͳ\n"); + printf("->2ѧɼͳ\n"); + printf("->3Ӣɼͳ\n"); + printf("->4ϼ˵\n"); + + //ѧϢڴ + FILE *fp=fopen("../stu_info/stu_info.txt","r"); + struct stu *head,*p,*q,*t,*r; + head=(struct stu *) malloc(sizeof(struct stu)); + head->prev=NULL; + q=head; + int info_num=0; + while (!feof(fp)){ + p=(struct stu *) malloc(sizeof(struct stu)); + fscanf(fp,"%s %s %s %d %f %f %f",&p->stu_num,&p->name,&p->gender,&p->age,&p->chinese,&p->math,&p->english); + info_num+=1; + p->prev=q; + q->next=p; + q=p; + } + fclose(fp); + //ݱһΪУһڵΪ + p->prev->next=NULL; + //¼ + info_num=info_num-1; + + + + //ȡû룬жִз + char statistic_menu_input; + printf("\n->ѡ1/2/3/4"); + fflush(stdin); + scanf("%c",&statistic_menu_input); + switch (statistic_menu_input) { + //ͳijɼ + case '1':{ + chinese_statistic: + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãijɼͳ\n\n"); + printf("->1ѯ\n"); + printf("->2ѯ\n"); + printf("->3βѯ\n"); + printf("->4ϼ˵\n"); + + //ȡû룬жִз + char chinese_menu_input; + printf("\n->ѡ1/2/3/4"); + fflush(stdin); + scanf("%c",&chinese_menu_input); + switch (chinese_menu_input) { + //ѯ + case '1':{ + // + p=head->next; + r=p->next; + p->next=NULL; + p=r; + + while(p!=NULL) + { + r=p->next; + q=head; + while(q->next!=NULL&&q->next->chinesechinese) + { + q=q->next; + } + p->next=q->next; + q->next=p; + p=r; + } + + //Ľ + t=head->next; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + while (t!=NULL){ + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + + printf("\n"); + printf("->ƽΪ%.2f\n\n",chinese_av()); + + chinese_statistic_re1: + //ȡû룬жִз + printf("->Ƿѯy/n"); + fflush(stdin); + scanf("%c",&statistic_menu_input); + switch (statistic_menu_input) { + case 'y':{ + goto continue_statistic; + //break; + } + case 'n':{ + secondary_menu(); + //break; + } + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto chinese_statistic_re1; + //break; + } + } + //break; + } + + + //ѯ + case '2':{ + // + p=head->next; + r=p->next; + p->next=NULL; + p=r; + + while(p!=NULL) + { + r=p->next; + q=head; + while(q->next!=NULL&&q->next->chinese>p->chinese) + { + q=q->next; + } + p->next=q->next; + q->next=p; + p=r; + } + + //Ľ + t=head->next; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + while (t!=NULL){ + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + + printf("\n"); + printf("->ƽΪ%.2f\n\n",chinese_av()); + + chinese_statistic_re2: + //ȡû룬жִз + printf("->Ƿѯy/n"); + fflush(stdin); + scanf("%c",&statistic_menu_input); + switch (statistic_menu_input) { + case 'y':{ + goto continue_statistic; + //break; + } + case 'n':{ + secondary_menu(); + break; + } + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto chinese_statistic_re2; + //break; + } + } + break; + } + + + //βѯ + case '3':{ + system("cls"); + fflush(stdin); + float min,max; + chinese_query_by_fractional_segment: + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãijɼβѯ\n\n"); + printf("->Ҫѯijɼ:\n"); + printf("->ͷ֣"); + fflush(stdin); + scanf("%f",&min); + printf("->߷֣"); + fflush(stdin); + scanf("%f",&max); + + //ûǷϷ + if(min>max){ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto chinese_query_by_fractional_segment; + } + else{ + q=head; + p=head->next; + while (p!=NULL){ + if(p->chinesechinese>max){ + r=p; + p=p->next; + q->next=p; + free(r); + } + else{ + p=p->next; + q=q->next; + } + } + } + + //Ľ + t=head->next; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + while (t!=NULL){ + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + + printf("\n"); + printf("->ƽΪ%.2f\n\n",chinese_av()); + + chinese_query_by_fractional_segment_re: + //ȡû룬жִз + printf("->Ƿѯy/n"); + fflush(stdin); + scanf("%c",&statistic_menu_input); + switch (statistic_menu_input) { + case 'y': { + goto continue_statistic; + //break; + } + case 'n': { + secondary_menu(); + break; + } + default: { + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto chinese_query_by_fractional_segment_re; + //break; + } + } + break; + } + //ϼ˵ + case '4':{ + goto continue_statistic; + //break; + } + //벻Ϸ + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto chinese_statistic; + //break; + } + } + } + //ͳѧɼ + case '2':{ + math_statistic: + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãѧɼͳ\n\n"); + printf("->1ѯ\n"); + printf("->2ѯ\n"); + printf("->3βѯ\n"); + printf("->4ϼ˵\n"); + + //ȡû룬жִз + char math_menu_input; + printf("\n->ѡ1/2/3/4"); + fflush(stdin); + scanf("%c",&math_menu_input); + switch (math_menu_input) { + //ѯ + case '1':{ + // + p=head->next; + r=p->next; + p->next=NULL; + p=r; + + while(p!=NULL) + { + r=p->next; + q=head; + while(q->next!=NULL&&q->next->mathmath) + { + q=q->next; + } + p->next=q->next; + q->next=p; + p=r; + } + + //Ľ + t=head->next; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + while (t!=NULL){ + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + + printf("\n"); + printf("->ѧƽΪ%.2f\n\n",math_av()); + + math_statistic_re1: + //ȡû룬жִз + printf("->Ƿѯy/n"); + fflush(stdin); + scanf("%c",&statistic_menu_input); + switch (statistic_menu_input) { + case 'y':{ + goto continue_statistic; + //break; + } + case 'n':{ + secondary_menu(); + break; + } + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto math_statistic_re1; + //break; + } + } + break; + } + + + //ѯ + case '2':{ + // + p=head->next; + r=p->next; + p->next=NULL; + p=r; + + while(p!=NULL) + { + r=p->next; + q=head; + while(q->next!=NULL&&q->next->math>p->math) + { + q=q->next; + } + p->next=q->next; + q->next=p; + p=r; + } + + //Ľ + t=head->next; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + while (t!=NULL){ + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + + printf("\n"); + printf("->ѧƽΪ%.2f\n\n",math_av()); + + math_statistic_re2: + //ȡû룬жִз + printf("->Ƿѯy/n"); + fflush(stdin); + scanf("%c",&statistic_menu_input); + switch (statistic_menu_input) { + case 'y':{ + goto continue_statistic; + //break; + } + case 'n':{ + secondary_menu(); + break; + } + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto math_statistic_re2; + //break; + } + } + break; + } + + + //βѯ + case '3':{ + system("cls"); + fflush(stdin); + float min,max; + math_query_by_fractional_segment: + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãɼβѯ\n\n"); + printf("->Ҫѯѧɼ:\n"); + printf("->ͷ֣"); + fflush(stdin); + scanf("%f",&min); + printf("->߷֣"); + fflush(stdin); + scanf("%f",&max); + + //ûǷϷ + if(min>max){ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto math_query_by_fractional_segment; + } + else{ + q=head; + p=head->next; + while (p!=NULL){ + if(p->mathmath>max){ + r=p; + p=p->next; + q->next=p; + free(r); + } + else{ + p=p->next; + q=q->next; + } + } + } + + //Ľ + t=head->next; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + while (t!=NULL){ + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + + printf("\n"); + printf("->ѧƽΪ%.2f\n\n",math_av()); + + math_query_by_fractional_segment_re: + //ȡû룬жִз + printf("->Ƿѯy/n"); + fflush(stdin); + scanf("%c",&statistic_menu_input); + switch (statistic_menu_input) { + case 'y': { + goto continue_statistic; + //break; + } + case 'n': { + secondary_menu(); + break; + } + default: { + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto math_query_by_fractional_segment_re; + //break; + } + } + break; + } + //ϼ˵ + case '4':{ + goto continue_statistic; + //break; + } + //벻Ϸ + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto math_statistic; + //break; + } + } + break; + } + //ͳӢɼ + case '3':{ + english_statistic: + system("cls"); + fflush(stdin); + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãӢɼͳ\n\n"); + printf("->1ѯ\n"); + printf("->2ѯ\n"); + printf("->3βѯ\n"); + printf("->4ϼ˵\n"); + + //ȡû룬жִз + char english_menu_input; + printf("\n->ѡ1/2/3/4"); + fflush(stdin); + scanf("%c",&english_menu_input); + switch (english_menu_input) { + //ѯ + case '1':{ + // + p=head->next; + r=p->next; + p->next=NULL; + p=r; + + while(p!=NULL) + { + r=p->next; + q=head; + while(q->next!=NULL&&q->next->englishenglish) + { + q=q->next; + } + p->next=q->next; + q->next=p; + p=r; + } + + //Ľ + t=head->next; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + while (t!=NULL){ + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + + printf("\n"); + printf("->ӢƽΪ%.2f\n\n",english_av()); + + english_statistic_re1: + //ȡû룬жִз + printf("->Ƿѯy/n"); + fflush(stdin); + scanf("%c",&statistic_menu_input); + switch (statistic_menu_input) { + case 'y':{ + goto continue_statistic; + //break; + } + case 'n':{ + secondary_menu(); + break; + } + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto english_statistic_re1; + //break; + } + } + break; + } + + + //ѯ + case '2':{ + // + p=head->next; + r=p->next; + p->next=NULL; + p=r; + + while(p!=NULL) + { + r=p->next; + q=head; + while(q->next!=NULL&&q->next->english>p->english) + { + q=q->next; + } + p->next=q->next; + q->next=p; + p=r; + } + + //Ľ + t=head->next; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + while (t!=NULL){ + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + + printf("\n"); + printf("->ӢƽΪ%.2f\n\n",english_av()); + + english_statistic_re2: + //ȡû룬жִз + printf("->Ƿѯy/n"); + fflush(stdin); + scanf("%c",&statistic_menu_input); + switch (statistic_menu_input) { + case 'y':{ + goto continue_statistic; + //break; + } + case 'n':{ + secondary_menu(); + break; + } + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto english_statistic_re2; + //break; + } + } + break; + } + + + //βѯ + case '3':{ + system("cls"); + fflush(stdin); + float min,max; + english_query_by_fractional_segment: + printf("------------------------------ѧϢϵͳ------------------------------\n"); + printf("->ǰλãɼβѯ\n\n"); + printf("->ҪѯӢɼ:\n"); + printf("->ͷ֣"); + fflush(stdin); + scanf("%f",&min); + printf("->߷֣"); + fflush(stdin); + scanf("%f",&max); + + //ûǷϷ + if(min>max){ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto english_query_by_fractional_segment; + } + else{ + q=head; + p=head->next; + while (p!=NULL){ + if(p->englishenglish>max){ + r=p; + p=p->next; + q->next=p; + free(r); + } + else{ + p=p->next; + q=q->next; + } + } + } + + //Ľ + t=head->next; + system("cls"); + fflush(stdin); + printf("-------------------------------------------------ѧϢϵͳ-------------------------------------------------\n"); + printf("->ǰλãѧϢѯ\n\n"); + printf("ѧ Ա ijɼ ѧɼ Ӣɼ\n\n"); + while (t!=NULL){ + printf("%-20s %-20s %-10s %-10d %-20.2f %-20.2f %-20.2f\n",t->stu_num,t->name,t->gender,t->age,t->chinese,t->math,t->english); + t=t->next; + } + + printf("\n"); + printf("->ӢƽΪ%.2f\n\n",english_av()); + + english_query_by_fractional_segment_re: + //ȡû룬жִз + printf("->Ƿѯy/n"); + fflush(stdin); + scanf("%c",&statistic_menu_input); + switch (statistic_menu_input) { + case 'y': { + goto continue_statistic; + //break; + } + case 'n': { + secondary_menu(); + break; + } + default: { + printf("벻Ϸ룡\n\n"); + fflush(stdin); + goto english_query_by_fractional_segment_re; + //break; + } + } + break; + } + //ϼ˵ + case '4':{ + goto continue_statistic; + //break; + } + //벻Ϸ + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto math_statistic; + //break; + } + } + break; + } + //ϼ˵ + case '4':{ + secondary_menu(); + break; + } + //벻Ϸ + default:{ + printf("벻Ϸ룡\n\n"); + fflush(stdin); + Sleep(2000); + goto continue_statistic; + } + } +} + + +float chinese_av(){ + float chinese_sum=0,chinese_av; + + //ѧϢڴ + FILE *fp=fopen("../stu_info/stu_info.txt","r"); + struct stu *head,*p,*q,*t,*r; + head=(struct stu *) malloc(sizeof(struct stu)); + head->prev=NULL; + q=head; + int info_num=0; + while (!feof(fp)){ + p=(struct stu *) malloc(sizeof(struct stu)); + fscanf(fp,"%s %s %s %d %f %f %f",&p->stu_num,&p->name,&p->gender,&p->age,&p->chinese,&p->math,&p->english); + chinese_sum+=p->chinese; + info_num+=1; + p->prev=q; + q->next=p; + q=p; + } + fclose(fp); + //ݱһΪУһڵΪ + p->prev->next=NULL; + //¼ + info_num=info_num-1; + chinese_av=chinese_sum/info_num; + return chinese_av; +} + +float math_av(){ + float math_sum=0,math_av; + + //ѧϢڴ + FILE *fp=fopen("../stu_info/stu_info.txt","r"); + struct stu *head,*p,*q,*t,*r; + head=(struct stu *) malloc(sizeof(struct stu)); + head->prev=NULL; + q=head; + int info_num=0; + while (!feof(fp)){ + p=(struct stu *) malloc(sizeof(struct stu)); + fscanf(fp,"%s %s %s %d %f %f %f",&p->stu_num,&p->name,&p->gender,&p->age,&p->chinese,&p->math,&p->english); + math_sum+=p->math; + info_num+=1; + p->prev=q; + q->next=p; + q=p; + } + fclose(fp); + //ݱһΪУһڵΪ + p->prev->next=NULL; + //¼ + info_num=info_num-1; + math_av=math_sum/info_num; + return math_av; +} + +float english_av(){ + float english_sum=0,english_av; + + //ѧϢڴ + FILE *fp=fopen("../stu_info/stu_info.txt","r"); + struct stu *head,*p,*q,*t,*r; + head=(struct stu *) malloc(sizeof(struct stu)); + head->prev=NULL; + q=head; + int info_num=0; + while (!feof(fp)){ + p=(struct stu *) malloc(sizeof(struct stu)); + fscanf(fp,"%s %s %s %d %f %f %f",&p->stu_num,&p->name,&p->gender,&p->age,&p->chinese,&p->math,&p->english); + english_sum+=p->english; + info_num+=1; + p->prev=q; + q->next=p; + q=p; + } + fclose(fp); + //ݱһΪУһڵΪ + p->prev->next=NULL; + //¼ + info_num=info_num-1; + english_av=english_sum/info_num; + return english_av; +} \ No newline at end of file diff --git a/heads/add_module.h b/heads/add_module.h new file mode 100644 index 0000000..cfbf52d --- /dev/null +++ b/heads/add_module.h @@ -0,0 +1 @@ +void add_module(); \ No newline at end of file diff --git a/heads/delete_module.h b/heads/delete_module.h new file mode 100644 index 0000000..2a381f1 --- /dev/null +++ b/heads/delete_module.h @@ -0,0 +1 @@ +void delete_module(); \ No newline at end of file diff --git a/heads/for_function_module.h b/heads/for_function_module.h new file mode 100644 index 0000000..a5b19d8 --- /dev/null +++ b/heads/for_function_module.h @@ -0,0 +1,2 @@ +#include "stu_info.h" +int main(); \ No newline at end of file diff --git a/heads/for_main.h b/heads/for_main.h new file mode 100644 index 0000000..cbc7914 --- /dev/null +++ b/heads/for_main.h @@ -0,0 +1,12 @@ +#include "stdio.h" +#include "stdlib.h" +#include "windows.h" +#include "main_menu.h" +#include "login_module.h" +#include "registered_module.h" +#include "secondary_menu.h" +#include "add_module.h" +#include "query_module.h" +#include "delete_module.h" +#include "statistic_module.h" +#include "modify_module.h" diff --git a/heads/login_module.h b/heads/login_module.h new file mode 100644 index 0000000..5288e1c --- /dev/null +++ b/heads/login_module.h @@ -0,0 +1 @@ +void login_module(); \ No newline at end of file diff --git a/heads/main_menu.h b/heads/main_menu.h new file mode 100644 index 0000000..1119823 --- /dev/null +++ b/heads/main_menu.h @@ -0,0 +1 @@ +void main_menu(); \ No newline at end of file diff --git a/heads/modify_module.h b/heads/modify_module.h new file mode 100644 index 0000000..8a53f90 --- /dev/null +++ b/heads/modify_module.h @@ -0,0 +1 @@ +void modify_module(); \ No newline at end of file diff --git a/heads/query_module.h b/heads/query_module.h new file mode 100644 index 0000000..4e1ab15 --- /dev/null +++ b/heads/query_module.h @@ -0,0 +1 @@ +void query_module(); \ No newline at end of file diff --git a/heads/registered_module.h b/heads/registered_module.h new file mode 100644 index 0000000..ab371ac --- /dev/null +++ b/heads/registered_module.h @@ -0,0 +1 @@ +void registered_module(); diff --git a/heads/secondary_menu.h b/heads/secondary_menu.h new file mode 100644 index 0000000..036a0f4 --- /dev/null +++ b/heads/secondary_menu.h @@ -0,0 +1 @@ +void secondary_menu(); \ No newline at end of file diff --git a/heads/statistic_module.h b/heads/statistic_module.h new file mode 100644 index 0000000..5a66a72 --- /dev/null +++ b/heads/statistic_module.h @@ -0,0 +1 @@ +void statistic_module(); \ No newline at end of file diff --git a/heads/stu_info.h b/heads/stu_info.h new file mode 100644 index 0000000..7a4043a --- /dev/null +++ b/heads/stu_info.h @@ -0,0 +1,8 @@ +struct stu{ + char stu_num[20]; + char name[20]; + char gender[10]; + int age; + float chinese,math,english; + struct stu *prev,*next; +}; diff --git a/heads/users.h b/heads/users.h new file mode 100644 index 0000000..6862df6 --- /dev/null +++ b/heads/users.h @@ -0,0 +1,5 @@ +struct user{ + char account[20]; + char password[20]; + struct user *next; +}; \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..b961386 --- /dev/null +++ b/main.c @@ -0,0 +1,61 @@ +/********************************************************************************************************************** + * _ooOoo_ * + * o8888888o * + * 88" . "88 * + * (| -_- |) * + * O\ = /O * + * ___/`---'\____ * + * . ' \\| |// `. * + * / \\||| : |||// \ * + * / _||||| -:- |||||- \ * + * / | | \\\ - /// | | \ * + * | \_| ''\---/'' | | * + * \ .-\__ `-` ___/-. / * + * ___`. .' /--.--\ `. . __ * + * ."" '< `.___\_<|>_/___.' >'"". * + * | | : `- \`.;`\ _ /`;.`/ - ` : | | * + * \ \ `-. \_ __\ /__ _/ .-` / / * + * ======`-.____`-.___\_____/___.-`____.-'====== * + * `=---=' * + * * + * ............................................. * + * 汣 BUG * + **********************************************************************************************************************/ + + +#include "heads/for_main.h" + +int main() { + //ʾ˵ + main_menu(); + + //ȡû룬жִз + char main_menu_input; + re_input_main_menu_choice: + printf("-> ѡ1/2/3"); + fflush(stdin); + scanf("%c",&main_menu_input); + switch (main_menu_input) { + //¼ + case '1':{ + login_module(); + break; + } + //ע + case '2':{ + registered_module(); + break; + } + //˳ + case '3':{ + exit(0); + } + //벻Ϸ + default:{ + printf("->벻Ϸ룡\n\n"); + fflush(stdin); + goto re_input_main_menu_choice; + } + } + return 0; +} diff --git a/stu_info/stu_info.txt b/stu_info/stu_info.txt new file mode 100644 index 0000000..861470f --- /dev/null +++ b/stu_info/stu_info.txt @@ -0,0 +1,10 @@ +001 ΰ÷ Ů 18 95.000000 88.000000 99.000000 +002 ־ Ů 17 98.000000 99.000000 96.000000 +003 ڹ 19 88.000000 90.000000 93.000000 +004 20 76.000000 88.000000 65.000000 +005 Ů 15 100.000000 95.000000 100.000000 +006 17 91.000000 78.000000 0.000000 +007 18 78.000000 85.000000 70.000000 +008 ޺ Ů 16 89.000000 60.000000 78.000000 +009 Ů 19 96.000000 88.000000 98.000000 +010 л־ 17 79.000000 78.000000 88.000000 diff --git a/users/users.txt b/users/users.txt new file mode 100644 index 0000000..ba04cfd --- /dev/null +++ b/users/users.txt @@ -0,0 +1 @@ +admin admin diff --git a/测试数据 b/测试数据 new file mode 100644 index 0000000..861470f --- /dev/null +++ b/测试数据 @@ -0,0 +1,10 @@ +001 ΰ÷ Ů 18 95.000000 88.000000 99.000000 +002 ־ Ů 17 98.000000 99.000000 96.000000 +003 ڹ 19 88.000000 90.000000 93.000000 +004 20 76.000000 88.000000 65.000000 +005 Ů 15 100.000000 95.000000 100.000000 +006 17 91.000000 78.000000 0.000000 +007 18 78.000000 85.000000 70.000000 +008 ޺ Ů 16 89.000000 60.000000 78.000000 +009 Ů 19 96.000000 88.000000 98.000000 +010 л־ 17 79.000000 78.000000 88.000000