From a30e14e5e74a68f0f734a9a89078dc60b83fbe57 Mon Sep 17 00:00:00 2001 From: pfwtzfkoe <3296553455@qq.com> Date: Sun, 12 Nov 2023 23:06:44 +0800 Subject: [PATCH] ADD file via upload --- 8-final vision.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 8-final vision.c diff --git a/8-final vision.c b/8-final vision.c new file mode 100644 index 0000000..7697e95 --- /dev/null +++ b/8-final vision.c @@ -0,0 +1,176 @@ +#include +#include +#define MAX_STUDENTS 100 +typedef struct +{ + char id[20]; + char class[20]; + char name[20]; + float score1, score2, score3; +} Student; +int numStudents=0; // 记录当前学生的数量 +Student students[MAX_STUDENTS]; +void showMenu() +{ + printf("%30s1.input\n", " "); + printf("%30s2.delete\n", " "); + printf("%30s3.select\n", " "); + printf("%30s4.order\n", " "); + printf("%30s5.output\n", " "); + printf("%30s6.quit\n", " "); + printf("%30splease input your option\n", " "); + +} +void insertStudent() +{ + + printf("ID "); + scanf("%s", students[numStudents].id); + printf("class: "); + scanf("%s", &(students[numStudents].class)); + printf("name: "); + scanf("%s", students[numStudents].name); + printf("score1: "); + scanf("%f", &(students[numStudents].score1)); + printf("score2: "); + scanf("%f", &(students[numStudents].score2)); + printf("score3: "); + scanf("%f", &(students[numStudents].score3)); + numStudents++; +} + +void deleteStudent() +{ + char idOrName[20]; + scanf("%s", idOrName); + int i, j; + int found = 0; + for (i = 0; i < numStudents; i++) + { + if (strcmp(students[i].id, idOrName) == 0 || strcmp(students[i].name, idOrName) == 0) + { + found = 1; + for (j = i; j < numStudents - 1; j++) + { + students[j] = students[j + 1]; + } + numStudents--; + break; + } + } + for ( i = 0; i < numStudents; i++) + { + printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].class, students[i].name, students[i].score1, students[i].score2, students[i].score3); + } +} +void selectStudent() +{ + char idOrName[20]; + scanf("%s", idOrName); + int i,j; + int f=0; + for (i = 0; i < numStudents; i++) + { + if (strcmp(students[i].id, idOrName) == 0 || strcmp(students[i].name, idOrName) == 0) + { + f=1; + printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].class, students[i].name, students[i].score1, students[i].score2, students[i].score3); + } + } + if(f==0) printf("there is no eligible student\n"); +} + +void orderStudent() +{ + int i,j; + for (i = 0; i < numStudents; i++) + { + for (j=i+1;j students[j].class || (students[i].class == students[j].class && students[i].score1 + students[i].score2 + students[i].score3 < students[j].score1 + students[j].score2 + students[j].score3)) + { + Student temp = students[j]; + students[j] = students[i]; + students[i] = temp; + } + } + } + for ( i = 0; i < numStudents; i++) + { + printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].class, students[i].name, students[i].score1, students[i].score2, students[i].score3); + } +} +void printStudent() +{ + int i=0; + for (i = 0; i < numStudents; i++) + { + printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].class, students[i].name, students[i].score1, students[i].score2, students[i].score3); + } +} + +int main() +{ + int choice; + char a[4]; + while (1) + { + showMenu(); + scanf("%d", &choice); + switch (choice) + { + case 1: + insertStudent(); + while(1) + { + printf("continue?\n"); + scanf("%s",&a); + if(strcmp(a,"yes")==0) + { + insertStudent(); + continue; + } + else break; + } + break; + case 2: + deleteStudent(); + while(1) + { + printf("continue?\n"); + scanf("%s",&a); + if(strcmp(a,"yes")==0) + { + deleteStudent(); + continue; + } + else break; + } + break; + case 3: + selectStudent(); + while(1) + { + printf("continue?\n"); + scanf("%s",&a); + if(strcmp(a,"yes")==0) + { + selectStudent(); + continue; + } + else break; + } + break; + case 4: + orderStudent(); + break; + case 5: + printStudent(); + break; + case 6: + return 0; + } + //showMenu(); + } +} +