代码如下:
for(i=0;i<66;i++)
printf("*");
printf("\n");
printf("1.Inputrecord\n");
printf("2.Caculatetotelandaveragescoreofe控架旧耐verycourse\n");
printf360问答("3.Caculatetotelandaveragescoreofeverystudent\n");
printf("4.Sortin测descendingorderbytotalscoreofeverystudent\n");
printf("5.Sortinascendingorderbytotalscoreofeverystudent\n");
print音主早关均酸志总名f("6.Sort对首映连刘inascendingorderbynumber\n");
printf("延怕脱意7.Sortinascendingorderbyname\n");
printf("8.Searchbynumber\n");
printf("9.Searchby线离故等降元布氢低孔术name\n");
printf("10.Statisticanalysisforeverycour移小煤查茶角杀se\n");
printf("11.Listrecord\n");
printf("12.Writetoafile\n");
printf("***.readfromafile\n")必牛边著观;
printf("0.Exit\n");
for(i=0;i<66;i++)
printf("*");
printf("\n");
printf("Pleaseenteryourchoice:");
printf("\n");
输入函数:
voidReadscore(STUstu[],intn,intm) //1.输入数据
{
i静皮即有家施跟聚路nti,j;
for(i=0;i<n;i++)
{
p端婷阿兰杀特洋反rintf("Inputstudent'sID,nameandsco夜没高孙象呼他反向振皮re");
scanf("%ld",&stu[i].studentID);
scanf("%s",stu乱怕洋真束[i].studentName);
for(j厚蒸慢顾顾当情答武孔形=0;j<m;j++)
scanf给每感故运甚富灯他("%d",&stu[i].score[j]);
}
}
数据处理函数:
voidTota(STUstu[],intn法场顾哥思,intm) //2.计算每门课程的总分和平均分
{
inti,j,sum[M];
doubleave[M];
for(j=0;j<m;j++)
{
sum[j]=0;
for(i=0;i<n;i++)
{
sum[义双肥触告j]=sum[j]+stu[景师兵学修还i].score[j];
}
ave[j]=(double)sum[j]/n;
}
for(i=0;i<m;i++)
printf("川讲升始部机倍Project%d总分=%d,课程的平均分=%f\n",i+1,sum[i],ave[i]);
}
voidDatasort_1(STUstu[],intn,intm) //3.计算每个学生的总分和平均分
{
inti,j,sum[N];
doubleave[N];
for(i=0;i<n;i++)
{
sum[i]=0;
for(j=0;j<m;j++)
{
sum[i]=sum[i]+stu[i].score[j];
}
ave[i]=(double)sum[i]/m;
}
for(i=0;i<n;i++)
printf("ID:%10ld,Name:%sAllscore=%d,Theave=%f\n",stu[i].studentID,stu[i].studentName,sum[i],ave[i]);
}
排序函数:
voidDatasort_2(STUstu[],intn,intm) //4.按每个学生的总分由高到低排出名次表
{
inti,j,k,h,sum[N];
STUt;
for(i=0;i<n;i++)
{
sum[i]=0;
for(j=0;j<m;j++)
{
sum[i]=sum[i]+stu[i].score[j];
}
}
for(i=0;i<n;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(sum[j]>sum[k])
k=j;
}
if(i!=k)
{
t=stu[i],h=sum[i];
stu[i]=stu[k],sum[i]=sum[k];
stu[k]=t,sum[k]=h;
}
}
for(i=0;i<n;i++)
printf("ID:%10ld,Name:%s,Score:%d\n",stu[i].studentID,stu[i].studentName,sum[i]);
}
voidDatasort_3(STUstu[],intn,intm) //5.按每个学生的总分由低到高排出名次表
{
inti,j,k,h,sum[N];
STUt;
for(i=0;i<n;i++)
{
sum[i]=0;
for(j=0;j<m;j++)
{
sum[i]=sum[i]+stu[i].score[j];
}
}
for(i=0;i<n;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(sum[j]<sum[k])
k=j;
}
if(i!=k)
{
t=stu[i],h=sum[i];
stu[i]=stu[k],sum[i]=sum[k];
stu[k]=t,sum[k]=h;
}
}
for(i=0;i<n;i++)
printf("ID:%10ld,Name:%s,score:%d\n",stu[i].studentID,stu[i].studentName,sum[i]);
}
voidDatasort_4(STUstu[],intn,intm) //6.按学号由小到大排出名次表
{
inti,j,k;
STUt;
for(i=0;i<n;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(stu[j].studentID<stu[k].studentID)
k=j;
}
if(i!=k)
t=stu[k],stu[k]=stu[i],stu[i]=t;
}
for(i=0;i<n;i++)
{
printf("ID:%10ld,Name:%s\n",stu[i].studentID,stu[i].studentName);
for(j=0;j<m;j++)
printf("Project%dScore:%d\n",j+1,stu[i].score[j]);
}
}
数据分析函数:
voidStatistis(STUstu[],intn,intm) //10.
{
inti,j,count_1,count_2,count_3,count_4,count_5;
for(j=0;j<m;j++)
{
count_1=0,count_2=0,count_3=0,count_4=0,count_5=0;
for(i=0;i<n;i++)
{
if(stu[i].score[j]>=90)
count_1++;
elseif(stu[i].score[j]>=80)
count_2++;
elseif(stu[i].score[j]>=70)
count_3++;
elseif(stu[i].score[j]>=60)
count_4++;
else
count_5++;
}
printf("project%d\n",j+1);
printf("优秀:%d\t优秀率:%f%\n",count_1,(float)count_1/n);
printf("良好:%d\t良好率:%f%\n",count_2,(float)count_2/n);
printf("中等:%d\t中等率:%f\n",count_3,(float)count_3/n);
printf("及格:%d\t及格率:%f\n",count_4,(float)count_4/n);
printf("不及格:%d\t不及格率:%f\n",count_5,(float)count_5/n);
}
}
数据界面打印函数:
voidList(STUstu[],intn,intm) //11.
{
inti,j,sum[N];
doubleave[N];
for(i=0;i<n;i++)
{
sum[i]=0;
for(j=0;j<m;j++)
{
sum[i]=sum[i]+stu[i].score[j];
}
ave[i]=(double)sum[i]/m;
}
for(i=0;i<n;i++)
{
printf("ID:%10ld,Name:%s\n",stu[i].studentID,stu[i].studentName);
for(j=0;j<m;j++)
{
printf("Score%d:%d\n",j+1,stu[i].score[j]);
}
printf("Allscore=%d\n平均分%f\n",sum[i],ave[i]);
}
}
文件处理函数:
voidWritetoFile(STUstu[],intn,intm) //将每个学生的记录信息写入文件
{
Tota(stu,n,m);
Datasort_2(stu,n,m);
FILE*fp;
if((fp=fopen("student.txt","w"))==NULL)
{
printf("Failuretoopenstudent.txt!\n");
exit(0);
}
fwrite(stu,sizeof(STU),n,fp);
fclose(fp);
}
intReadfromFile(STUstu[],intn,intm)//从文件中读出每个学生的记录信息并显示
{
FILE*fp;
inti;
if((fp=fopen("student.txt","r"))==NULL)
{
printf("Failuretoopenstudent.txt!\n");
exit(0);
}
for(i=0;!feof(fp);i++)
{
fread(&stu[i],sizeof(STU),1,fp);
}
fclose(fp);
printf("Totalstudentis%d.\n",i-1);
n=i-1;
List(stu,n,m); //输出从文件中读出的信息到屏幕上
returni-1;
}
标签:管理系统,代码,成绩