go语言学生管理练习题 go语言学生管理系统( 四 )


p=head;
do
{printf("|%d\t|%s\t|%.1f\t|%.1f\t|%.1f\t|\n",p-number,p-name,p-computer,p-english,p-math);
printf("-----------------------------------------\n");
p=p-next;}while (p!=NULL);
}
}
/*==============================================================================================*/
score *tongji(score *head)
/*函数tongji,功能:统计学生成绩*/
{
float sum1=0,sum2=0,sum3=0,ave1=0,ave2=0,ave3=0,max=0,min;
score *p;
int x,y=0,i=0;
p=head;
printf("1个人总分和平均分\t2单科平均分\t3总分最高分\t4总分最低分\n");
scanf("%d",x);
getchar();
switch(x)
{
case 1: if(head==NULL)
{printf("\n没有任何学生资料!\n");return(head);}
else
{
printf("---------------------------------------------------------\n");
printf("|学号\t|姓名\t|计算机\t|英语\t|数学\t|总分\t|平均分\t|\n");
printf("---------------------------------------------------------\n");
while(p!=NULL)
{
sum1=p-computer+p-english+p-math;
ave1=sum1/3;
printf("|%d\t|%s\t|%.1f\t|%.1f\t|%.1f\t|%.1f\t|%.1f\t|\n",p-number,p-name,p-computer,p-english,p-math,sum1,ave1);
printf("---------------------------------------------------------\n");/*打印表格域*/
p=p-next;}
}
return(head);break;
case 2: if(head==NULL)
{printf("\n没有任何学生资料!\n");return(head);}
while(p!=NULL)
{
sum1=sum1+p-computer;
sum2=sum2+p-english;
sum3=sum3+p-math;/*计算总分*/
y=y+1;
ave1=sum1/y;
ave2=sum2/y;
ave3=sum3/y;
p=p-next;
}
printf("计算机 平均分是%.1f\n",ave1);
printf("英语平均分是%.1f\n",ave2);
printf("数学平均分是%.1f\n",ave3);
return(head); break;
case 3:
if(head==NULL)
{printf("\n没有任何学生资料!\n");return(head);}
max=p-computer+p-english+p-math;
while(in)
{
i=i+1;
sum1=p-computer+p-english+p-math;
if(maxsum1)
max=sum1;
p=p-next;
}
printf("总分最高分:%.1f",max);
printf("\n");
return(head); break;
case 4: if(head==NULL)
{printf("\n没有任何学生资料!\n");return(head);}
while(p!=NULL)
{
min=p-computer+p-english+p-math;
while(p!=NULL)
{sum2=p-computer+p-english+p-math;
if(minsum2)
min=sum2;
p=p-next;
}
}
printf("总分最低分:%.1f",min);
printf("\n");
return(head); break;
default :printf("输入错误,请重试!\n");
}
return(head);
}
/*==============================================================================================*/
save(score *p1)
/*函数save,功能:保存学生的资料*/
{
FILE *fp;
char filepn[20];/*用来存放文件保存路径以及文件名*/
printf("请输入文件路径及文件名:");
scanf("%s",filepn);
if((fp=fopen(filepn,"w+"))==NULL)
{
printf("不能打开文件!\n");
return 0;
}
fprintf(fp,"|学号\t|姓名\t|计算机\t|英语\t|数学\t|\n");
fprintf(fp,"-----------------------------------------\n");
while(p1!=NULL)
{
fprintf(fp,"%d\t%s\t%.1f\t%.1f\t%.1f\t\n",p1-number,p1-name,p1-computer,p1-english,p1-math);
p1=p1-next;
}
fclose(fp);
printf("文件已经保存!\n");
return 0;
}
/*==============================================================================================*/
score *paixu(score *head) /*定义排序函数 。此函数带回一个指向链表头的指针*/
{ score *p,*max;
inti,j,x;
float fen;
char t[10];
if(head==NULL)
{printf("\n没有任何学生资料,请先建立链表!\n");return(head);}/*链表为空*/
max=p=head;

推荐阅读