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; + } + } +} + +