语言输入输出排序打印学生成绩单.docx
- 文档编号:7232590
- 上传时间:2023-01-22
- 格式:DOCX
- 页数:15
- 大小:16.96KB
语言输入输出排序打印学生成绩单.docx
《语言输入输出排序打印学生成绩单.docx》由会员分享,可在线阅读,更多相关《语言输入输出排序打印学生成绩单.docx(15页珍藏版)》请在冰豆网上搜索。
语言输入输出排序打印学生成绩单
#include
#include
#include
//确定最大值
#defineN30
typedefstructstudent
{
longid;
charname[10];
floatscore[4];
}STUDENT;
STUDENTstu[N];
voidaddc(structstudent*pt,intn);
voidadds(structstudent*pt,intn);
voidpxs(structstudent*pt,int(*comp)(floata,floatb),intn);
intds(floata,floatb);
intas(floata,floatb);
voidpxi(structstudent*pt,intn);
voidpxn(structstudent*pt,intn);
voidseai(structstudent*pt,intn);
voidsean(structstudent*pt,intn);
voidana(structstudent*pt,intn);
voidwri(STUDENT*pt,intn);
voidrea(STUDENT*pt,intn);
//主函数
intmain()
{
intn,con=14,i,j;
printf("Inputstudentnumber(n<30):
");
scanf("%d",&n);
if(n>N||n<1)
return0;
else
{
//主程序
while(con!
=0)
{
//输出
printf("\nManagementforStudents'scores\n");
printf("1.Appendrecord\n");
printf("2.Calculatetotalandaveragescoreofeverycourse\n");
printf("3.Calculatetotalandaveragescoreofeverystudent\n");
printf("4.Sortindescendingorderbytotalscoreofeverystudent\n");
printf("5.Sortinascendingorderbytotalscoreofeverystudent\n");
printf("6.Sortinascendingorderbynumber\n");
printf("7.Sortindictionaryorderbyname\n");
printf("8.Searchbynumber\n");
printf("9.Searchbyname\n");
printf("10.Statisticanalysis\n");
printf("11.Listrecord\n");
printf("12.Writetoafile\n");
printf("13.Readfromafile\n");
printf("0.Exit\n");
//录入学生的人数:
printf("PleaseInputyourchoice:
");
scanf("%d",&con);
//录入每个学生的学号、姓名和各科成绩:
if(con==1)
{
printf("Inputstudent'sID,nameandscore:
\n");
for(i=0;i { scanf("%ld",&stu[i].id); getchar(); fgets(stu[i].name,sizeof(stu[i].name),stdin);///有问题! ! ! scanf("%f%f%f",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]); } } //计算每门课程的总分和平均分: elseif(con==2) { addc(stu,n); } //计算每个学生各门课程的总分和平均分: elseif(con==3) { adds(stu,n); } //按总成绩由高到低排出名次表: elseif(con==4) { printf("Sortindescendingorderbytotalscoreofeverystudent: \n"); printf("NO\tName\tMT\tEN\tPH\tSUM\tAVER\n"); pxs(stu,ds,n); } //按总成绩由低到高排出名次表: elseif(con==5) { printf("Sortinascendingorderbytotalscoreofeverystudent: \n"); printf("NO\tName\tMT\tEN\tPH\tSUM\tAVER\n"); pxs(stu,as,n); } //按学号由小到大排出成绩表: elseif(con==6) { printf("Sortinascendingorderbynumber: \n"); printf("NO\tName\tMT\tEN\tPH\tSUM\tAVER\n"); pxi(stu,n); } //按姓名的字典顺序排出成绩表: elseif(con==7) { printf("Sortindictionaryorderbyname: \n"); printf("NO\tName\tMT\tEN\tPH\tSUM\tAVER\n"); 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("NO\tName\tMT\tEN\tPH\tSUM\tAVER\n"); for(i=0;i { printf("%ld\t",stu[i].id); for(j=0;stu[i].name[j]! ='\n';j++) { putchar(stu[i].name[j]); } printf("\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\n",stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); } } //写入文件 elseif(con==12) { wri(stu,n); } //读取文件 elseif(con==13) { rea(stu,n); } elseif(con==0) { printf("Endofprogram! \n"); } else { printf("Inputerror! \n"); } } } 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("course%d: sum=%.0f,aver=%.0f\n",(j+1),sum,(sum/n)); } } voidadds(structstudent*pt,intn) { inti; for(i=0;i { stu[i].score[3]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2]; printf("student%d: sum=%.0f,aver=%.0f\n",(i+1),stu[i].score[3],(stu[i].score[3]/3)); } } voidpxs(structstudent*pt,int(*comp)(floata,floatb),intn) { inti,j; structstudenttemp; for(i=0;i { for(j=0;j<(n-i-1);j++) { if((*comp)(stu[j].score[3],stu[j+1].score[3])) { temp=stu[j]; stu[j]=stu[j+1]; stu[j+1]=temp; } } } for(i=0;i { printf("%ld\t",stu[i].id); for(j=0;stu[i].name[j]! ='\n';j++) { putchar(stu[i].name[j]); } printf("\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\n",stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); } } intds(floata,floatb) { returna } intas(floata,floatb) { returna>b; } voidpxi(structstudent*pt,intn) { inti,j; structstudenttemp; for(i=0;i { for(j=0;j<(n-i-1);j++) { if(stu[j].id>stu[j+1].id) { temp=stu[j]; stu[j]=stu[j+1]; stu[j+1]=temp; } } } for(i=0;i { printf("%ld\t",stu[i].id); for(j=0;stu[i].name[j]! ='\n';j++) { putchar(stu[i].name[j]); } printf("\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\n",stu[i].score[0],stu[i].score[1],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-1);j++) { if(strcmp(stu[j].name,stu[j+1].name)>0) { temp=stu[j]; stu[j]=stu[j+1]; stu[j+1]=temp; } } } for(i=0;i { printf("%ld\t",stu[i].id); for(j=0;stu[i].name[j]! ='\n';j++) { putchar(stu[i].name[j]); } printf("\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\n",stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); } } voidseai(structstudent*pt,intn) { inti,j,con=0; longid; structstudenttemp; printf("Inputthenumberyouwanttosearch: "); scanf("%ld",&id); for(i=0;i { for(j=0;j<(n-i-1);j++) { if(stu[j].score[3] { temp=stu[j]; stu[j]=stu[j+1]; stu[j+1]=temp; } } } for(i=0;i { if(stu[i].id==id) { printf("%d\t%ld\t",(i+1),stu[i].id); for(j=0;stu[i].name[j]! ='\n';j++) { putchar(stu[i].name[j]); } printf("\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\n",stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); con=1; break; } } if(con==0) printf("Notfound! \n"); } voidsean(structstudent*pt,intn) { inti,j,con=0; charname[10]; structstudenttemp; printf("Inputthenameyouwanttosearch: "); getchar(); fgets(name,sizeof(name),stdin);///有问题! ! ! ! for(i=0;i { for(j=0;j<(n-i-1);j++) { if(stu[j].score[3] { temp=stu[j]; stu[j]=stu[j+1]; stu[j+1]=temp; } } } for(i=0;i { if(strcmp(stu[i].name,name)==0) { printf("%d\t%ld\t",(i+1),stu[i].id); for(j=0;stu[i].name[j]! ='\n';j++) { putchar(stu[i].name[j]); } printf("\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\n",stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); con=1; break; } } if(con==0) printf("Notfound! \n"); } voidana(structstudent*pt,intn) { inti,j,n1,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) n1+=1; elseif(stu[i].score[j]<70) n2+=1; elseif(stu[i].score[j]<80) n3+=1; elseif(stu[i].score[j]<90) n4+=1; elseif(stu[i].score[j]<=100) { n5+=1; if(stu[i].score[j]==100) n6+=1; } } printf("Forcourse%d: \n",(j+1)); printf("<60\t%d\t%.2f%%\n",n1,100*(float)n1/n); printf("%d-%d\t%d\t%.2f%%\n",60,69,n2,100*(float)n2/n); printf("%d-%d\t%d\t%.2f%%\n",70,79,n3,100*(float)n3/n); printf("%d-%d\t%d\t%.2f%%\n",80,89,n4,100*(float)n4/n); printf("%d-%d\t%d\t%.2f%%\n",90,100,n5,100*(float)n5/n); printf("%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 { for(j=0;j<(n-i-1);j++) { if(stu[j].id>stu[j+1].id) { temp=stu[j]; stu[j]=stu[j+1]; stu[j+1]=temp; } } } if((fp=fopen("student.txt","w"))==NULL) exit(0); //fprintf(fp,"NO\tName\tMT\tEN\tPH\tSUM\tAVER\n"); for(i=0;i { fprintf(fp,"%ld\t",stu[i].id); for(j=0;stu[i].name[j]! ='\n';j++) { fprintf(fp,"%c",stu[i].name[j]); } fprintf(fp,"\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\n",stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],(stu[i].score[3]/3)); } fclose(fp); printf("savesuccessfully! "); } voidrea(STUDENT*pt,intn) { FILE*fp; intm; longa; floatc,d,e,f,g; charb[10]; //charhead[50]; if((fp=fopen("student.txt","r"))==NULL) exit(0); //fgets(head,50,fp); //puts(head); printf("NO\tName\tMT\tEN\tPH\tSUM\tAVER\n"); for(m=0;m { //printf("scjdbfdsdj"); fscanf(fp,"%ld",&a); printf("%ld\t",a); fscanf(fp,"%10s",b); printf("%s\t",b); fscanf(fp,"%f",&c); printf("%.0f\t",c); fscanf(fp,"%f",&d); printf("%.0f\t",d); fscanf(fp,"%f",&e); printf("%.0f\t",e); fscanf(fp,"%f",&f); printf("%.0f\t",f); fscanf(fp,"%f",&g); printf("%.0f\n",g); //printf("jdhergjdkfnjherdgfdhb\n"); } fclose(fp); }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 输入输出 排序 打印 学生 成绩单
![提示](https://static.bdocx.com/images/bang_tan.gif)