学生成绩管理系统的代码是什么?

2024-11-24 22:51:34
推荐回答(1个)
回答1:

代码如下:

for(i=0;i<66;i++)

printf("*");

printf("\n");

printf("1.Input record\n");

printf("2.Caculate totel and average score of every course\n");

printf("3.Caculate totel and average score of every student\n");

printf("4.Sort in descending order by total score of every student\n");

printf("5.Sort in ascending order by total score of every student\n");

printf("6.Sort in ascending order by number\n");

printf("7.Sort in ascending order by name\n");

printf("8.Search by number\n");

printf("9.Search by name\n");

printf("10.Statistic analysis for every course\n");

printf("11.List record\n");

printf("12.Write to a file\n");

printf("13.Read from a file\n");

printf("0.Exit\n");

for(i=0;i<66;i++)

printf("*");

printf("\n");

printf("Please enter your choice:");

printf("\n");

输入函数:

void Readscore (STU stu[],int n,int m)    //1.输入数据

{

int i,j;

for(i=0;i

{

printf("Input student's ID ,name and score");

scanf("%ld",&stu[i].studentID);

scanf("%s",stu[i].studentName);

for(j=0;j

scanf("%d",&stu[i].score[j]);

}

}

数据处理函数:

void Tota (STU stu[],int n,int m)     //2.计算每门课程的总分和平均分

{

int i,j,sum[M];

double ave[M];

for(j=0;j

{

sum[j]=0;

for(i=0;i

{

sum[j]=sum[j]+stu[i].score[j];

}

ave[j]=(double)sum[j]/n;

}

for(i=0;i

printf("Project %d 总分=%d,课程的平均分=%f\n",i+1,sum[i],ave[i]);

}

void Datasort_1 (STU stu[],int n,int m)     //3.计算每个学生的总分和平均分

{

int i,j,sum[N];

double ave[N];

for(i=0;i

{

sum[i]=0;

for(j=0;j

{

sum[i]=sum[i]+stu[i].score[j];

}

ave[i]=(double)sum[i]/m;

}

for(i=0;i

printf("ID:%10ld,Name: %s Allscore=%d,The ave=%f\n",stu[i].studentID,stu[i].studentName,sum[i],ave[i]);

}

排序函数:

void Datasort_2 (STU stu[],int n,int m)          //4.按每个学生的总分由高到低排出名次表

{

int i,j,k,h,sum[N];

STU t;

for(i=0;i

{

sum[i]=0;

for(j=0;j

{

sum[i]=sum[i]+stu[i].score[j];

}

}

for(i=0;i

{

k=i;

for(j=i+1;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

printf("ID:%10ld,Name:%s,Score:%d\n",stu[i].studentID,stu[i].studentName,sum[i]);

}

void Datasort_3 (STU stu[],int n,int m)          //5.按每个学生的总分由低到高排出名次表

{

int i,j,k,h,sum[N];

STU t;

for(i=0;i

{

sum[i]=0;

for(j=0;j

{

sum[i]=sum[i]+stu[i].score[j];

}

}

for(i=0;i

{

k=i;

for(j=i+1;j

{

if (sum[j]

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

printf("ID:%10ld,Name:%s,score:%d\n",stu[i].studentID,stu[i].studentName,sum[i]);

}

void Datasort_4 (STU stu[],int n,int m)    //6.按学号由小到大排出名次表

{

int i,j,k;

STU t;

for(i=0;i

{

k=i;

for(j=i+1;j

{

if (stu[j].studentID

k=j;

}

if(i!=k)

t=stu[k],stu[k]=stu[i],stu[i]=t;

}

for(i=0;i

{

printf("ID:%10ld,Name:%s\n",stu[i].studentID,stu[i].studentName);

for(j=0;j

printf("Project %d Score:%d\n",j+1,stu[i].score[j]);

}

}

数据分析函数:

void Statistis (STU stu[],int n,int m)   //10.

{

int i,j,count_1,count_2,count_3,count_4,count_5;

for(j=0;j

{

count_1=0,count_2=0,count_3=0,count_4=0,count_5=0;

for(i=0;i

{

if(stu[i].score[j]>=90)

count_1++;

else if(stu[i].score[j]>=80)

count_2++;

else if(stu[i].score[j]>=70)

count_3++;

else if(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);

}

}

数据界面打印函数:

void List (STU stu[],int n,int m)         //11.

{

int i,j,sum[N];

double ave[N];

for(i=0;i

{

sum[i]=0;

for(j=0;j

{

sum[i]=sum[i]+stu[i].score[j];

}

ave[i]=(double)sum[i]/m;

}

for(i=0;i

{

printf("ID:%10ld,Name:%s\n",stu[i].studentID,stu[i].studentName);

for(j=0;j

{

printf("Score %d :%d\n",j+1,stu[i].score[j]);

}

printf("Allscore=%d\n平均分%f\n",sum[i],ave[i]);

}

}

文件处理函数:

void WritetoFile(STU stu[],int n,int m)     //将每个学生的记录信息写入文件

{

Tota(stu,n,m);

Datasort_2 (stu,n,m);

FILE *fp;

if((fp=fopen("student.txt","w"))==NULL)

{

printf("Failure to open student.txt!\n");

exit(0);

}

fwrite(stu,sizeof(STU),n,fp);

fclose(fp);

}

int ReadfromFile(STU stu[],int n,int m)//从文件中读出每个学生的记录信息并显示

{

FILE *fp;

int i;

if((fp=fopen("student.txt","r"))==NULL)

{

printf("Failure to open student.txt!\n");

exit(0);

}

for(i=0;!feof(fp);i++)

{

fread(&stu[i],sizeof(STU),1,fp);

}

fclose(fp);

printf("Total student is %d.\n",i-1);

n=i-1;

List(stu,n,m);      //输出从文件中读出的信息到屏幕上

return i-1;

}