学生管理系统是我在学习完C语言后自己写的代码,很长,很多的地方运用的不好,还要多多改进
#include<windows.h> #include<stdio.h>#include<string.h>#define N sizeof(struct student)#define M sizeof(struct teacher)#define L sizeof(struct leader)struct student{int num;char mima[20];char name[20];char sex[20];float yuwen;float math;float english;float sum;struct student *next;};struct teacher{int num;char name[20]; char mima[20];char kind[20];struct teacher *next;};struct leader{int num;char name[20];char mima[20];struct leader *next;};void denglu();//登录界面 void denglu1();//主界面 void teacher_denglu(struct teacher *head_teacher,struct student *head_student);//教师登录 void student_denglu(struct student *head_student);//学生登录 void leader_denglu(struct leader *head_leader,struct teacher *head_teacher,struct student *head_student);//管理员登录 void student_menu(struct student *head_student,int num);//学生菜单 void teacher_menu(struct teacher *head_teacher,int num1,struct student *head_student);//教师菜单 void leader_menu(struct leader *head_leader,int num1,struct teacher *head_teacher,struct student *head_student);//管理员菜单 void leader_search(struct student *head_student,struct teacher *head_teacher);//管理员查询 void leader_Delete(struct student *head_student,struct teacher *head_teacher);//管理员删除 void leader_change(struct student *head_student,struct teacher *head_teacher);//管理员修改 void leader_bianli(struct student *head_student,struct teacher *head_teacher,struct leader *leader);//管理员遍历 struct student *student_zhuce(struct student *head_student);//学生注册 struct teacher *teacher_zhuce(struct teacher *head_teacher);//教师注册 struct leader *leader_zhuce(struct leader *head_leader);//管理员注册 void search_one(struct student *head_student,int num);//查询学生单个成绩 void search_sum(struct student *head_student,int num);//查询所有成绩 void search_No(struct student *head_student,int num);//查询排名 void change_studnet_mima(struct student *head_student,int num);//修改学生密码 void change_grate(struct student *head_student,int num);//修改学生成绩 void change_teacher_mima(struct teacher *head_teacher,int num);//修改教师密码 void search_teacher(struct teacher *head_teacher,int num);//查询教师信息 void search_student(struct student *head_student,int num);//查询学生信息 struct teacher *Delete_teacher(struct teacher *head_teacher,int num);//删除教师 struct student *Delete_student(struct student *head_student,int num);//删除学生 void change_teacher(struct teacher *head_teacher,int num);//修改教师信息 void change_leader_mima(struct leader *head_leader,int num);//修改管理员密码 void bianli_student(struct student *head_student);//遍历学生 void bianli_teacher(struct teacher *head_teacher);//遍历教师 void bianli_leader(struct leader *head_leader);//遍历管理员 void write(struct student *head_student,struct teacher *head_teacher,struct leader *head_leader);//写入文件 void sort(struct student *head_student);//排序 void sort_num(struct student *head_student);//按学号排序 void sort_sum(struct student *head_student);//按总分排序 void sort_yuwen(struct student *head_student);//按语文成绩排序 void sort_math(struct student *head_student);//按数学成绩排序 void sort_english(struct student *head_student);//按英语成绩排序 void write_student(struct student *head_student);//写入学生文件 void write_teacher(struct teacher *head_teacher);//写入教师文件 void write_leader(struct leader *head_leader);//写入管理员文件 int main(void){denglu();//登录界面 denglu1();return 0; }struct student *creat_student()//将学生数据从文件中读入学生链表 {struct student *head,*p1,*p2,*p3,t; FILE *p;head=NULL;p1=p2=(struct student*)malloc(N);p=fopen("学生.txt","r");if((p=fopen("学生.txt","r"))==NULL){printf("文件打开错误");return head;}while(fread(&t,N,1,p)!=0)//读取文件直到没有数据 {if(head==NULL){head=(struct student*)malloc(N);head->num=t.num;head->next=NULL;strcpy(head->mima,t.mima);strcpy(head->name,t.name);strcpy(head->sex,t.sex);head->yuwen=t.yuwen;head->math=t.math;head->english=t.english;head->sum=t.sum;head->next=NULL;}else{if(head->next==NULL){head->next=p1;}p1->num=t.num;p1->next=NULL;strcpy(p1->mima,t.mima);strcpy(p1->name,t.name);strcpy(p1->sex,t.sex);p1->yuwen=t.yuwen;p1->math=t.math;p1->english=t.english;p1->sum=t.sum;p1=(struct student*)malloc(N);p3=p2;p2->next=p1;p2=p1;}}if(head==NULL){head=(struct student*)malloc(N);head->next=NULL;return head;fclose(p);}if(head->next==NULL){return head;fclose(p);}else{free(p1);p3->next=NULL;fclose(p);return head;}}struct teacher *creat_teacher()//将教师数据从文件中读入教师链表 {struct teacher *head,*p1,*p2,*p3,t;FILE *p;head=NULL;p1=p2=(struct teacher*)malloc(M);p=fopen("教师.txt","r");if((p=fopen("教师.txt","r"))==NULL){printf("文件打开错误");return head; }while(fread(&t,M,1,p)!=0)//读取文件直到没有数据 {if(head==NULL){head=(struct teacher*)malloc(M);head->num=t.num;head->next=NULL;strcpy(head->name,t.name);strcpy(head->mima,t.mima);strcpy(head->kind,t.kind);}else{if(head->next==NULL){head->next=p1;}p1->num=t.num;p1->next=NULL;strcpy(p1->name,t.name);strcpy(p1->mima,t.mima);strcpy(p1->kind,t.kind);p1=(struct teacher*)malloc(M);p3=p2;p2->next=p1;p2=p1;} }if(head==NULL){head=(struct teacher*)malloc(M);head->next=NULL;return head;fclose(p);}if(head->next==NULL){return head;fclose(p);}else{free(p1);p3->next=NULL;fclose(p);return head;}}struct leader *creat_leader()//将教师数据从文件中读入教师链表 {struct leader *head,*p1,*p2,*p3,t;FILE *p;head=NULL;p1=p2=(struct leader*)malloc(L);p=fopen("管理员.txt","r");if((p=fopen("管理员.txt","r"))==NULL){printf("文件打开错误");return head; }while(fread(&t,L,1,p)!=0)//读取文件直到没有数据 {if(head==NULL){head=p1;}p1->num=t.num;p1->next=NULL;strcpy(p1->name,t.name);strcpy(p1->mima,t.mima);p1=(struct leader*)malloc(L);p3=p2;p2->next=p1;p2=p1;}if(head==NULL){return head;fclose(p);}else{free(p1);p3->next=NULL;fclose(p);return head;}}void denglu(){while(!kbhit()){printf("\n\n\n\t\t\t\t\t★★★★★★★★★★★★★★\n\n");printf("\t\t\t\t\t★★★★★★★★★★★★★★\n\n");printf("\t\t\t\t\t 欢迎进入教务管理系统!!!\n\n");printf("\t\t\t\t\t★★★★★★★★★★★★★★\n\n");printf("\t\t\t\t\t★★★★★★★★★★★★★★\n\n");Sleep(1000);system("cls");printf("\n\n\n\t\t\t\t\t☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n\n");printf("\t\t\t\t\t☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n\n");printf("\t\t\t\t\t 欢迎进入教务管理系统!!!\n\n");printf("\t\t\t\t\t☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n\n");printf("\t\t\t\t\t☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n\n");Sleep(1000);system("cls");}}void denglu1(){struct student *head_student=creat_student();//创建三个链表 struct teacher *head_teacher=creat_teacher();struct leader *head_leader=creat_leader(); char c;getchar();do{fflush(stdin);printf("\t----------------------------------------\n");//主界面 printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t| 1.学生登录 |\n");printf("\t| 2.教师登录 |\n");printf("\t| 3.管理员登录 |\n");printf("\t| 4.注册 |\n");printf("\t| 0.退出程序 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0'){case 1:student_denglu(head_student);// 学生登录break;case 2:teacher_denglu(head_teacher,head_student);//教师登录break;case 3:leader_denglu(head_leader,head_teacher,head_student);//管理员登录break;case 4:system("cls"); int choice;do{printf("\t----------------------------------------\n");//注册界面 printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t| 1.学生注册 |\n");printf("\t| 2.教师注册 |\n");printf("\t| 3.管理员注册 |\n");printf("\t| 0.返回主菜单 |\n");printf("\t----------------------------------------\n");printf("请选择:"); scanf("%d",&choice); switch(choice){case 1:head_student=student_zhuce(head_student);//学生注册break;case 2:head_teacher=teacher_zhuce(head_teacher);//教师注册break;case 3:head_leader=leader_zhuce(head_leader);//管理员注册break;case 0:break;default:printf("输入错误!请重试!!!\n");system("pause");system("cls");} }while(choice!=0); break;case 0:break;default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");} }while((c-'0')!=0);//退出 system("cls");printf("\t\t\t\t*************************************\n");printf("\t\t\t\t 谢谢使用!!!\n");printf("\t\t\t\t*************************************");write(head_student,head_teacher,head_leader);//将数据写入文件 }void teacher_denglu(struct teacher *head_teacher,struct student *head_student)//教师登录 {if(head_student->next==NULL||head_teacher->next==NULL)//判断教师链表和学生链表是否为空 {printf("学生或教师链表为空!!!\n");system("pause");system("cls");}else{char mima1[20];int num1;struct teacher *p;int s;int flag=0;srand((int)time(NULL));int start =(rand()%(99999-10000+1))+ 10000;//初始化验证码 printf("请输入教工号:");scanf("%d",&num1);printf("请输入密码:");scanf("%s",mima1);printf("请输入验证码:%d\n",start);printf("请输入验证码:");scanf("%d",&s);if(s==start)//判断验证码是否满足 {for(p=head_teacher->next;p;p=p->next){if(p->num==num1&&strcmp(p->mima,mima1)==0)//判断教工号和密码是否满足 {printf("\t----------------------------------------\n");printf("\t 登录成功!\n");printf("\t 欢迎进入教务管理系统!!!\n");printf("\t----------------------------------------\n");flag=1;system("pause");system("cls");teacher_menu(head_teacher,num1,head_student);//进入教师菜单 }}if(!flag){printf("\t\t\t\t查无此人!!!\n");//若所有教师都不满足,输出 查无此人system("pause");system("cls"); return ;}}else{printf("\t\t\t\t验证码错误!!!");//若验证码不满足,输出 验证码错误system("pause");system("cls"); }}}void student_denglu(struct student *head_student)//学生登录 {if(head_student->next==NULL)//判断学生链表是否 {printf("学生链表为空!!!\n");system("pause");system("cls");}else{char mima1[20];int num1;struct student *p;int s;int flag=0;srand((int)time(NULL));//初始化验证码 int start =(rand()%(99999-10000+1))+ 10000;printf("请输入学号:");scanf("%d",&num1);printf("请输入密码:");scanf("%s",mima1);printf("请输入验证码:%d\n",start);printf("请输入验证码:");scanf("%d",&s);if(s==start)//判断验证码是否满足 {for(p=head_student->next;p;p=p->next){if(p->num==num1&&strcmp(p->mima,mima1)==0)//判断学号与密码是否匹配 {printf("\t----------------------------------------\n");printf("\t 登录成功!\n");printf("\t 欢迎进入教务管理系统!!!\n");printf("\t----------------------------------------\n");flag=1;system("pause");system("cls");student_menu(head_student,num1);//进入学生菜单 }}if(!flag){printf("\t\t\t\t查无此人!!!\n");//判断是否有此人 system("pause");system("cls"); }}else{printf("\t\t\t\t验证码错误!!!");//若验证码不满足,输出 验证码错误system("pause");system("cls"); }}}void leader_denglu(struct leader *head_leader,struct teacher *head_teacher,struct student *head_student){if(head_student->next==NULL||head_teacher->next==NULL||head_leader==NULL){printf("学生,教师或管理员其中之一链表为空!!!\n");system("pause");system("cls");}else{char mima1[20];int num1;struct leader *p;int s;int flag=0;srand((int)time(NULL));//初始化验证码 int start =(rand()%(99999-10000+1))+ 10000;printf("请输入管理员号:");scanf("%d",&num1);printf("请输入密码:");scanf("%s",mima1);printf("请输入验证码:%d\n",start);printf("请输入验证码:");scanf("%d",&s);if(s==start)//判断验证码是否满足 {for(p=head_leader;p;p=p->next){if(p->num==num1&&strcmp(p->mima,mima1)==0)//判断管理员号与密码是否匹配 {printf("\t----------------------------------------\n");printf("\t 登录成功!\n");printf("\t 欢迎进入教务管理系统!!!\n");printf("\t----------------------------------------\n");flag=1;system("pause");system("cls");leader_menu(head_leader,num1,head_teacher,head_student);//进入管理员菜单 }}if(!flag){printf("\t\t\t\t查无此人!!!\n");//判断是否有此人 system("pause");system("cls"); return ;}}else{printf("\t\t\t\t验证码错误!!!");//若验证吗不满足,输出 验证码错误system("pause");system("cls"); }}}struct student *student_zhuce(struct student *head_student){int num;int flag=0;char mima[20];char sex[20];char name[20];struct student *p=head_student,*p1,*p2;printf("请输入学号:");scanf("%d",&num);for(p1=head_student;p1;p1=p1->next){if(p1->num==num)flag=1; } if(flag)//判断是否注册过 { printf("\t\t\t此学号已被注册过!!!\n"); return head_student; }printf("请输入密码:");scanf("%s",mima);printf("请输入姓名:");scanf("%s",name);printf("请输入性别:");scanf("%s",sex); if(head_student->next==NULL)//注册第一个人的信息 {p1=(struct student*)malloc(N);head_student->next=p1;p1->num=num;strcpy(p1->mima,mima);strcpy(p1->name,name);strcpy(p1->sex,sex); p1->yuwen=0;p1->math=0;p1->english=0;p1->sum=p1->math+p1->english+p1->yuwen;p1->next=NULL; printf("注册成功!!!");system("pause");system("cls");}else{while(p)//尾插法插入新节点 {p2=p;p=p->next;}p1=(struct student*)malloc(N);p1->num=num;strcpy(p1->mima,mima);strcpy(p1->name,name);strcpy(p1->sex,sex); p1->yuwen=0;p1->math=0;p1->english=0;p1->sum=p1->math+p1->english+p1->yuwen;p1->next=NULL;p2->next=p1;printf("注册成功!!!\n");system("pause");system("cls");}return head_student;}struct teacher *teacher_zhuce(struct teacher *head_teacher){int num;int flag=0; char name[20];char mima[20];char kind[20];struct teacher *p=head_teacher,*p1,*p2;printf("请输入教工号:");scanf("%d",&num);for(p1=head_teacher;p1;p1=p1->next){if(p1->num==num)flag=1; } if(flag)//判断是否注册过 { printf("\t\t\t此教工号已被注册过!!!\n"); return head_teacher; }printf("请输入密码:");scanf("%s",mima);printf("请输入姓名:");scanf("%s",name);printf("请输入所授科目:");scanf("%s",kind);if(head_teacher->next==NULL)//注册第一个人的信息 {p1=(struct teacher*)malloc(M);head_teacher->next=p1;p1->num=num;strcpy(p1->mima,mima);strcpy(p1->name,name);strcpy(p1->kind,kind);p1->next=NULL;printf("注册成功!!!\n");system("pause");system("cls");}else{while(p)//尾插法插入新节点 {p2=p;p=p->next;}p1=(struct teacher*)malloc(M);p1->num=num;strcpy(p1->mima,mima);strcpy(p1->name,name);strcpy(p1->kind,kind);p1->next=NULL;p2->next=p1;printf("注册成功!!!\n");system("pause");system("cls");}return head_teacher;}struct leader *leader_zhuce(struct leader *head_leader){int num;int flag=0;char mima[20];char name[20];struct leader *p=head_leader,*p1,*p2;printf("请输入管理员号:");scanf("%d",&num);for(p1=head_leader;p1;p1=p1->next){if(p1->num==num)flag=1; } if(flag)//判断是否注册过 { printf("\t\t\t此学号已被注册过!!!\n"); return head_leader; }printf("请输入密码:");scanf("%s",mima);printf("请输入姓名:");scanf("%s",name);if(head_leader==NULL)//注册第一个人的信息 {p1=(struct leader*)malloc(L);head_leader=p1;p1->num=num;strcpy(p1->mima,mima);strcpy(p1->name,name);p1->next=NULL;printf("注册成功!!!\n");system("pause");system("cls");}else{while(p)//尾插法插入新节点 {p2=p;p=p->next;}p1=(struct leader*)malloc(L);p1->num=num;strcpy(p1->mima,mima);strcpy(p1->name,name);p1->next=NULL;p2->next=p1;printf("注册成功!!!\n");system("pause");system("cls");}return head_leader;}void student_menu(struct student *head_student,int num){int choice;char c;do{fflush(stdin);system("cls");printf("\t----------------------------------------\n");//学生菜单界面 printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t| 1.单科成绩查询 |\n");printf("\t| 2.全部成绩查询 |\n");printf("\t| 3.排名查询 |\n");printf("\t| 4.修改密码 |\n");printf("\t| 0.返回主菜单 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch((c-'0')){case 1:search_one(head_student,num);//单科成绩查询break;case 2:search_sum(head_student,num);//全部成绩查询break;case 3:search_No(head_student,num);//排名查询break;case 4:change_studnet_mima(head_student,num);//修改密码break;case 0:break;//返回 default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");}}while((c-'0')!=0); }void teacher_menu(struct teacher *head_teacher,int num1,struct student *head_student){char c;int num;do{fflush(stdin);system("cls");printf("\t----------------------------------------\n");//教师菜单界面 printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t| 1.查询学生成绩 |\n");printf("\t| 2.修改学生成绩 |\n");printf("\t| 3.删除学生 |\n");printf("\t| 4.修改密码 |\n");printf("\t| 5.遍历学生 |\n");printf("\t| 6.学生排序 |\n");printf("\t| 0.返回主菜单 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0'){case 1:printf("请输入所查学生学号:");scanf("%d",&num); search_sum(head_student,num);//查询学生成绩break;case 2:printf("学生信息为:\n"); bianli_student(head_student);printf("请输入所改学生学号:");scanf("%d",&num); change_grate(head_student,num);//修改学生成绩break;case 3:printf("学生信息为:\n"); bianli_student(head_student);printf("请输入所删学生学号:");scanf("%d",&num); head_student=Delete_student(head_student,num);//删除学生break;case 4:change_teacher_mima(head_teacher,num1);//修改密码break;case 5:bianli_student(head_student);//遍历学生system("pause");system("cls");break;case 6:sort(head_student); //学生排序break;case 0:break;//返回 default:printf("输入错误!请重试!!!\n");system("pause");system("cls");}}while((c-'0')!=0); }void leader_menu(struct leader *head_leader,int num1,struct teacher *head_teacher,struct student *head_student){int c;int num;do{fflush(stdin);system("cls");printf("\t----------------------------------------\n");//管理员菜单界面 printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t| 1.查询师生信息 |\n");printf("\t| 2.删除师生信息 |\n");printf("\t| 3.修改师生信息 |\n");printf("\t| 4.修改密码 |\n");printf("\t| 5.遍历各信息 |\n");printf("\t| 6.学生排序 |\n");printf("\t| 0.返回主菜单 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0'){case 1:leader_search(head_student,head_teacher); //查询师生信息break;case 2:leader_Delete(head_student,head_teacher);//删除师生信息break;case 3:leader_change(head_student,head_teacher); //修改师生信息break;case 4:change_leader_mima(head_leader,num1);//修改密码break;case 5:leader_bianli(head_student,head_teacher,head_leader);//遍历各信息break;case 6:sort(head_student); // 学生排序break;case 0:break;default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");}}while((c-'0')!=0);}void leader_search(struct student *head_student,struct teacher *head_teacher){int num;char c;do{fflush(stdin);system("cls"); printf("\t----------------------------------------\n");printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t| 1.查询老师信息 |\n");printf("\t| 2.查询学生信息 |\n");printf("\t| 0.返回 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0'){case 1:printf("请输入学教工号:");//查询老师信息scanf("%d",&num); search_teacher(head_teacher,num);break;case 2:printf("请输入学生学号:");//查询学生信息scanf("%d",&num); search_student(head_student,num);break;case 0:break;default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");}}while((c-'0')!=0);}void leader_Delete(struct student *head_student,struct teacher *head_teacher){int num;char c;do{fflush(stdin);system("cls");printf("\t----------------------------------------\n");printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t| 1.删除老师信息 |\n");printf("\t| 2.删除学生信息 |\n");printf("\t| 0.返回 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0'){case 1:printf("请输入学教工号:");//删除老师信息scanf("%d",&num); head_teacher=Delete_teacher(head_teacher,num);break;case 2:printf("请输入所删学生学号:");//删除学生信息scanf("%d",&num); head_student=Delete_student(head_student,num);break;case 0:break;//返回 default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");} }while((c-'0')!=0);}void leader_change(struct student *head_student,struct teacher *head_teacher){int num;char c;do{fflush(stdin);system("cls");printf("\t----------------------------------------\n");printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t| 1.修改老师信息 |\n");printf("\t| 2.修改学生信息 |\n");printf("\t| 0.返回 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0'){case 1:printf("请输入所改教工号:");scanf("%d",&num); change_teacher(head_teacher,num);//修改老师信息 break;case 2:printf("请输入所改学生学号:");scanf("%d",&num); change_grate(head_student,num);//修改学生信息 break;case 0:break;//返回 default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");}}while((c-'0')!=0);}void leader_bianli(struct student *head_student,struct teacher *head_teacher,struct leader *head_leader){int num;char c;do{fflush(stdin);system("cls");printf("\t----------------------------------------\n");printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t| 1.遍历学生 |\n");printf("\t| 2.遍历教师 |\n");printf("\t| 3.遍历管理员 |\n");printf("\t| 0.返回 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0'){case 1:bianli_student(head_student);//遍历学生 system("pause");system("cls");break;case 2:bianli_teacher(head_teacher);//遍历老师 system("pause");system("cls");break;case 3:bianli_leader(head_leader);//遍历管理员 system("pause");system("cls");break;case 0:break;//返回 default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");} }while((c-'0')!=0);}void search_one(struct student *head_student,int num){char c;struct student *p=head_student->next;while(p->num!=num&&p){p=p->next;if(p==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");return;}}do{fflush(stdin);printf("\t----------------------------------------\n");printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t 请选择要查询的科目: |\n");printf("\t| 1.语文 |\n");printf("\t| 2.数学 |\n");printf("\t| 3.英语 |\n");printf("\t| 0.返回 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0'){case 1:printf("\t\t\t语文成绩为%.2f\n",p->yuwen);//查询语文成绩 system("pause");system("cls");break;case 2:printf("\t\t\t数学成绩为%.2f\n",p->math);//查询数学成绩 system("pause");system("cls");break;case 3:printf("\t\t\t英语成绩为%.2f\n",p->english);//查询英语成绩 system("pause");system("cls");break;case 0:break;//返回 default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");}}while((c-'0')!=0);} void search_sum(struct student *head_student,int num){struct student *p=head_student->next;while(p->num!=num){p=p->next;if(p==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");return;}}printf("\t\t\t语文\t数学\t英语\t总分\n");printf("\t\t\t%.2f\t%.2f\t%.2f\t%.2f\n",p->yuwen,p->math,p->english,p->sum);system("pause");system("cls");}void search_No(struct student *head_student,int num)//排名查询 {int no;char c;struct student *p1,*p2;p1=head_student->next;while(p1->num!=num){p1=p1->next;if(p1==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");}}do{fflush(stdin);p2=head_student->next; no=1;system("cls");printf("\t----------------------------------------\n");printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t 请选择要查询的科目: |\n");printf("\t| 1.查询语文排名 |\n");printf("\t| 2.查询数学排名 |\n");printf("\t| 3.查询英语排名 |\n");printf("\t| 4.查询总排名 |\n");printf("\t| 0.返回 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0'){case 1:while(p2){if(p2->yuwen>p1->yuwen)//记录所有比之较大的 no++;p2=p2->next;}printf("语文排名为%d\n",no);system("pause");system("cls");break;case 2:while(p2){if(p2->math>p1->math)//记录所有比之较大的 no++;p2=p2->next;}printf("数学排名为%d\n",no);system("pause");system("cls");break;case 3:while(p2){if(p2->english>p1->english)//记录所有比之较大的 no++;p2=p2->next;}printf("英语排名为%d\n",no);system("pause");system("cls");break;case 4:while(p2){if(p2->sum>p1->sum)//记录所有比之较大的 no++;p2=p2->next;}printf("总排名为%d\n",no);system("pause");system("cls");break;case 0:break;default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");}}while((c-'0')!=0);}void change_studnet_mima(struct student *head_student,int num){struct student *p=head_student->next;char mima1[20];char mima[20];while(p->num!=num){p=p->next;if(p==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");return;}}printf("请输入原密码:");scanf("%s",mima);printf("请输入新密码:"); scanf("%s",mima1);if(strcmp(p->mima,mima)==0)//判断是否与原密码相等 {printf("修改成功!!!\n");strcpy(p->mima,mima1);//覆盖原密码 system("pause");system("cls");}else{printf("与原密码不符,修改失败!!!\n");}}void change_grate(struct student *head_student,int num){struct student *p1=head_student->next;float grate;char c;while(p1->num!=num){p1=p1->next;if(p1==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");return;}} do{fflush(stdin);system("cls");printf("\t----------------------------------------\n");printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t 请选择要修改的科目: |\n");printf("\t| 1.修改语文成绩 |\n");printf("\t| 2.修改数学成绩 |\n");printf("\t| 3.修改英语成绩 |\n");printf("\t| 0.返回 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0'){case 1:printf("%s的原语文成绩为%.2f\n",p1->name,p1->yuwen);//修改语文成绩printf("请输入修改后的成绩:");scanf("%f",&grate);p1->yuwen=grate;p1->sum=(grate+p1->math+p1->english);printf("修改成功!!!\n");system("pause");system("cls");break;case 2:printf("%s的原数学成绩为%.2f\n",p1->name,p1->math);//修改数学成绩printf("请输入修改后的成绩:");scanf("%f",&grate);p1->math=grate;p1->sum=(p1->yuwen+grate+p1->english);printf("修改成功!!!\n");system("pause");system("cls");break;case 3:printf("%s的原英语成绩为%.2f\n",p1->name,p1->english);//修改英语成绩printf("请输入修改后的成绩:");scanf("%f",&grate);p1->english=grate;p1->sum=(p1->yuwen+p1->math+grate);printf("修改成功!!!\n");system("pause");system("cls");break;case 0://返回 break;default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");}}while((c-'0')!=0);}void change_teacher_mima(struct teacher *head_teacher,int num){struct teacher *p=head_teacher->next;char mima1[20];char mima[20];while(p->num!=num){p=p->next;if(p==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");return;}}printf("请输入原密码:");scanf("%s",mima);printf("请输入新密码:"); scanf("%s",mima1);if(strcmp(p->mima,mima)==0)//判断是否与原密码相等 {printf("修改成功!!!\n");strcpy(p->mima,mima1);//覆盖原密码 system("pause");system("cls");}else{printf("与原密码不符,修改失败!!!\n");system("pause");system("cls");}}void search_teacher(struct teacher *head_teacher,int num){struct teacher *p=head_teacher->next;while(p->num!=num){p=p->next;if(p==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");return;}}printf("\t\t\t姓名\t教工号\t所授科目\n");printf("\t\t\t%s\t%d\t%s\n",p->name,p->num,p->kind);system("pause");system("cls");}void search_student(struct student *head_student,int num){struct student *p=head_student->next;while(p->num!=num){p=p->next;if(p==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");return;}}printf("\t\t\t学号\t姓名\t性别\t语文\t数学\t英语\t总分\n");printf("\t\t\t%d\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",p->num,p->name,p->sex,p->yuwen,p->math,p->english,p->sum);system("pause");system("cls");}struct teacher *Delete_teacher(struct teacher *head_teacher,int num){struct teacher *ptemp;struct teacher *p;if(head_teacher->next==NULL){printf("删除失败,无信息!!!\n");//若链表中无信息,删除失败 system("pause");system("cls");return head_teacher;}ptemp=head_teacher;p=ptemp;while(ptemp->num!=num&&ptemp){p=ptemp;ptemp=ptemp->next;if(ptemp==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");return head_teacher;}}p->next=ptemp->next;//将节点的指针域链接,释放中间节点 free(ptemp);printf("删除成功!!!\n");system("pause");system("cls");return head_teacher;}struct student *Delete_student(struct student *head_student,int num){struct student *ptemp;struct student *p;if(head_student->next==NULL){printf("删除失败,无信息!!!\n");//若链表中无信息,删除失败 system("pause");system("cls");return head_student;}ptemp=head_student;p=ptemp;while(ptemp->num!=num){p=ptemp;ptemp=ptemp->next;if(ptemp==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");return head_student;}}p->next=ptemp->next;//将节点的指针域链接,释放中间节点 free(ptemp);printf("删除成功!!!\n");system("pause");system("cls");return head_student;}void change_teacher(struct teacher *head_teacher,int num){struct teacher *p=head_teacher->next;char kind[20];while(p->num!=num)//判断有没有这个人 {p=p->next;if(p==NULL){printf("查无此人!!!\n");system("pause");system("cls");return;}}printf("请输入所改科目:");scanf("%s",kind);printf("修改成功!!!\n");strcpy(p->kind,kind);system("pause");system("cls");}void change_leader_mima(struct leader *head_leader,int num){struct leader *p=head_leader;char mima1[20];char mima[20];while(p->num!=num){p=p->next;if(p==NULL){printf("查无此人!!!\n");//判断有没有此人 system("pause");system("cls");return;}}printf("请输入原密码:");scanf("%s",mima);printf("请输入新密码:"); scanf("%s",mima1);if(strcmp(p->mima,mima)==0)//判断是否是原密码 {printf("修改成功!!!\n");strcpy(p->mima,mima1);//覆盖原密码 system("pause");system("cls");}else{printf("与原密码不符,修改失败!!!\n");}}void bianli_student(struct student *head_student){struct student *p=head_student->next;printf("\t\t\t学号\t姓名\t性别\t语文\t数学\t 英语\t 总分\n");while(p)//遍历学生信息 {printf("\t\t\t%d%8s%8s%10.2f%10.2f%10.2f%10.2f\n",p->num,p->name,p->sex,p->yuwen,p->math,p->english,p->sum);p=p->next;}}void bianli_teacher(struct teacher *head_teacher){struct teacher *p=head_teacher->next;printf("\t\t\t姓名\t教工号\t所授科目\n");while(p)//遍历教师 {printf("\t\t\t%s%8d%8s\n",p->name,p->num,p->kind);p=p->next;}}void bianli_leader(struct leader *head_leader){struct leader *p=head_leader;printf("\t\t\t管理员号\t姓名\n");while(p)//遍历管理员 {printf("\t\t\t%d%16s\n",p->num,p->name);p=p->next;} }void sort_num(struct student *head_student){struct student *p,*q;struct student *min;int t;char t1[20];float t2;for(p=head_student->next;p->next!=NULL;p=p->next){min=p;//把当前的视为最小的 for(q=p->next;q;q=q->next){if(q->num>min->num)min=q;//找到一个最小的 }if(min!=p)//若两个不相等,交换数据 {t=p->num;p->num=min->num;min->num=t;strcpy(t1,p->name);strcpy(p->name,min->name);strcpy(min->name,t1);strcpy(t1,p->mima);strcpy(p->mima,min->mima);strcpy(min->mima,t1);strcpy(t1,p->sex);strcpy(p->sex,min->sex);strcpy(min->sex,t1);t2=p->english;p->english=min->english;min->english=t2;t2=p->math;p->math=min->math;min->math=t2;t2=p->yuwen;p->yuwen=min->yuwen;min->yuwen=t2;t2=p->sum;p->sum=min->sum;min->sum=t2;}}printf("已经完成排序\n"); }void sort_sum(struct student *head_student){struct student *p,*q;struct student *min;int t;char t1[20];float t2;for(p=head_student->next;p->next!=NULL;p=p->next){min=p;//把当前的视为最小的 for(q=p->next;q;q=q->next){if(q->sum>min->sum)min=q;//找到一个最小的 }if(min!=p)//若两个不相等,交换数据 {t=p->num;p->num=min->num;min->num=t;strcpy(t1,p->name);strcpy(p->name,min->name);strcpy(min->name,t1);strcpy(t1,p->mima);strcpy(p->mima,min->mima);strcpy(min->mima,t1);strcpy(t1,p->sex);strcpy(p->sex,min->sex);strcpy(min->sex,t1);t2=p->english;p->english=min->english;min->english=t2;t2=p->math;p->math=min->math;min->math=t2;t2=p->yuwen;p->yuwen=min->yuwen;min->yuwen=t2;t2=p->sum;p->sum=min->sum;min->sum=t2;}}printf("已经完成排序\n"); } void sort_yuwen(struct student *head_student){struct student *p,*q;struct student *min;int t;char t1[20];float t2;for(p=head_student->next;p->next!=NULL;p=p->next){min=p;//把当前的视为最小的 for(q=p->next;q;q=q->next){if(q->yuwen>min->yuwen)min=q;//找到一个最小的 }if(min!=p)//若两个不相等,交换数据 {t=p->num;p->num=min->num;min->num=t;strcpy(t1,p->name);strcpy(p->name,min->name);strcpy(min->name,t1);strcpy(t1,p->mima);strcpy(p->mima,min->mima);strcpy(min->mima,t1);strcpy(t1,p->sex);strcpy(p->sex,min->sex);strcpy(min->sex,t1);t2=p->english;p->english=min->english;min->english=t2;t2=p->math;p->math=min->math;min->math=t2;t2=p->yuwen;p->yuwen=min->yuwen;min->yuwen=t2;t2=p->sum;p->sum=min->sum;min->sum=t2;}}printf("已经完成排序\n"); }void sort_math(struct student *head_student){struct student *p,*q;struct student *min;int t;char t1[20];float t2;for(p=head_student->next;p->next!=NULL;p=p->next){min=p;//把当前的视为最小的 for(q=p->next;q;q=q->next){if(q->math>min->math)min=q;//找到一个最小的 }if(min!=p)//若两个不相等,交换数据 {t=p->num;p->num=min->num;min->num=t;strcpy(t1,p->name);strcpy(p->name,min->name);strcpy(min->name,t1);strcpy(t1,p->mima);strcpy(p->mima,min->mima);strcpy(min->mima,t1);strcpy(t1,p->sex);strcpy(p->sex,min->sex);strcpy(min->sex,t1);t2=p->english;p->english=min->english;min->english=t2;t2=p->math;p->math=min->math;min->math=t2;t2=p->yuwen;p->yuwen=min->yuwen;min->yuwen=t2;t2=p->sum;p->sum=min->sum;min->sum=t2;}}printf("已经完成排序\n"); }void sort_english(struct student *head_student){struct student *p,*q;struct student *min;int t;char t1[20];float t2;for(p=head_student->next;p->next!=NULL;p=p->next){min=p;//把当前的视为最小的 for(q=p->next;q;q=q->next){if(q->english>min->english)min=q;//找到一个最小的 }if(min!=p)//若两个不相等,交换数据 {t=p->num;p->num=min->num;min->num=t;strcpy(t1,p->name);strcpy(p->name,min->name);strcpy(min->name,t1);strcpy(t1,p->mima);strcpy(p->mima,min->mima);strcpy(min->mima,t1);strcpy(t1,p->sex);strcpy(p->sex,min->sex);strcpy(min->sex,t1);t2=p->english;p->english=min->english;min->english=t2;t2=p->math;p->math=min->math;min->math=t2;t2=p->yuwen;p->yuwen=min->yuwen;min->yuwen=t2;t2=p->sum;p->sum=min->sum;min->sum=t2;}}printf("已经完成排序\n"); }void sort(struct student *head_student){char c;do{ fflush(stdin);printf("\t----------------------------------------\n");printf("\t| 学生管理系统 |\n");printf("\t----------------------------------------\n");printf("\t 请选择排序方式: |\n");printf("\t| 1.语文排序 |\n");printf("\t| 2.数学排序 |\n");printf("\t| 3.英语排序 |\n");printf("\t| 4.总分排序 |\n");printf("\t| 5.学号排序 |\n");printf("\t| 0.返回 |\n");printf("\t----------------------------------------\n");printf("请选择:"); c=getchar();switch(c-'0') {case 1:sort_yuwen(head_student);//按语文排序 bianli_student(head_student);break;case 2:sort_math(head_student);//按数学排序 bianli_student(head_student);break;case 3:sort_english(head_student);//按英语排序 bianli_student(head_student);break;case 4:sort_sum(head_student);//按总分排序bianli_student(head_student);break;case 5:sort_num(head_student);//按学号排序bianli_student(head_student);break;case 0:break;default:printf("输入错误!请重试!!!\n");fflush(stdin);system("pause");system("cls");}}while((c-'0')!=0);}void write(struct student *head_student,struct teacher *head_teacher,struct leader *head_leader){write_student(head_student);write_teacher(head_teacher);write_leader(head_leader);}void write_student(struct student *head_student)//写入学生文件 {FILE *pt;struct student *p=head_student;pt=fopen("学生.txt","wt+");while(p) {fwrite(p,N,1,pt);p=p->next;}fclose(pt);}void write_teacher(struct teacher *head_teacher)//写入教师文件 {FILE *pt;struct teacher *p=head_teacher;pt=fopen("教师.txt","wt+");while(p) {fwrite(p,M,1,pt);p=p->next;}fclose(pt);}void write_leader(struct leader *head_leader)//写入管理员文件 {FILE *pt;struct leader *p=head_leader;pt=fopen("管理员.txt","wt+");while(p) {fwrite(p,L,1,pt);p=p->next;}fclose(pt);}