C语言高手帮帮忙
编制一个统计存储在文件中的学生考试分数的管理程序。设学生成绩以一个学生一条记录的形式存储在文件中,每个学生记录包含的信息有姓名、学号和数学、语文和英语三门功课的成绩。要求编制具有以下几项功能的程序:求出各门课程的平均分;在屏幕上显示全部学生成绩;按总分由高到低显示学生信息(用冒泡排序法排序···)。
答案:#include "stdio.h"
struct student
{ char name[12];
int num;
int grade[3];
}stu[3];
int inputgrade()
{ int i; FILE *fp;
if((fp=fopen("b.txt","r"))==NULL)
{ printf("cannot open file.\
");
exit(0); }
for(i=0;i<3;i++)
fscanf(fp,"%s %d %d %d %d",stu[i].name,&stu[i].num,&stu[i].grade[0],&stu[i].grade[1],&stu[i].grade[2]);
printf("The grade has enter.\
");
fclose(fp);
}
int outputgrade()
{ int i;
printf(" the grade is:\
");
for(i=0;i<3;i++)
{ printf("%s %d %d %d %d",stu[i].name,stu[i].num,stu[i].grade[0],stu[i].grade[1],stu[i].grade[2]);
printf("\
"); }
}
int average()
{ int i,j; float sum,aver;
for(j=0;j<3;j++)
{ sum=0; aver=0;
for(i=0;i<3;i++)
{ sum=sum+stu[i].grade[j]; }
aver=sum/3.0;
printf("The %d grade average is %f.\
",j,aver); }
return 0;
}
int maopaosort()
{
int i,j,k,t,gra[9];
for(k=0;k<3;k++)
gra[k]=stu[0].grade[k];
for(k=3;k<6;k++)
gra[k]=stu[1].grade[k-3];
for(k=6;k<9;k++)
gra[k]=stu[2].grade[k-6];
for(j=0;j<8;j++)
for(i=0;i<8-j;i++)
if(gra[i+1]<gra[i])
{
t=gra[i];
gra[i]=gra[i+1];
gra[i+1]=t;
}
printf("the sort number is:\
");
for(k=8;k>=0;k--)
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(gra[k]==stu[i].grade[j])
printf("%d %s %d\
",gra[k],stu[i].name,stu[i].num);
}
main()
{ int s,i,flag,l;
int pass[4];
printf("This is a performance management system:\
");
for(l=0;l<3;l++)
{ flag=0;
printf("
please enter the password: ");
scanf("%1d%1d%1d%1d",&pass[0],&pass[1],&pass[2],&pass[3]);
for(i=0;i<4;i++)
if(pass[i]==i+1) flag=flag+1;
if(flag==4) { printf("You enter the performance management system:\
");
printf("they are four choose:\
");
printf("choose one is grade input,enter choose one,please enter 1 :\
");
printf("choose two is grade output,enter choose two,please enter 2 :\
");
printf("choose three is grade average,enter choose three,please enter 3 :\
");
printf("choose three is grade sort,enter choose four,please enter 4 :\
");
for(i=0;i<5;i++)
{ printf("please enter you choose: ");
scanf("%d",&s);
printf("\
");
switch(s)
{case 1:inputgrade();break;
case 2:outputgrade();break;
case 3:average();break;
case 4:maopaosort();break;
default :printf("you enter choose is wrong.\
"); }
}
}
else printf("the password is wrong.\
") ; }
getch();
}
这个我已经调试好了
要源程序的话hi我
进入系统的密码是1234
b.txt 中的内容是
liudenghua 2021 89 78 67
guofucheng 2022 99 98 97
zhangxueyou 2023 88 87 76
刚才又改了一下 刚才有个功能没实现 就是冒泡法后输出学生信息
现在改好了 要是有什么问题 hi我就OK了嗯 报酬呢?
上一个:C语言做课程设计
下一个:c语言程序的含义