diff --git a/step8.cpp b/step8.cpp new file mode 100644 index 0000000..6569c29 --- /dev/null +++ b/step8.cpp @@ -0,0 +1,140 @@ +#include +#include +struct Message +{ + char Id[6]; + char clas[3]; + char name[10]; + double score1; + double score2; + double score3; + double score; +}student[10]; +int sum=0; +int main(){ + void MENU(); + void INPUT(int i); + void DELETE(); + void SELECT(); + void SORT(); + void PRINT(int sum); + int choose; + MENU(); + scanf("%d",&choose); + while(choose!=6){ + MENU(); + if(choose==1){ + INPUT(0); + } + else if(choose==2){ + DELETE(); + } + else if(choose==3){ + SELECT(); + } + else if(choose==4){ + SORT(); + } + else { + PRINT(sum); + } + scanf("%d",&choose); + } +} +void MENU(){ + printf("1.input\n2.delete\n3.select\n4.order\n5.output\n6.quit\n"); + printf("please input your option\n"); +} +void PRINT(int sum){ + int i; + for(i=0;i<=sum;i++){ + printf("%s,%s,%s,%.1lf,%.1lf,%.1lf,%.1lf\n",student[i].Id,student[i].clas,student[i].name,student[i].score1,student[i].score2,student[i].score3,student[i].score); + } +} +int RESPONSE(){ + printf("continue?\n"); + char approve[5]="yes"; + char response[5]; + scanf("%s",response); + if(strcmp(response,approve)==0) + return 1; + else + return 0; +} +int INPUT(int i){ + printf("Id "); + scanf("%s",student[i].Id); + printf("class "); + scanf("%s",student[i].clas); + printf("name "); + scanf("%s",student[i].name); + printf("score1 "); + scanf("%lf",&student[i].score1); + printf("score2 "); + scanf("%lf",&student[i].score2); + printf("score3 "); + scanf("%lf",&student[i].score3); + int word=RESPONSE(); + if(word){ + sum++; + INPUT(i+1); + } + student[i].score=student[i].score1+student[i].score2+student[i].score3; + return 0; +} +void DELETE(){ + char input[10]; + int i,t=0; + scanf("%s",input); + for(i=0;i<=sum;i++){ + if(strcmp(student[i].Id,input)==0||strcmp(student[i].name,input)==0){ + t=1; + break; + } + } + if(t==0){ + PRINT(sum); + } + else{ + while(i0){ + struct Message temp; + temp=student[j];student[j]=student[j+1];student[j+1]=temp; + } + else if(strcmp(student[j].clas,student[j+1].clas)==0&&student[j].score