/* insert()
{
int i;
int j;
int k;
printf("Input student's number and name:\n");
scanf("%d%s",&stu[N].num,stu[N].name);
if((fp=fopen("student","w"))==NULL)
{ printf("can not open the file.\n"); exit(0);}
if (stu[N].num<stu[N-1].num)
{ for(i=0;i<N;i++)
{k=i; for(j=i+1;j<=N;j++)
if(stu[j].num<stu[k].num) k=j;
if(k!=i) {t=stu[i];stu[i]=stu[k];stu[k]=t;}}
for (i=0;i<N;i++)
if(fwite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("error\n");
fclose(fp);
N=N+1;
meau();
} */
deleted()
{
int i;
int j;
int n;
int flag;
int num;
printf("\n Input number deleted:");
scanf("%d",&num);
for(flag=1,i=0;i<N;i++)
{if(num==stu[i].num)
for(j=i;j<N;j++) stu[j]=stu[j++]; flag=0;
} if(!flag) N=N-1;else printf("\n not found!");
fp=fopen("student","wb");
for (i=0;i<N;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("error\n");
fclose(fp);
meau();}
check()
{ char a; int i;
int b;
int c;
printf("Deng ji na yi xiang chang ji('X','Q','S')\n? ");
scanf("%s",&a);
if(a=='X'||a=='x')
{ printf("Qing shu ru di ji ci cheng ji:\n");
scanf("%d",&c);
printf("Qing shu ru cheng ji:\n");
for (i=0;i<N;i++)
scanf("%f",&stu[i].xiti[a-1]);
}else if(a=='Q'||a=='q')
{ printf("Qing shu ru di ji ci cheng ji:\n");
scanf("%d",&b);
printf("Qing shu ru cheng ji:\n");
for (i=0;i<N;i++)
scanf("%f",&stu[i].quiz[a-1]);
}else if(a=='S'||a=='s')
{ printf("Qing shu ru kao shi cheng ji:\n");
for (i=0;i<N;i++)
scanf("%f",&stu[i].score1);
fp=fopen("student","wb");
for (i=0;i<N;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("error\n");
fclose(fp);
meau();
}
}
amend()
{ printf("amend right!"); meau();}
print()
{ int i;
printf("SCORTED STUDENT'S SCORES LIST IS AS FELLOWS\n\n\n");
printf("------------------------------------------------------------------------\n");
printf(" NO. NAME SCORE1 SCORE2 SCORE3 TOTAL \n");
printf("------------------------------------------------------------------------\n");
fp=fopen("student","rb");
for (i=0;i<N;i++)
{fread(&stu[i],sizeof(struct student),1,fp);
printf("%4d%6s%8d%8d%8d%10.2f\n",stu[i].num,stu[i].name,stu[i].score1,
stu[i].score2,stu[i].score3,stu[i].total); }
fclose(fp);
meau();
}
chaxun(int num)
{int i;
fp=fopen("student","rb");
for (i=0;i<N;i++)
if(fread(&stu[i],sizeof(struct student),1,fp)!=1)
printf("error\n");
for (i=0;i<N;i++)
if(num==stu[i].num)
printf("SCORTED STUDENT'S SCORES LIST IS AS FELLOWS\n");
printf("------------------------------------------------------------------------\n");
printf(" NO. NAME SCORE1 SCORE2 SCORE3 TOTAL ");
printf("------------------------------------------------------------------------\n");
printf("%3d%-10s%8d%8d%8d%10.2f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total);
fclose(fp);
meau();
}
meau()
{char e;
printf("\n\n --------------------------------------------------------------------------\n");
printf(" Qing xuan ze: A.charu B.dengji C.xiugai D.shanchu E.print F.exit\n ");
printf(" --------------------------------------------------------------------------\n");
scanf("%s",&e);
switch(e){
case 'a':insert();break;
case 'b':check();break;
case 'c':amend();break;
case 'd':deleted();break;
case 'e':print();break;
case 'f':exit(0);break;
default:printf("Error!\n");
}
}
jisuan()
{ int i;
int j;
int k;
int s=0;
int t=0;
for(i=0;i<N;i++)
{for(j=0;j<16;j++)
s+=stu[i].xiti[j]; stu[i].score2=s;
}
for(i=0;i<N;i++)
{for(k=0;k<3;k++)
t+=stu[i].quiz[k]; stu[i].score3=t;
}
for(i=0;i<N;i++)
stu[i].total=stu[i].score2+stu[i].score3+stu[i].score1;
}
/*jisuan()
{ int i;
int j;
int k;
int s=0;
int t=0;
for(i=0;i<N;i++)
{for(j=0;j<16;j++)
s+=stu[i].xiti[j]; stu[i].score2=s/16.0;
}
for(i=0;i<N;i++)
{for(k=0;k<3;k++)
t+=stu[i].quiz[k]; stu[i].score3=t/3.0;
}
for(i=0;i<N;i++)
stu[i].total=stu[i].score2*10/100.0+stu[i].score3*20/100.0+stu[i].score1*70/100.0;
} */
meau2()
{int n;
printf("Input Your Number:");
scanf("%d",&n);
chaxun(n);
}