You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.3 KiB

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
struct stud
{
char id[20];
char clas[20];
char name[20];
double score1;
double score2;
double score3;
double score;
};int SSS;int rak[20];
int main()
{struct stud stu[10];
void men();void inpu(struct stud stu[10],int n[1]);void del(struct stud stu[10],int n[1]);void sel(struct stud stu[10],int n[1]);
void ord(struct stud stu[10],int n[1]);void out(struct stud stu[10],int n[1]);
int n[1];int i;
for(i=0;i<20;i++){rak[i]=i;}
start:
men();scanf("%d",&i);
switch(i)
{case 1:inpu(stu,n);goto start;
case 2:del(stu,n);goto start;
case 3:sel(stu,n);goto start;
case 4:ord(stu,n);goto start;
case 5:out(stu,n);goto start;
case 6:break;
}
return 0;
}
void men()
{printf("\n1.input\n2.delete\n3.select\n4.order\n5.output\n6.quit\nplease input your option\n");}
void inpu(struct stud stu[10],int n[1])
{int i=0,p=1;char a[20];
while(p)
{printf("Id ");scanf("%s",&stu[i].id);
printf("class ");scanf("%s",&stu[i].clas);
printf("name ");scanf("%s",&stu[i].name);
printf("score1 ");scanf("%lf",&stu[i].score1);
printf("score2 ");scanf("%lf",&stu[i].score2);
printf("score3 ");scanf("%lf",&stu[i].score3);
printf("continue?\n");
while(1){scanf("%s",&a);
if(strcmp(a,"no")==0){p=0;n[0]=SSS=i;break;}else if(strcmp(a,"yes")==0){break;}else{printf("please input yes/no\n");}}
i++;
}}
void del(struct stud stu[10],int n[1])
{char a[20];int i,p=1;
while(p)
{scanf("%s",&a);
for(i=0;i<=n[0];i++)
{if(strcmp(a,stu[i].id)==0||strcmp(a,stu[i].name)==0){break;}}
if(i<=n[0]&&SSS)
{strcpy(stu[i].id,"");strcpy(stu[i].clas,"");strcpy(stu[i].name,"");stu[i].score1=0;stu[i].score2=0;stu[i].score3=0;SSS--;}
for(i=0;i<=n[0];i++)
{if(stu[i].score1!=0)
{printf("%s %s %s %3.1f %3.1f %3.1f\n",stu[i].id,stu[i].clas,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3);}}
printf("continue?\n");
while(1){scanf("%s",&a);
if(strcmp(a,"no")==0){p=0;break;}else if(strcmp(a,"yes")==0){break;}else{printf("please input yes/no\n");}}
}for(i=0;i<20;i++){rak[i]=i;}}
void sel(struct stud stu[10],int n[1])
{int i,p=1,t;char a[20];
while(p)
{scanf("%s",&a);
t=1;
for(i=0;i<=n[0];i++)
{if(strcmp(a,stu[i].id)==0||strcmp(a,stu[i].clas)==0)
{t=0;printf("%s %s %s %3.1f %3.1f %3.1f\n",stu[i].id,stu[i].clas,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3);}}
if(t){printf("there is no eligible student\n");}printf("continue?\n");
while(1){scanf("%s",&a);
if(strcmp(a,"no")==0){p=0;break;}else if(strcmp(a,"yes")==0){break;}else{printf("please input yes/no\n");}}
}}
void ord(struct stud stu[10],int n[1])
{int i,j,k,a,b;int mark[20];
for(i=0;i<=n[0];i++){mark[i]=0;stu[i].score=stu[i].score1+stu[i].score2+stu[i].score3;}
for(i=0;i<=SSS;i++)
{for(k=0,j=0;j<=n[0]&&k<=n[0];)
{if(mark[j]||stu[j].score1==0){j++;continue;}if(mark[k]||stu[k].score1==0){k++;continue;}
a=atoi(stu[j].clas);b=atoi(stu[k].clas);
if(a<b){k=j;}if(a==b&&stu[j].score>stu[k].score){k=j;}j++;continue;
}rak[i]=k;mark[k]=1;
}
for(i=0;i<=SSS;i++)
{j=rak[i];
printf("%s %s %s %3.1f %3.1f %3.1f\n",stu[j].id,stu[j].clas,stu[j].name,stu[j].score1,stu[j].score2,stu[j].score3);
}}
void out(struct stud stu[10],int n[1])
{int i,j;
for(i=0;i<=SSS;i++)
{j=rak[i];printf("%s %s %s %3.1f %3.1f %3.1f\n",stu[j].id,stu[j].clas,stu[j].name,stu[j].score1,stu[j].score2,stu[j].score3);}}