diff --git a/README.md b/README.md index 02615d7..1af57ae 100644 --- a/README.md +++ b/README.md @@ -22,38 +22,21 @@ int main() } 步骤2 -#include - +#include int main() { - struct student + int num[3]; + float math[3],physic[3],english[3],sum[3]; + int i; + for(i=0;i<3;i++) { - int number; - float gaoshu; - float dawu; - float yy; - float add; - }student1, student2, student3; - scanf("%d",&student1.number); -scanf("%f",&student1.gaoshu); -scanf("%f",&student1.dawu); -scanf("%f",&student1.yy); -scanf("%d",&student2.number); -scanf("%f",&student2.gaoshu); -scanf("%f",&student2.dawu); -scanf("%f",&student2.yy); -scanf("%d",&student3.number); -scanf("%f",&student3.gaoshu); -scanf("%f",&student3.dawu); -scanf("%f",&student3.yy); - student1.add = (student1.gaoshu + student1.dawu + student1.yy); - student2.add = (student2.gaoshu + student2.dawu + student2.yy); - student3.add = (student3.gaoshu + student3.dawu + student3.yy); - printf("%d %f %f %f %f\n", student1.number, student1.gaoshu, student1.dawu, student1.yy, student1.add); - -printf("%d %f %f %f %f\n", student2.number, student2.gaoshu, student2.dawu, student2.yy, student2.add); - -printf("%d %f %f %f %f\n", student3.number, student3.gaoshu, student3.dawu, student3.yy, student3.add); + scanf("%d %f %f %f",&num[i],&math[i],&physic[i],&english[i]); + sum[i]=math[i]+physic[i]+english[i]; + } + for(i=0;i<3;i++) + { + printf("%d %.1f %.1f %.1f %.1f\n",num[i],math[i],physic[i],english[i],sum[i]); + } } 步骤3 int main() @@ -482,176 +465,172 @@ scanf("%d",&changer1); } 步骤八 #include -struct student{ - int id; - int class; +#include +#define N 100 + +struct stu_info +{ + char num[20]; + char cls[20]; char name[20]; - double score1; - double score2; - double score3; - double score; -}stu[7]; -void xunwen(void){ + float math,physics,english,total; +}; + +struct stu_info stu[N]; +int top=0; + +void print_menu() +{ printf("1.input\n"); - printf("2.delet\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 input(void){ - int i,j; - char str[3]; - void zhixing(void); - for(i=0;i<7;i++){ - printf("id "); - scanf("%d",&stu[i].id); - printf("class "); - scanf("%d",&stu[i].class); - 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"); - scanf("%s",str); - if(str[0]=='y') - continue; - else if(str[0]=='n') - break; - else - return; - } - for(i=0;i<7;i++){ - stu[i].score=stu[i].score1+stu[i].score2+stu[i].score3; - } - xunwen(); - zhixing(); -} -void delet(struct student stu4[]){ - void xunwen(void); - void zhixing(void); - int i,j,k,a,b,c; - char str[3]; - scanf("%d",&a); - for(i=0;i<7;i++){ - if(stu[i].id==a){ - stu[i].id=0; - } - } - for(i=0;i<7;i++){ - if(stu[i].id!=0) - printf("%d %d %s %.1f %.1f %.1f %.1f %.1f\n",stu[i].id,stu[i].class,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score); - } - printf("continue?\n"); - struct student *p=stu; - scanf("%s",str); - if(str[0]=='y') - delet(p); - else if(str[0]=='n') - xunwen(); - zhixing(); + +void print() +{ + int i; + for(i=0;i100){ - for(i=0;i<7;i++){ - if(stu7[i].id==a) - printf("%d %d %s %.1f %.1f %.1f %.1f\n",stu[i].id,stu[i].class,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score); - c=0; - } - } - else if(a<100){ - for(i=0;i<7;i++){ - if(stu7[i].class==a){ - printf("%d %d %s %.1f %.1f %.1f %.1f\n",stu[i].id,stu[i].class,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score); - c=0; - } - } - } - if(c==1) - printf("there is no eligible student"); - printf("continue?\n"); - struct student *p=stu; - scanf("%s",str); - if(str[0]=='y'){ - select(p); - } - else if(str[0]=='n'){ - xunwen(); - zhixing(); - } + +void input() +{ + char op[20]; + while(1) + { + printf("Id "); + scanf("%s",stu[top].num); + printf("class "); + scanf("%s",&stu[top].cls); + printf("name "); + scanf("%s",stu[top].name); + printf("score1 "); + scanf("%f",&stu[top].math); + printf("score2 "); + scanf("%f",&stu[top].physics); + printf("score3 "); + scanf("%f",&stu[top].english); + stu[top].total=stu[top].math+stu[top].physics+stu[top].english; + top++; + printf("continue?\n"); + do{ + scanf("%s",op); + }while(strcmp(op,"yes")!=0&&strcmp(op,"no")!=0); + if(strcmp(op,"no")==0) return; + } } -void order(struct student stu2[]){ - void zhixing(void); - void output(void); - int i,j,k=0,a,b,c; - struct student temp; - struct student stu1[7]; - for(i=0;i<7;i++){ - stu1[i]=stu2[i]; - } - for(i=0;i<6;i++){ - for(j=i+1;j<7;j++){ - if(stu1[j].score>=stu1[i].score){ - temp=stu1[i]; - stu1[i]=stu1[j]; - stu1[j]=temp; - } - } - } - for(i=1;i<30;i++){ - for(j=0;j<7;j++){ - if(stu1[j].class==i) - stu2[k++]=stu1[j]; - } - } - for(i=0;i<7;i++){ - if(stu[i].id!=0){ - printf("%d %s %d %.1f %.1f %.1f",stu[i].id,stu[i].class,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3); - } - } - xunwen(); - zhixing(); + +void del() +{ + int i,d; + char key[20],op[20]; + while(1) + { + i=0,d=0; + scanf("%s",key); + while(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 output(){ - void zhixing(void); - int i; - for(i=0;i<7;i++){ - if(stu[i].id!=0) - printf("%d %d %s %.1f %.1f %.1f %.1f\n",stu[i].id,stu[i].class,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score); + +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; } - xunwen(); - zhixing(); } -void quit(void){ - return; -} -void zhixing(void){ - int i; - scanf("%d",&i); - struct student *p=stu; - switch(i){ - case 1:input();break; - case 2:delet(p);break; - case 3:select(p);break; - case 4:order(p);break; - case 5:output();break; - case 6:quit();break; + +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(){ - xunwen(); - zhixing(); - return 0; + +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; + } + } } +