diff --git a/8.c b/8.c new file mode 100644 index 0000000..dc7e8bf --- /dev/null +++ b/8.c @@ -0,0 +1,168 @@ +#include +#include +#define N 100 + +struct stu_info +{ + char num[20]; + char cls[20]; + char name[20]; + float math,physics,english,total; +}; + +struct stu_info stu[N]; +int top=0; + +void print_menu() +{ + printf("1.input\n"); + printf("2.delete\n"); + printf("3.select\n"); + printf("4.order\n"); + printf("5.output\n"); + printf("6.quit\n"); + printf("please input your option\n"); +} + +void print() +{ + int i; + for(i=0;inum,key)==0||strcmp((stu+i)->name,key)==0) + { + d++;top--; + *(stu+i)=*(stu+i+d); + } + else + { + *(stu+i)=*(stu+i+d); + i++; + } + } + print(); + printf("continue?\n"); + do{ + scanf("%s",op); + }while(strcmp(op,"yes")!=0&&strcmp(op,"no")!=0); + if(strcmp(op,"no")==0) return; + } +} + +void select() +{ + int i,flag; + char key[20],op[20]; + while(1) + { + flag=0; + scanf("%s",key); + for(i=0;inum,key)==0||strcmp((stu+i)->cls,key)==0) + { + flag=1; + printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",stu[i].num,stu[i].cls,stu[i].name,stu[i].math,stu[i].physics,stu[i].english,stu[i].total); + } + } + if(!flag) + { + printf("there is no eligible student\n"); + return; + } + printf("continue?\n"); + do{ + scanf("%s",op); + }while(strcmp(op,"yes")!=0&&strcmp(op,"no")!=0); + if(strcmp(op,"no")==0) return; + } +} + +void order() +{ + int i,j; + struct stu_info tmp; + for(i=0;icls,(stu+j+1)->cls)==1||strcmp((stu+j)->cls,(stu+j+1)->cls)==0&&((stu+j)->total<(stu+j+1)->total)) + { + tmp = *(stu+j); + *(stu+j) = *(stu+j+1); + *(stu+j+1) = tmp; + } + } + } + print(); + return; +} + +int main() +{ + int op; + while(1) + { + print_menu(); + scanf("%d",&op); + switch(op) + { + case(1): + input(); + break; + case(2): + del(); + break; + case(3): + select(); + break; + case(4): + order(); + break; + case(5): + print(); + break; + case(6): + return 0; + } + } +} +