功能:
- 录入学生信息
- 打印学生信息
- 统计学生人数
- 查找学生信息
- 修改学生信息
- 删除学生信息
- 按成绩排序
- 退出系统
#include<stdio.h>#include<stdlib.h>#include<conio.h>//学生信息typedefstruct_Student{intstuNum;charname[20];intscore;}Student;//结点信息typedefstruct_Node{Student student;struct_Node*next;}Node;voidwelcome();voidinputStudent(Node*head);voidprintStudent(Node*head);voidcountStudent(Node*head);voidfindStudent(Node*head);voidsaveStudent(Node*head);voidloadStudent(Node*head);voidmodifyStudent(Node*head);voiddeleteStudent(Node*head);voidsortStudent(Node*head);intmain(){//创建头结点Node*head=(Node*)malloc(sizeof(Node));head->next=NULL;loadStudent(head);while(1){welcome();charc=_getch();switch(c){case'1'://录入学生信息inputStudent(head);break;case'2'://打印学生信息printStudent(head);break;case'3'://统计学生人数countStudent(head);break;case'4'://查找学生信息findStudent(head);break;case'5'://修改学生信息modifyStudent(head);break;case'6'://删除学生信息deleteStudent(head);break;case'7'://按成绩排序sortStudent(head);break;case'8'://退出系统system("cls");printf("Bye Bye!\n");exit(0);break;default:printf("请重新输入\n");break;}}return0;}voidwelcome(){printf("*********************************\n");printf("*\t学生成绩管理系统\t*\n");printf("*********************************\n");printf("*\t请选择功能列表\t\t*\n");printf("*********************************\n");printf("*\t1.录入学生信息\t\t*\n");printf("*\t2.打印学生信息\t\t*\n");printf("*\t3.统计学生人数\t\t*\n");printf("*\t4.查找学生信息\t\t*\n");printf("*\t5.修改学生信息\t\t*\n");printf("*\t6.删除学生信息\t\t*\n");printf("*\t7.按成绩排序\t\t*\n");printf("*\t8.退出系统\t\t*\n");printf("*********************************\n");}voidinputStudent(Node*head){Node*fresh=(Node*)malloc(sizeof(Node));fresh->next=NULL;printf("请输入学生的学号,姓名,成绩 ");scanf("%d%s%d",&fresh->student.stuNum,fresh->student.name,&fresh->student.score);Node*move=head;while(move->next!=NULL){move=move->next;}//将学生插入到尾部move->next=fresh;saveStudent(head);//暂停程序system("pause");//清空控制台system("cls");}voidprintStudent(Node*head){Node*move=head->next;while(move!=NULL){printf("学号:%d 姓名:%s 成绩:%d\n",move->student.stuNum,move->student.name,move->student.score);move=move->next;}//暂停程序system("pause");//清空控制台system("cls");}voidcountStudent(Node*head){intcount=0;Node*move=head->next;while(move!=NULL){count++;move=move->next;}printf("学生的总人数为:%d\n",count);//暂停程序system("pause");//清空控制台system("cls");}voidfindStudent(Node*head){printf("请输入要查找的学生的学号: ");intstuNum;scanf("%d",&stuNum);Node*move=head->next;while(move!=NULL){if(stuNum==move->student.stuNum){printf("学号: %d 姓名:%s 成绩:%d\n",move->student.stuNum,move->student.name,move->student.score);//暂停程序system("pause");//清空控制台system("cls");return;}move=move->next;}printf("未找到学生信息\n");//暂停程序system("pause");//清空控制台system("cls");}voidsaveStudent(Node*head){FILE*file=fopen("./stu.info","w");Node*move=head->next;while(move!=NULL){if(fwrite(&move->student,sizeof(Student),1,file)!=1){printf("写入失败\n");return;}move=move->next;}fclose(file);}voidloadStudent(Node*head){FILE*file=fopen("./stu.info","r");if(!file){printf("没有学生文件,跳过读取\n");return;}Node*fresh=(Node*)malloc(sizeof(Node));fresh->next=NULL;Node*move=head;while(fread(&fresh->student,sizeof(Student),1,file)==1){move->next=fresh;move=fresh;fresh=(Node*)malloc(sizeof(Student));fresh->next=NULL;}free(fresh);fclose(file);printf("读取成功\n");}voidmodifyStudent(Node*head){printf("请输入要修改的学生的学号: ");intstuNum;scanf("%d",&stuNum);Node*move=head->next;while(move!=NULL){if(move->student.stuNum==stuNum){printf("请输入学生姓名,成绩\n");scanf("%s%d",move->student.name,&move->student.score);saveStudent(head);printf("修改成功\n");//暂停程序system("pause");//清空控制台system("cls");return;}move=move->next;}printf("未找到学生信息\n");//暂停程序system("pause");//清空控制台system("cls");}voiddeleteStudent(Node*head){printf("请输入要删除的学生学号 ");intstuNum=0;scanf("%d",&stuNum);Node*move=head;while(move->next!=NULL){if(move->next->student.stuNum==stuNum){Node*tmp=move->next;move->next=move->next->next;free(tmp);tmp=NULL;saveStudent(head);printf("删除成功\n");//暂停程序system("pause");//清空控制台system("cls");return;}move=move->next;}printf("未找到学生信息\n");//暂停程序system("pause");//清空控制台system("cls");}voidsortStudent(Node*head){Node*save=NULL;Node*move=NULL;for(Node*turn=head->next;turn->next!=NULL;turn=turn->next){for(move=head->next;move->next!=save;move=move->next){if(move->student.score>move->next->student.score){Student temp=move->student;move->student=move->next->student;move->next->student=temp;}}save=move;}printStudent(head);}