diff --git a/1到6问(这里main函数是第6问,看其他问需要稍改动main函数).c b/1到6问(这里main函数是第6问,看其他问需要稍改动main函数).c new file mode 100644 index 0000000..7ad9a5c --- /dev/null +++ b/1到6问(这里main函数是第6问,看其他问需要稍改动main函数).c @@ -0,0 +1,239 @@ +#include +#include +struct student +{ + char num[10]; + float Math; + float Physic; + float English; + float sum; + float ave; + int class; + int inserted;//sign whether the student is inserted + char name[10]; + int mod;//sign whether the student is modified +}; +void menu()// print menu +{ + for(int i=0;i<30;i++) + printf(" "); + printf("1.Input\n"); + for(int i=0;i<30;i++) + printf(" "); + printf("2.Output\n"); + for(int i=0;i<30;i++) + printf(" "); + printf("3.Order\n"); + for(int i=0;i<30;i++) + printf(" "); + printf("4.Quit\n"); +} +void OSmenu(char x)// operation on menu +{ + if(x=='i') + printf("You are trying to Input info\n"); + else if(x=='o') + printf("You are trying to Output info\n"); + else if(x=='m') + printf("You are trying to Make things ordered\n"); + else if(x=='q') + printf("You are about to Quit\n"); + else + printf("Wrong input\n"); +} +void inputstudent(struct student *t)//input info without class +{ + scanf("%s %f %f %f",&(t->num),&(t->Math),&(t->Physic),&(t->English)); + t->sum=t->Math+t->Physic+t->English; + t->ave=t->sum/3; + t->inserted=0; + t->mod=0; +} +void inputstudent2(struct student *t)//input info with class +{ + scanf("%s %d %f %f %f",&(t->num),&(t->class),&(t->Math),&(t->Physic),&(t->English)); + t->sum=t->Math+t->Physic+t->English; + t->ave=t->sum/3; + t->inserted=0; + t->mod=0; +} +void inputstudent3(struct student *t)//input info with class name +{ + scanf("%s %d %s %f %f %f",&(t->num),&(t->class),&(t->name),&(t->Math),&(t->Physic),&(t->English)); + t->sum=t->Math+t->Physic+t->English; + t->ave=t->sum/3; + t->inserted=0; + t->mod=0; +} +void insertstudent(struct student *t)//insert student +{ + scanf("%s %d %f %f %f",&(t->num),&(t->class),&(t->Math),&(t->Physic),&(t->English)); + t->sum=t->Math+t->Physic+t->English; + t->ave=t->sum/3; + t->inserted=1; +} +void outputstudent1(struct student *t)// output num and grade of all subject +{ + printf("%s %.1f %.1f %.1f %.1f\n",t->num,t->Math,t->Physic,t->English,t->sum); +} +void outputstudent2(struct student *t)// output num,sum and ave +{ + printf("%s %.1f %.1f\n",t->num,t->sum,t->ave); +} +void outputstudent3(struct student *t)// output num,class,whether inserted and grade of all subject +{ + if(t->inserted==0) + printf("%s %d %.1f %.1f %.1f\n",t->num,t->class,t->Math,t->Physic,t->English); + else + printf("%s %d %.1f %.1f %.1f inserted\n",t->num,t->class,t->Math,t->Physic,t->English); +} +void outputstudent4(struct student *t)// output num,class,name,and grade of all subject +{ + printf("%s %s %d %.1f %.1f %.1f\n",t->num,t->name,t->class,t->Math,t->Physic,t->English); +} +void outputstudent5(struct student*t)//output info by class +{ + for(int i=0;i<3;i++) + { + if(i==0||(t+i)->class!=(t+i-1)->class) + { + if((t+i)->mod==1) + printf("%d %s %s %.1f %.1f %.1f modified\n",(t+i)->class,(t+i)->num,(t+i)->name,(t+i)->Math,(t+i)->Physic,(t+i)->English); + else + printf("%d %s %s %.1f %.1f %.1f\n",(t+i)->class,(t+i)->num,(t+i)->name,(t+i)->Math,(t+i)->Physic,(t+i)->English); + } + else + { + if((t+i)->mod==1) + printf(" %s %s %.1f %.1f %.1f modified\n",(t+i)->num,(t+i)->name,(t+i)->Math,(t+i)->Physic,(t+i)->English); + else + printf(" %s %s %.1f %.1f %.1f\n",(t+i)->num,(t+i)->name,(t+i)->Math,(t+i)->Physic,(t+i)->English); + } + } +} +void orderstudent(struct student *t,int n)//order without class +{ + for(int i=0;isum>(t+j)->sum) + { + struct student m; + m=*(t+i); + *(t+i)=*(t+j); + *(t+j)=m; + } + } + } +} +void orderstudent2(struct student *t,int n)//order with class +{ + for(int i=0;iclass>(t+j)->class) + { + struct student m; + m=*(t+i); + *(t+i)=*(t+j); + *(t+j)=m; + } + } + } + for(int i=0;iclass==(t+j)->class&&(t+i)->sum<(t+j)->sum) + { + struct student m; + m=*(t+i); + *(t+i)=*(t+j); + *(t+j)=m; + } + } + } +} +void removestudent(struct student *t)//remove student(num or name) +{ + for(int i=0;i<3;i++) + outputstudent4(t+i); + char re[10]; + char p; + scanf("%s",re); + for(int i=0;i<3;i++) + { + if(strcmp((t+i)->num,re)!=0&&strcmp((t+i)->name,re)!=0) + { + outputstudent4(t+i); + } + } + printf("Are you sure(yes/no)?\n"); + scanf("%c",&p); + scanf("%c",&p); + if(p=='n') + { + for(int i=0;i<3;i++) + outputstudent4(t+i); + } + else + { + for(int i=0;i<3;i++) + { + if(strcmp((t+i)->num,re)==0||strcmp((t+i)->name,re)==0) + { + for(int j=i;j<2;j++) + { + *(t+j)=*(t+j+1); + } + } + } + } +} +void modstudent(struct student *t)//mod info according to num +{ + struct student f; + inputstudent3(&f); + for(int i=0;i<3;i++) + { + if(strcmp((t+i)->num,f.num)==0) + { + *(t+i)=f; + (t+i)->mod=1; + } + } +} +int main() +{ + struct student s[10]; + strcpy(s[0].num,"10001"); + strcpy(s[0].name,"Zhang"); + s[0].class=11; + s[0].Math=99.5; + s[0].Physic=88.5; + s[0].English=89.5; + s[0].sum=s[0].Math+s[0].Physic+s[0].English; + s[0].inserted=0; + strcpy(s[1].num,"10002"); + strcpy(s[1].name,"Yang"); + s[1].class=12; + s[1].Math=77.9; + s[1].Physic=56.5; + s[1].English=87.5; + s[1].sum=s[1].Math+s[1].Physic+s[1].English; + s[1].inserted=0; + strcpy(s[2].num,"10003"); + strcpy(s[2].name,"Liang"); + s[2].class=11; + s[2].Math=92.5; + s[2].Physic=99.0; + s[2].English=60.5; + s[2].sum=s[2].Math+s[2].Physic+s[2].English; + s[2].inserted=0; + orderstudent2(&s[0],3); + modstudent(&s[0]); + outputstudent5(&s[0]); + return 0; +} \ No newline at end of file