c语言输入输出排序打印学生成绩单.docx
- 文档编号:10696829
- 上传时间:2023-02-22
- 格式:DOCX
- 页数:16
- 大小:17.09KB
c语言输入输出排序打印学生成绩单.docx
《c语言输入输出排序打印学生成绩单.docx》由会员分享,可在线阅读,更多相关《c语言输入输出排序打印学生成绩单.docx(16页珍藏版)》请在冰豆网上搜索。
c语言输入输出排序打印学生成绩单
#includc
#include
#include
〃确定最大值
#dcfineN30
typedefstnictstudent
{
longid;
charnamc[10];
floatscore|4];
}STUDENT;
STUDENTstu[N];
voidaddc(structstudent*pt,intn);
voidadds(stnictstudent*pt,intn);
voidpxs(stnictstudent*pt,int(*comp)(floata,floatb),intn);
intds(floata,floatb);
intas(floata,floatb);
voidpxi(stmctstudent*pt,intn);
voidpxn(structstudent*pt,intn);
voidseai(structstudent*pt,intn);
voidsean(stnictstudent*pt,intn);
voidana(stnictstudent*pt,intn);
voidwri(STUDENT*pt.intn);
voidrea(STUDENT*pt,intn);
//主函数
intmain()
{
intn,con=14,ij;
printf(HInputstudentnumber(n<30):
H);
scanfC^d^&n);
if(n>NIIn<1)
return0;
else
{
//主程序
while(con!
=0)
〃输出printf(H\nManagementforStudents1scores\nH);printf(nl.Appendrecord\nu);
printf(H2.Calculatetotalandaveragescoreofeverycoursc'n”);printf(M3.Calculatetotalandaveragescoreofeverystudcnt\nM);
printf(H4.Sortindescendingorderbytotalscoreofeverystudent\nn);
printf(M5.Sortinascendingorderbytotalscoreofeverystudent\nH);printf(H6.Sortinascendingorderbynumber\nM);
printf(M7.Sortindictionaryorderbyname\nn);
printf(n8.Searchbynumber\nH);
printf(H9.Searchbyname\nH);
printfC'lO.Statisticanalysis'll);
printf(H11.Listrecords’);
printf(H12.Writetoafile\nH);
printf(H13.Readfromafile\nH);
printf(HO.Exit\nH);
//录入学生的人数:
printf("PleaseInputyourchoice:
'*);
scanf(”%cT;&con);
//录入每个学生的学号、姓名和各科成绩:
if(con=1)
{
printf(HInputstudenfsID.nameandscore:
\nM);
for(i=0;i { scanf(M%ldH,&stu[i].id); getcharO; fgets(stu[i].name,sizeof(stu[i].name),stdin);///有问题! ! ! scanf(M%f%f%f'\&stu[i].score[0],&stu[i].score[l],&stu[i].score[2]); } } 〃计算每门课程的总分和平均分: elseif(con==2) { addc(stu.n); } 〃计算每个学生各门课程的总分和平均分: elseif(con==3) { adds(stu,n); } //按总成绩由髙到低排出名次表: elseif(con==4) { printf(HSortindescendingorderbytotalscoreofeverystudentAn'1); printf(MNO\tName\tMT\tEN\tPH\tSUM\tAVER\nM); pxs(stu,ds,n); } //按总成绩由低到髙排出名次表: elseif(con==5) { printf(HSortinascendingorderbytotalscoreofeverystudent: \nH); printf(MNO\tName\tMBtEN\tPH\tSUM\tAVER\nH); pxs(stu,as,n); } //按学号由小到大排出成绩表: elseif(con==6) { printf(HSortinascendingorderbynuinbcr: \nM); printf(HNO\tName\tMBtEN\tPH\tSUM\tAVER\nM); pxi(stu.n); //按姓名的字典顺序排出成绩表: elseif(con==7) { printf(HSortindictionaryorderbynameAn'*); printf(MNO\tNamc\tMntEN\tPH\tSUM\tAVER\nH); pxn(stu,n); } //按学号查询学生排名、学号、姓需及其考试成绩: elseif(con==8) { seai(stu,n); } //按姓名查询学生排名、学号、姓名及其考试成绩: elseif(con==9) ( sean(stu,n); } //按100,(90~100)(80~89)(70~79)(60~69)(0~59)统计各科每个类别的人数以及 所占的百分比: elseif(con==10) ( ana(stu.n); } 〃输出信息 elseif(con==11) ( printf(MNO\tName\tMT\tEN\tPH\tSUM\tAVER\nH); for(i=0;i { printf(M%ld\f\stu[i].id); for(j=0;stu(i].name[j]! =r\n,;j++) putchar(stu[i].name[j]); printf(,,\t%.0At%.0f\t%.0f\t%.0f\t%.0An,\stu[i].score[0],stu[i].score[l],stu[i].score[2],stu[i].score[3],(stu[i].score[3]⑶); } } 〃写入文件 elseif(con==12) { wri(stiLn); } 〃读取文件 elseif(con==13) { rea(stu,n); } elseif(con==0) { printfC'Endofprogram! \nH); } else { printf(MInputerror! \nM); } ) } return0; ) voidaddc(structstudent*pt,intn) { inti,j; floatsum; for(j=0;j<3;j++) ( sum=0; for(i=0;i<3;i++) { sum+=stu[i].score[j]; ) printf(Mcourse%d: sum=%.0f.aver=%.0f\nH,(j+1),sum,(sum/n)); } ) voidadds(stnictstudent*pt,intn) { inti; for(i=0;i ( stu[i].score[3]=stu[i].score[0]+stu[i].score[l]+stu[i].score[2]; printf(Mstudent%d: sum=%.0taver=%.0f\n",(i+1),stu[i].score[3],(stu[i].score[3]/3)); } ) voidpxs(structstudent*pt,int(*comp)(floata,floatb),intn) intij; structstudenttemp: for(i=0;i { for(j=0;j<(n-i-l);j++) { if((*comp)(stu[j].score[3],stu(j+1].score[3])) temp=stu[j];stu[j]=stuQ+l]; stu[j+l]=temp; } ) }for(i=0;i { printf(,,%ld\t,\stu[i].id); for(j=0;stu[i].name[j]! =An';j++) putchar(stu[i].name(j]); } printf(',\t%.OAt%.Of\t%.OAt%.OAt%.Of\n,\stu[i].score[0],stu[i].score[l],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); } } intds(floata,floatb) { returna } intas(floata.floatb) { returna>b: ) voidpxi(stnictstudent*pt? intn) { inti,j; structstudenttemp; for(i=0;i { for(j=0;j<(n-i-l);j++) { if(stu[j].id>stu[j+l].id) { temp=stu[j]; stu[j]=stu[j+l];stu[j+lj=temp; } } } for(i=0;i ( printf(N%ld\t,\stu[i].id); for(j=0;stu[i].name[j]! =An: j++) { putchar(stu[i].name[j]); ) printf(H\t%.0f\t%.0f\t%.0f\t%.0At%.0f\n,\stu[i].score[0],stu[i].score[l],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); voidpxn(structstudent*pt,intn) { inti,j; structstudenttemp; for(i=0;i ( for(j=0;j<(n-i-l);j++) { if(strcmp(stu[j].name.stuIj+l].name)>O) { temp=stu[j]; stu[j]=stu[j+l];stu[j+l]=temp; } } } for(i=0;i ( printf(N%ld\t,\stu[i].id); for(j=0;stu[i].name[j]! =An: j++) { putchar(stu[i].name[j]); ) printf(H\t%.0f\t%.0f\t%.0f\t%.0At%.0f\n,\stu[i].score[0],stu[i].score[l],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); } } voidseai(structstudent*pt,intn) { intijcon=0; longid: structstudenttemp; printf(nInputthenumberyouwanttosearch: M); scanf(N%ld,\&id);for(i=0;i for(j=0;j<(n-i-l);j++) { if(stu[j].score[3J { temp=stu[j]; stu[j]=stu[j+l]: stu[j+l]=temp; } ) } for(i=0;i { if(stu[i].id=id) { printf(,,%d\t%ld\t,',(i+1),stu(ij.id); for(j=0;stu[i].name[j]! =,\n';j++) { putchar(stu[i].name[j]); stu[i].score[l], } printf(H\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\n\stu[i].score[0],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); con=l; break; ) } if(con==0) printf(HNotfound! \n*'); ) voidsean(stnictstudent*pt,intn) { intijcon=0; charnameflOJ; structstudenttemp; printf(MInputthenameyouwanttosearch: 11); getchar(); fgets(name,sizeof(name),stdin);///有问题! ! ! ! for(i=0;i { for(j=0;j<(n-i-l);j++) {if(stu[j].score[3J { temp=stufj]; stu[j]=stu[j+l]: stu[j+l]=temp; } } } for(i=0;i { if(strcmp(stu[i].name,name)=O) {printf(H%d\t%Id\f\(i+1),stu[i].id); for(j=0;stu[i].name[j]! =,\n';j++) { putchar(stu[i].name[j]); stu[i].score[l], }printf(M\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\n,\stu[i].score[0],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); con=l; break; ) } if(con==0) printf(MNotfound! \nH); } voidana(stnictstudent*pt,intn) { inti,j,nl,n2,n3,n4,n5,n6; for(j=0;j<3;j++) { n1=0;n2=0;n3=0;n4=0;n5=0;n6=0: for(i=0;i { if(stu[i].score[j]<60) nl+=l; elseif(stu[i].score[j]<70)n2+=l; elseif(stu[i].score[j]<80) n3+=l; elseif(stu[i].score[j]<90) n4+=l; elseif(stu[i].score|j]<=100) { n5+=l; if(stu[i].score[j]==100)i】6+=1; } ) printf(HForcourse%d: \n'\(j+1));printf(,,<60\t%d\t%.2f%%\n,\nl,100*(float)nl/n); printf(,,%d-%d\t%d\t%.2f%%\nM,60.69,n2,100*(float)n2/n); printf(H%d-%d\t%d\t%.2f%%\n,\70.79,n3,100*(float)n3/n); printf(N%d-%d\t%d\t%.2f%%\n,\80,89,n4,100*(float)n4/n); printf(H%d-%d\t%d\t%.2f%%\nM.90,100,n5,100*(float)n5/n); printf(H%d\t%d\t%.2f%%\n,\100,n6,100*(float)n6/n); } } voidwri(STUDENT*pt,intn) { FILE*fp; inti,j; structstudenttemp; for(i=0;i if(stu[j].id>stu[j+l].id) { temp=stu[j]; stu|j]=stu[j+l];stu[j+lj=temp; } ) } if((fp=fopen(,,student.txt,\MwH))==NULL) exit(O); //fprintf(fp.,,NO\tNanie\tMrntEN\tPH\tSUM\tAVER\nH); for(i=0;i { fprintf(fp,M%ld\tH,stu[i].id); for(j=0: stu[i].namc[j]! =*\n;j++) { fprintf(fp,H%c*\stu[i].name[j]); stu[i].score[l], ) fprintf(fp;,\t%.0f\t%.0f\t%.0At%.0f\t%.0f\n\stu[i].score[0],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); } fclose(fp); printf(Hsavesuccessfully! 0); ) voidrea(STUDENT*pt,intn) { FILE*fp; intm; longa; floatc・d.c,f.g; charb[10]; //charhead[50]; if((fp=fopen(Mstudent.txtH,T'))==NULL) exit(O); //fgets(head,50,fp); //puts(head); printf(HNO\tNanie\tMT\tEN\tPH\tSUM\tAVER\n,r); for(m=0;m //printfC'scjdbfdsdj");fscanf(fp「%ldl&a);printf(,,%ld\t,\a);fscanf(fp「%10s",b);printf(”%s\U,b);fscanf(fp,n%f\&c);printf(H%.0f\t,\c);fscanf(fp,N%f\&d);printf(,,%.0f\t,\d);fscanf(fp,n%f\&c);printfC%.0AtM,e);fscanf(fp,N%f\&f);printf(H%.0f\t,\f);fscanf(fp,M%f\&g);primf(・%0f\n”,g); //primf(: jdhcrgjdkfnjhcrdgfdhb'n”);} fclose(fp);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 输入输出 排序 打印 学生 成绩单
![提示](https://static.bdocx.com/images/bang_tan.gif)