diff --git a/task7.cpp b/task7.cpp new file mode 100644 index 0000000..5397499 --- /dev/null +++ b/task7.cpp @@ -0,0 +1,276 @@ +#include +#include + +#define MARK 10 +int input=0; +char range[17]; +//定义结构体 +struct Student +{ + int ID;//学号 + int classes; + char name[8]; + float math_grade; + float physics_grade; + float English_grade; + float sum; +}; + +int pow10(int M) +{ + int num=1; + for(int i=1;i<=M;i++) + { + num*=10; + } + + return num; +} + +//对结构体中的从start同学到end同学排序 +void Sort(struct Student information[8],int start,int end) +{ + //先班级 + for(int i=start;i<=end;i++) + { + for(int j=start;j<=end-1;j++) + { + if(information[j].classes>information[j+1].classes) + { + struct Student tmp=information[j]; + information[j]=information[j+1]; + information[j+1]=tmp; + } + } + } + //同班同学再成绩 + for(int i=start;i<=end;i++) + { + int con=0;//记录连续了几人 + for(int j=1;j<=end-i;j++) + { + if(information[i].classes==information[i+j].classes) + {con=j; + } + else + { + break; + } + } + + if(con)//有人是同班同学,在此内排序 + { + for(int m=i;m<=i+con;m++) + { + for(int n=i;n<=i+con-1;n++) + { + if(information[n].sum=start) + { + new_information[j]=information[i]; + j++;//最后会有j个被选入 + } + } //筛选出了所有学生 + + //排序 + Sort(new_information,0,j-1); + output(new_information,0,j-1); + } + else if(input==2) + { + int start=0;int end=0; + start=10000*(range[0]-'0')+1000*(range[1]-'0')+100*(range[2]-'0')\ + +10*(range[3]-'0')+(range[4]-'0'); + end=10000*(range[6]-'0')+1000*(range[7]-'0')+100*(range[8]-'0')\ + +10*(range[9]-'0')+(range[10]-'0'); + int i=0;int j=0; + for(int i=0;i<=6;i++) + { + if(information[i].ID<=end&&information[i].ID>=start) + { + new_information[j]=information[i]; + j++;//最后会有j个被选入 + } + } //筛选出了所有学生 + + //排序 + Sort(new_information,0,j-1); + output(new_information,0,j-1); + } + else if(input==3) + { + int j=0; + + for(int i=0;i<=6;i++) + { + int judge=1;//判断是否缩写吻合的标志 + for(int k=0;range[k]!='*';k++) + { + if(information[i].name[k]!=range[k]) + { + judge=0; + break; + } + } + if(judge) + { + new_information[j]=information[i]; + j++;//最后会有j个被选入 + } + } //筛选出了所有学生 + + //排序 + Sort(new_information,0,j-1); + output(new_information,0,j-1); + } + else if(input==4) + { + float sum = 0.0; + int a = 0; //a是整数的有几位,也是小数点在字符串的位置 + for (int i = 0; range[i] != '\0'; i++) + { + if (range[i] != '.') + { + a++; + } + else + { + break; + } + } + //计算sum + for (int i = 0; range[i] != '\0'; i++) + { + if (ia) + { + sum += 1.0 / pow10( i - a) * (range[i] - '0'); + } + } + + int j=0; + for(int i=0;i<=6;i++) + { + if(information[i].sum>=sum) + { + new_information[j]=information[i]; + j++;//最后会有j个被选入 + } + } //筛选出了所有学生 + + //排序 + Sort(new_information,0,j-1); + output(new_information,0,j-1); + } + else if(input==5) + { + int classes=10*(range[0]-'0')+(range[1]-'0'); + int start=10000*(range[3]-'0')+1000*(range[4]-'0')\ + +100*(range[5]-'0')+10*(range[6]-'0')+(range[7]-'0');; + int end=10000*(range[9]-'0')+1000*(range[10]-'0')\ + +100*(range[11]-'0')+10*(range[12]-'0')+(range[13]-'0');; + + int j=0; + for(int i=0;i<=6;i++) + { + if(information[i].classes==classes&&\ + information[i].ID<=end&&information[i].ID>=start) + { + new_information[j]=information[i]; + j++;//最后会有j个被选入 + } + } //筛选出了所有学生 + + //排序 + Sort(new_information,0,j-1); + output(new_information,0,j-1); + } + else + { + printf("请用正确的格式输入查询\n"); + } +} + +