operations.c

main
pywuc6np9 1 year ago
parent 3c6597c8d6
commit 0a96083bab

@ -94,48 +94,84 @@ void cancel(ss*stu){
//修改学生信息
void ModifyInfo(ss *stu)
{
char tmp[5];
do {
int len = stu->nums;
Student new_stu_info;
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);
Student* new_stu_info = newStudent();
printf("Id ");
scanf("%s", new_stu_info->id);
printf("\n");
printf("class ");
scanf(" %s", new_stu_info->clas);
printf("\n");
printf("name ");
scanf(" %s", new_stu_info->name);
printf("\n");
printf("score1 ");
scanf("%lf", &new_stu_info->score1);
printf("\n");
printf("score2 ");
scanf("%lf", &new_stu_info->score2);
printf("\n");
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;
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)*20), *min = malloc(sizeof(char)*20);
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 (stu->student[i].clas > max) {
if (strcmp(stu->student[i].clas , max)>0) {
strcpy(max, stu->student[i].clas);
}
if (stu->student[i].clas < min) {
if (strcmp(stu->student[i].clas , min)<0) {
strcpy(min, stu->student[i].clas);
}
}
int i = 0, flag = 0;
while (strcmp(min, max) != 1) {
while (i < len && strcmp(min, stu->student[i++].clas) == 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 %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);
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 %lf %lf %lf\n", stu->student[i].id, stu->student[i].name, stu->student[i].score1, stu->student[i].score2, stu->student[i].score3);
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 %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);
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 %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);
}
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);
}
min = min + 1;
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){
for(int i=0;i<stu->nums;i++){

Loading…
Cancel
Save