From 9e6d2ca82e4ebc508c7183dc52fd438954c99e98 Mon Sep 17 00:00:00 2001 From: pfwtzfkoe <3296553455@qq.com> Date: Sun, 12 Nov 2023 23:06:53 +0800 Subject: [PATCH] ADD file via upload --- xuejixitong-lianbiao.c | 151 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 xuejixitong-lianbiao.c diff --git a/xuejixitong-lianbiao.c b/xuejixitong-lianbiao.c new file mode 100644 index 0000000..2054c6b --- /dev/null +++ b/xuejixitong-lianbiao.c @@ -0,0 +1,151 @@ +#include +#include +#include + +typedef struct Student { + char id[20]; + char classname[20]; + char name[20]; + float score1, score2, score3; + struct Student* next; +} Student; + +Student* head = NULL; // 头节点指针 + +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() { + Student* newStudent = (Student*)malloc(sizeof(Student)); + printf("ID: "); + scanf("%s", newStudent->id); + printf("class: "); + scanf("%s", newStudent->class); + printf("name: "); + scanf("%s", newStudent->name); + printf("score1: "); + scanf("%f", &newStudent->score1); + printf("score2: "); + scanf("%f", &newStudent->score2); + printf("score3: "); + scanf("%f", &newStudent->score3); + newStudent->next = head; + head = newStudent; +} + +void deleteStudent() { + char idOrName[20]; + scanf("%s", idOrName); + Student* current = head; + Student* prev = NULL; + while (current != NULL) { + if (strcmp(current->id, idOrName) == 0 || strcmp(current->name, idOrName) == 0) { + if (prev == NULL) { + head = current->next; + } else { + prev->next = current->next; + } + free(current); + break; + } + prev = current; + current = current->next; + } + printStudent(); +} + +void selectStudent() { + char idOrName[20]; + scanf("%s", idOrName); + Student* current = head; + int found = 0; + while (current != NULL) { + if (strcmp(current->id, idOrName) == 0 || strcmp(current->name, idOrName) == 0) { + printf("%s %s %s %.1f %.1f %.1f\n", current->id, current->class, current->name, current->score1, current->score2, current->score3); + found = 1; + } + current = current->next; + } + if (found == 0) { + printf("There is no eligible student\n"); + } +} + +void orderStudent() { + // 省略排序功能的具体实现 +} + +void printStudent() { + Student* current = head; + while (current != NULL) { + printf("%s %s %s %.1f %.1f %.1f\n", current->id, current->class, current->name, current->score1, current->score2, current->score3); + current = current->next; + } +} + +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; + } + } +} + +