学生成绩管理系统v5.0

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includestdio.h#includestring.h#includestdlib.h#defineN50//最大人数#defineG150//字符串个数typedefstructstudent{longstudentID;charstudentName[10];intscore[6];//6门课程的成绩}STUDENT;voidInputscore(STUDENTstr[],intn,intm);/*n为学生人数,m为科目的数目,输入的功能*///voidPrintscore(STUDENTstr[],floataver[],intn,intm);//输出voidEverystuscore(STUDENTstr[],intn,intm);/*计算每个学生的总分和平均分*/voidEverycouscore(STUDENTstr[],intn,intm);//计算每门课程的总分和平均分voiddatasort1(STUDENTstr[],intn,intm);//成绩由高到低进行排序voiddatasort2(STUDENTstr[],intn,intm);//成绩由低到高进行排序voiddatasort3(STUDENTstr[],intn,intm);//按学号由小到大进行排序voiddatasort4(STUDENTstr[],intn,intm);//按姓名的字典顺序排出成绩表voidSearchNum(STUDENTstr[],intn,intm,longy);//按学号查询学生排名及考试成绩voidSearchName(STUDENTstr[],intn,intm,chary[]);//按姓名查询学生排名及考试成绩voidAnalysis(STUDENTstr[],intn,intm);//分析类别voidPrintscore(STUDENTstr[],intn,intm);//输出voidmenu();intmain(){charf[10];intchoice,n,x,pos,m;longz;STUDENTstr[N];floata=0,b=0,c=0,d=0,e=0;//表示学生的成绩等级高低do{printf(请输入学生人数:);scanf(%d,&n);}while(n0);printf(请输入共有几门课程(最多不超过6门):);scanf(%d,&m);while(m0||m6)//非法字符异常处理{while(getchar()!='\n');printf(你输入的课程多于6门或者输入非法字符,请重新输入:);scanf(%d,&m);}Inputscore(str,n,m);//读入分数名字和学号do{menu();//输出菜单scanf(%d,&choice);switch(choice){case1:Everycouscore(str,n,m);//求每个课程的平均分和总分break;case2:Everystuscore(str,n,m);//求学生的平均分和总分break;case3:datasort1(str,n,m);break;case4:datasort2(str,n,m);break;case5:datasort3(str,n,m);break;case6:datasort4(str,n,m);break;case7:printf(请输入你要查询的学生的学号:);scanf(%ld,&z);SearchNum(str,n,m,z);//按学号查询学生排名及考试成绩break;case8:printf(请输入你要查询学生的姓名:);scanf(%s,f);SearchName(str,n,m,f);break;case9:Analysis(str,n,m);//分析类别break;case10:Printscore(str,n,m);//输出break;case0:break;default:printf(你输入的数有误,请重新输入正确的数\n);//处理非法字符}getchar();getchar();}while(choice!=0);}voidmenu()//输出菜单{printf(*****************学生成绩系统*******************\n);printf(1.Caculatetotelandaveragescoreofeverycourse\n);printf(2.Caculatetotelandaveragescoreofeverystudent\n);printf(3.Sortindescendingorderbytotalscoreofeverystudent\n);printf(4.Sortinascendingorderbytotalscoreofeverystudent\n);printf(5.Sortinascendingorderbynumber\n);printf(6.Sortinascendingorderbyname\n);printf(7.Searchbynumber\n);printf(8.Searchbyname\n);printf(9.Statisticanalysisforeverycourse\n);printf(10.Listrecord\n);printf(0.Exit\n);printf(**********************************\n);printf(Pleaseenteryourchoice:);}voidInputscore(STUDENTstr[],intn,intm)//n为学生人数,m为科目的数目{inti,j;for(i=0;in;i++){printf(请输入学生学号,姓名和各科成绩:(以空格作为间隔));scanf(%ld%*c%s,&str[i].studentID,str[i].studentName);for(j=0;jm;j++){scanf(%d,&str[i].score[j]);}}}voidEverystuscore(STUDENTstr[],intn,intm)/*计算每个学生的总分和平均分*/{inti,j,sum[6];floataver[6];for(i=0;in;i++){sum[i]=0;for(j=0;jm;j++){sum[i]=sum[i]+str[i].score[j];}aver[i]=(float)sum[i]/m;}for(i=0;in;i++){printf(学号为%ld\t姓名为%s的总分为=%d,平均分=%2.1f\n,str[i].studentID,str[i].studentName,sum[i],aver[i]);}}voidEverycouscore(STUDENTstr[],intn,intm)//计算每门课程的总分和平均分{inti,j;intsum[6];floataver[6];for(j=0;jm;j++){sum[j]=0;for(i=0;in;i++){sum[j]=sum[j]+str[i].score[j];}aver[j]=(float)sum[j]/n;}for(i=0;im;i++){printf(科目%d的总分=%d,课程的平均分=%2.1f\n,i+1,sum[i],aver[i]);}}voiddatasort1(STUDENTstr[],intn,intm)//成绩由高到低进行排序{inti,j,sum[N];STUDENTtemp1;inttemp2;for(i=0;in;i++){sum[i]=0;for(j=0;jm;j++){sum[i]=sum[i]+str[i].score[j];}}for(i=0;in-1;i++){for(j=i+1;jn;j++){if(sum[j]sum[i]){temp1=str[j];temp2=sum[j];str[j]=str[i];sum[j]=sum[i];str[i]=temp1;sum[i]=temp2;}}}for(i=0;in;i++){printf(学号:%ld\t姓名:%s\t总分:%d\n,str[i].studentID,str[i].studentName,sum[i]);}}voiddatasort2(STUDENTstr[],intn,intm)//成绩由低到高进行排序{inti,j,sum[N];STUDENTtemp1;inttemp2;for(i=0;in;i++){sum[i]=0;for(j=0;jm;j++){sum[i]=sum[i]+str[i].score[j];}}for(i=0;in-1;i++){for(j=i+1;jn;j++){if(sum[j]sum[i]){temp1=str[j];temp2=sum[j];str[j]=str[i];sum[j]=sum[i];str[i]=temp1;sum[i]=temp2;}}}for(i=0;in;i++){printf(学号:%ld\t姓名:%s\t总分:%d\n,str[i].studentID,str[i].studentName,sum[i]);}}voiddatasort3(STUDENTstr[],intn,intm)//按学号由小到大进行排序{inti,j;STUDENTtemp1;inttemp2;for(i=0;in-1;i++){for(j=i+1;jn;j++){if(str[j].studentIDstr[i].studentID){temp1=str[j];str[j]=str[i];str[i]=temp1;}}}for(i=0;in;i++){printf(学号:%ld\t姓名:%s\t\n,str[i].studentID,str[i].studentName);for(j=0;jm;j++){printf(科目%d的分数=%d\n,j+1,str[i].score[j]);}}}voiddatasort4(STUDENTstr[],intn,intm)//按姓名的字典顺序排出成绩表{inti,j;STUDENTtemp1;inttemp2;for(i=0;in-1;i++){for(j=i+1;jn;j++){if(strcmp(str[j].studentName,str[i].studentName)0){temp1=str[j];str[j]=str[i];str[i]=temp1;}}}for(i=0;in;i++){printf(学号:%ld\t姓名:%s\t\n,str[i].studentID,str[i].studentName);for(j=0;jm;j++){printf(科目%d的分数=%d\n,j+1,str[i].score[j]);}}}voidSearchNum(STUDENTstr[],intn,intm,longy)//按学号查询学生排名及考试成绩{inti,j,rank=1,find=0,sum[N],pos;for(i=0;in;i++){sum[i]=0;for(j=0;jm;j++){sum[i]=sum[i]+str[i].score[j];}}for(i=0;in;i++){if(str[i].studentID==y){find=1;pos=i;break;}}if(find==0){printf(没有找到!你输入的学号不正确!\n);}else{for(i=0;in;i++){if(sum[i]sum[pos]){rank++;}}printf(学号:%ld\t姓名:%s\t\n,str[pos].studentID,str[pos].studentName);for(j=0;jm;j++){printf(科目%d的分数=%d\n,j+1

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功