编写一个菜单驱动的学生成绩管理程序。实现如下管理功能:•能输入并显示n个学生的m门考试科目的成绩、总分和平均分。•按总分进行排序。•按学号进行排序。•任意输入一个学号,能显示该学生的姓名、各门功课的成绩。•将输入的学生成绩数据保存到文件中。•从文件中读出学生成绩数据。关键词:显示数据;排序;查询功能;写入文件;读出数据;输出菜单形式如下:ManagementforStudents'scores1.Appendrecord2.Listrecord3.Deleterecord4.Modifyrecord5.Searchrecord6.SortScoreindescendingorderbysum7.SortScoreinascendingorderbysum8.SortScoreindescendingorderbynum9.SortScoreinascendingorderbynumW.WritetoaFileR.ReadfromaFile0.ExitPleaseInputyourchoice:1.2其它规定1.2.1输入的形式和输出值的范围输入学生编号(以%d形式输入),学生姓名(以%s形式输入,十位),学生成绩(%d)。1.2.2输入的形式输出时以学号(%d),姓名(%s),成绩(%d),总分(%d),平均分(%f)形式1.2.3程序所能够达到的功能2输入成绩计算总分和平均分;罗列成绩;删除修改记录;按总分升序和讲叙排列并输出成绩记录;按学号升序和讲叙排列并输出成绩记录;程序源代码:#defineSTU_NUM2/*最多的学生人数*/#defineCOURSE_NUM2/*最多的考试科目*/#defineTUB50/*学生数*/#includestdio.hFILE*fp;structstudent{intnumber;/*每个学生的学号*/charname[10];/*每个学生的姓名*/intscore[COURSE_NUM];/*每个学生M门功课的成绩*/intsum;/*每个学生的总成绩*/floataverage;/*每个学生的平均成绩*/}s[TUB]={0,'ti',0,0,0};typedefstructstudentSTU;charmenu(void)/*菜单函数*/{charch;printf(\nManagementforStudents'scores\n);printf(1Appendrecord\n);printf(2Listrecord\n);3printf(3Deleterecord\n);printf(4Modifyrecord\n);printf(5Searchrecord\n);printf(6SortScoreindescendingorderbysum\n);printf(7SortScoreinascendingorderbysum\n);printf(8SortScoreindescendingorderbynum\n);printf(9SortScoreinascendingorderbynum\n);printf(wWritetoaFile\n);printf(rReadfromaFile\n);printf(0Exit\n);printf(PleaseInputyourchoice:);scanf(%c,&ch);return(ch);}voidappend()/*添加记录,计算出总分和平均值*/{inti,j;printf(请输入数据:\n);//输入数据for(i=0;iSTU_NUM;i++){printf(学号:);scanf(%d,&s[i].number);printf(姓名:);scanf(%s,s[i].name);for(j=0;jCOURSE_NUM;j++){printf(成绩:);scanf(%d,&s[i].score[j]);}4}for(i=0;iSTU_NUM;i++)//求总分{for(j=0;jCOURSE_NUM;j++)s[i].sum=s[i].sum+s[i].score[j];printf(总分%d,s[i].sum);}for(i=0;iSTU_NUM;i++)//求平均数{s[i].average=(s[i].sum)/(COURSE_NUM);printf(平均分%.2f,s[i].average);}}voidlist()/*显示记录_在屏幕中打印所有学生成绩*/{inti,j;for(i=0;iSTU_NUM;i++){printf(学号%3d,姓名%s,,s[i].number,s[i].name);for(j=0;jCOURSE_NUM;j++)printf(分数%4d,,s[i].score[j]);printf(总分%4d,平均分%4.2f\n,s[i].sum,s[i].average);}}voiddelete()/*删除记录_用后面的数据替换前一个*/{5inta,i,b=0;printf(Pleaseinputstudent'snumberyouwanttodelete:\n);scanf(%d,&a);for(i=0;iSTU_NUM;i++){if(s[i].number==a){b=1;s[i]=s[i+1];}}if(b==0)printf(Thenumberisnotfound!\npleasecheckitagain!\n);}voidmodify()/*修改记录_对要修改的数据重新复值*/{intb=0,a,i,j;printf(Pleaseinputstudent'snumberyouwanttomodify:\n);scanf(%d,&a);for(i=0;iSTU_NUM;i++){if(s[i].number==a){b=1;scanf(%d%s,&s[i].number,&s[i].name);for(j=0;jCOURSE_NUM;j++)scanf(%d,&s[i].score[j]);}}if(b==0)printf(Thenumberisnotfound!\npleasecheckitagain!\n);}6voidsearch()/*查询记录_输入学生学号,输出对应的成绩数据*/{inta,i,j;printf(Pleaseinputstudent'snumberyouwanttomodify:\n);scanf(%d,&a);for(i=0;iSTU_NUM;i++){if(s[i].number==a)printf(%d,%s,,s[i].number,s[i].name);for(j=0;jCOURSE_NUM;j++)printf(%d,,s[i].score[j]);printf(%d,%.2f\n,s[i].sum,s[i].average);}}voiddescending_sum()/*按总分排序_降序排列,打印出学生姓名和成绩*/{inti,j;STUt;for(i=0;iSTU_NUM;i++){for(j=i+1;jSTU_NUM;j++)if(s[i].sums[j].sum){t=s[j];s[j]=s[i];s[i]=t;}}for(i=0;iSTU_NUM;i++){printf(%d,%s,,s[i].number,s[i].name);for(j=0;jCOURSE_NUM;j++)7printf(%d,,s[i].score[j]);printf(%d,%.2f\n,s[i].sum,s[i].average);}}voidascending_sum()/*按总分排序_升序排列,打印出学生姓名和成绩*/{inti,j;STUt;for(i=0;iSTU_NUM;i++){for(j=i+1;jSTU_NUM;j++)if(s[i].sums[j].sum){t=s[j];s[j]=s[i];s[i]=t;}}for(i=0;iSTU_NUM;i++){printf(%d,%s,,s[i].number,s[i].name);for(j=0;jCOURSE_NUM;j++)printf(%d,,s[i].score[j]);printf(%d,%.2f\n,s[i].sum,s[i].average);}}voiddescending_number()/*按学号排序_按学号降序排列,打印出学生姓名和成绩*/{inti,j;STUt;8for(i=0;iSTU_NUM;i++){for(j=i+1;jSTU_NUM;j++)if(s[i].numbers[j].number){t=s[j];s[j]=s[i];s[i]=t;}}for(i=0;iSTU_NUM;i++){printf(%d,%s,,s[i].number,s[i].name);for(j=0;jCOURSE_NUM;j++)printf(%d,,s[i].score[j]);printf(%d,%.2f\n,s[i].sum,s[i].average);}}voidascending_number()/*按学号排序_按学号降序排列,打印出学生姓名和成绩*/{inti,j;STUt;for(i=0;iSTU_NUM;i++){for(j=i+1;jSTU_NUM;j++)if(s[i].numbers[j].number){t=s[j];s[j]=s[i];s[i]=t;}}for(i=0;iSTU_NUM;i++){printf(%d,%s,,s[i].number,s[i].name);for(j=0;jCOURSE_NUM;j++)printf(%d,,s[i].score[j]);9printf(%d,%.2f\n,s[i].sum,s[i].average);}}voidwrite()/*写入文件*/{FILE*fp;inti;fp=fopen(student_data,wb);for(i=0;iSTU_NUM;i++){fwrite(&s[i],sizeof(structstudent),1,fp);printf(writetofilesuccessfully.\n);}fclose(fp);}voidread()/*从文件中读出成绩*/{FILE*fp;inti,j;fp=fopen(student_data,rb);if(fp==NULL){printf(cannotopenthisfile!\n);exit(0);}for(i=0;iSTU_NUM;i++)fread(&s[i],sizeof(structstudent),1,fp);for(i=0;iSTU_NUM;i++)10{printf(%d,%s,,s[i].number,s[i].name);for(j=0;jCOURSE_NUM;j++)printf(%d,,s[i].score[j]);printf(%d,%.2f\n,s[i].sum,s[i].average);}fclose(fp);}voidmain()/*主程序_选择要执行的命令*/{FILE*fp;charch;while(1){ch=menu();switch(ch){case'1':append();break;case'2':list();break;case'3':delete();list();break;case'4':modify();list();break;case'5':search();break;case'6':descending_sum();break;case'7':ascending_sum();break;case'8':descending_number();break;case'9':ascending_number();break;case'w':write();break;case'r':read(