operations.c

main
pywuc6np9 1 year ago
parent 3c6597c8d6
commit 0a96083bab

@ -94,48 +94,84 @@ void cancel(ss*stu){
//修改学生信息 //修改学生信息
void ModifyInfo(ss *stu) void ModifyInfo(ss *stu)
{ {
int len = stu->nums; char tmp[5];
Student new_stu_info; do {
scanf("%s%s%s%lf%lf%lf", &new_stu_info.id, &new_stu_info.clas, &new_stu_info.name, &new_stu_info.score1, &new_stu_info.score2, &new_stu_info.score3); int len = stu->nums;
for (int i = 0; i < len; i++) { Student* new_stu_info = newStudent();
if (strcmp(new_stu_info.id, stu->student[i].id) == 0) {
stu->student[i] = new_stu_info; printf("Id ");
} scanf("%s", new_stu_info->id);
} printf("\n");
char *max = malloc(sizeof(char)*20), *min = malloc(sizeof(char)*20);
strcpy(max, stu->student[0].clas); printf("class ");
strcpy(min, stu->student[0].clas); scanf(" %s", new_stu_info->clas);
for (int i = 0; i < len; i++) { printf("\n");
if (stu->student[i].clas > max) {
strcpy(max, stu->student[i].clas); printf("name ");
} scanf(" %s", new_stu_info->name);
if (stu->student[i].clas < min) { printf("\n");
strcpy(min, stu->student[i].clas);
} printf("score1 ");
} scanf("%lf", &new_stu_info->score1);
int i = 0, flag = 0; printf("\n");
while (strcmp(min, max) != 1) {
while (i < len && strcmp(min, stu->student[i++].clas) == 0) { printf("score2 ");
if (flag == 1) { scanf("%lf", &new_stu_info->score2);
if (strcmp(stu->student[i].id, new_stu_info.id) == 0) { printf("\n");
printf(" %s %s %lf %lf %lf modified\n", stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
else
printf(" %s %s %lf %lf %lf\n", stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
else {
flag = 1;
if (strcmp(stu->student[i].id, new_stu_info.id) == 0) {
printf("%s %s %s %lf %lf %lf modified\n", stu->student[i].clas, stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
else
printf("%s %s %s %lf %lf %lf modified\n", stu->student[i].clas, stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
}
min = min + 1;
}
}
printf("score3 ");
scanf("%lf", &new_stu_info->score3);
printf("\n");
for (int i = 0; i < len; i++) {
if (strcmp(new_stu_info->id, stu->student[i].id) == 0) {
stu->student[i] = new_stu_info[0];
stu->student[i].score = stu->student[i].score1 + stu->student[i].score2 + stu->student[i].score3;
}
}
char* max = malloc(sizeof(char) * 4), * min = malloc(sizeof(char) * 4);
strcpy(max, stu->student[0].clas);
strcpy(min, stu->student[0].clas);
for (int i = 0; i < len; i++) {
if (strcmp(stu->student[i].clas , max)>0) {
strcpy(max, stu->student[i].clas);
}
if (strcmp(stu->student[i].clas , min)<0) {
strcpy(min, stu->student[i].clas);
}
}
int i = 0, flag = 0;
do {
while (i < len && strcmp(min, stu->student[i].clas) == 0) {
if (flag == 1) {
if (strcmp(stu->student[i].id, new_stu_info->id) == 0) {
printf(" %s %s %.1lf %.1lf %.1lf modified\n", stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
else
printf(" %s %s %.1lf %.1lf %.1lf\n", stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
else {
flag = 1;
if (strcmp(stu->student[i].id, new_stu_info->id) == 0) {
printf("%s %s %s %.1lf %.1lf %.1lf modified\n", stu->student[i].clas, stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
else
printf("%s %s %s %.1lf %.1lf %.1lf\n", stu->student[i].clas, stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
}
i++;
}
int class = atoi(min);
class++;
itoa(class,min,10);
} while (strcmp(max, min) >= 0);
printf("continue?\n");
scanf("%s", tmp);
}while (!strcmp(tmp, "yes"));
return;
}
//排序 //排序
void Order(ss *stu){ void Order(ss *stu){
for(int i=0;i<stu->nums;i++){ for(int i=0;i<stu->nums;i++){

Loading…
Cancel
Save