我也编写了一个学生成绩管理系统,可是怎么都有错,求高手帮忙看一下,谢谢
#include<stdio.h>#include<string.h>
#define SIZE 30
#define FORMAT "%7d %-20s %4d %4d %4d %4d\n"
struct student
{int num;
char name[20];
float score[4];
float average;
int rank;
}
struct student stu[SIZE],sort[SIZE],fail[SIZE],good[SIZE]; /*结构体*/
void save()
{FILE*fp;
fp=fopen("stu_dat","wb"); /*为读写建立一个新的二进制文件*/
int i;
for(i=0;i<SIZE;i++) /*判断写入格式是否正确*/
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
void main()
{int i,j,t,n;
float *zaver;
printf("请输入每位同学的成绩\n");
printf("No. Name 数电 模电 信号 英语\n");
for(i=0;i<SIZE;i++)
{
scanf(FORMAT,&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2],&stu[i].score[3]);
stu[i].rank=i+1;
}
save();
void averon(struct student*);
averon(&stu); /*计算每位同学的总平均分*/
for(n=0;n<SIZE;n++)
for(j=0;j<SIZE-1;j++)
for(i=0;i<SIZE-j;i++)
if(p->(stu[n].average)<p->(stu[n+1].average))
{
t=p->(stu[n].rank);
p->(stu[n].rank)=p->(stu[n+1].average);
p->(stu[n+1].average)=t;
}
for(t=0;t<SIZE;t++)
for(n=0;n<SIZE;n++)
if(strcmp(p->(stu[n].rank),t+1)==0)
{
p->(sort[t].num)=p->(stu[n].num);
p->(sort[t].name)=p->(stu[n].name);
p->(sort[t].score[1])=p->(stu[n].score[1]);
p->(sort[t].score[2])=p->(stu[n].score[2]);
p->(sort[t].score[3])=p->(stu[n].score[3]);
p->(sort[t].score[4])=p->(stu[n].score[4]);
p->(sort[t].average)=p->(stu[n].average);
p->(sort[t].rank)=p->(stu[n].rank);
printf("classification of data:")
for(t=0;t<SIZE;t++)
printf(FORMAT,&sort[t].num,sort[t].name,&sort[t].score[0],&sort[t].score[1],&sort[t].score[2],&sort[t].score[3]);
}
for(t=0;t<SIZE;t++)
for(i=0;i<SIZE;i++)
if(p->(sort[t].score[i])<60)
{
p->(fail[t].num)=p->(sort[t].num);
p->(fail[t].name)=p->(sort[t].name);
p->(fail[t].score[1])=p->(sort[t].score[1]);
p->(fail[t].score[2])=p->(sort[t].score[2]);
p->(fail[t].score[3])=p->(sort[t].score[3]);
p->(fail[t].score[4])=p->(sort[t].score[4]);
p->(fail[t].average)=p->(sort[t].average);
p->(fail[t].rank)=p->(sort[t].rank);
break;
}
for(t=0;t<SIZE;t++)
if(p->(sort[t].rank)<SIZE*0.4)
{
p->(good[t].num)=p->(sort[t].num);
p->(good[t].name)=p->(sort[t].name);
p->(good[t].score[1])=p->(sort[t].score[1]);
p->(good[t].score[2])=p->(sort[t].score[2]);
p->(good[t].score[3])=p->(sort[t].score[3]);
p->(good[t].score[4])=p->(sort[t].score[4]);
p->(good[t].average)=p->(sort[t].average);
p->(good[t].rank)=p->(sort[t].rank);
}
printf("students that can apply for scholarships are:")
for(t=0;t<SIZE*0.4;t++)
printf(FORMAT,&good[t].num,good[t].name,&stu[t].score[0],&stu[t].score[1],&stu[t].score[2],&stu[t].score[3]);
}
void averon(stuct student*p)
{float sum=0,aver,AVER;
for(p=stu;p<stu+30;p++)
{
sum=sum+(p->score[1])+(p->score[2])+(p->score[3])+(p->score[4]);
aver=sum/4;
(*p).average=aver;
for(p=stu;p<stu+30;p++)
sum=sum+(p->score[1])+(p->score[2])+(p->score[3])+(p->score[4])
AVER=sum/30;
*zaver=AVER; /*计算全班成绩的总平均分*/
}