From 022a3cd4fd368c3ca29b6a0fd210e617dae9935a Mon Sep 17 00:00:00 2001 From: pr9nfksyw Date: Thu, 21 Nov 2024 00:55:16 +0800 Subject: [PATCH] ADD file via upload --- order_other_opinion.c | 131 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 order_other_opinion.c diff --git a/order_other_opinion.c b/order_other_opinion.c new file mode 100644 index 0000000..cf5af92 --- /dev/null +++ b/order_other_opinion.c @@ -0,0 +1,131 @@ +#include +#include +#include +#include +#include +#include "menu.h" + +void insertStudentInfo(Student students[], int* count) { + if (*count >= MAX_STUDENTS) { + printf("学生已满,无法添加新学生。\n"); + return; + } + + Student newStudent; + int validInput; + + do { + validInput = 1; + printf("Id: "); + scanf_s("%9s", newStudent.id, (unsigned)_countof(newStudent.id)); + + // 验证学号是否只由数字组成 + for (int i = 0; i < strlen(newStudent.id); i++) { + if (!isdigit(newStudent.id[i])) { + validInput = 0; + break; + } + } + + if (!validInput) { + printf("学号只能由数字组成,请重新输入。\n"); + } + } while (!validInput); + + printf("Class: "); + scanf_s("%9s", newStudent.clas, (unsigned)_countof(newStudent.clas)); + printf("Name: "); + scanf_s("%9s", newStudent.name, (unsigned)_countof(newStudent.name)); + printf("Score1: "); + scanf_s("%lf", &newStudent.score1); + printf("Score2: "); + scanf_s("%lf", &newStudent.score2); + printf("Score3: "); + scanf_s("%lf", &newStudent.score3); + + newStudent.score = newStudent.score1 + newStudent.score2 + newStudent.score3; + + int i = *count; + while (i > 0 && (strcmp(students[i - 1].clas, newStudent.clas) > 0 || + (strcmp(students[i - 1].clas, newStudent.clas) == 0 && students[i - 1].score < newStudent.score))) { + students[i] = students[i - 1]; + i--; + } + students[i] = newStudent; + (*count)++; +} +void deleteStudentInfo(Student students[], int* count) { + char input[20]; + printf("Enter the student ID or name to delete: "); + scanf_s("%19s", input, (unsigned)_countof(input)); + + int i = 0; + while (i < *count && (strcmp(students[i].id, input) != 0 && strcmp(students[i].name, input) != 0)) { + i++; + } + + if (i == *count) { + printf("Student not found.\n"); + } + else { + for (int j = i; j < *count - 1; j++) { + students[j] = students[j + 1]; + } + (*count)--; + printf("Student deleted successfully.\n"); + } +} + +void modifyStudentInfo(Student students[], int count) { + char input[20]; + printf("Enter the student ID to modify: "); + scanf_s("%19s", input, (unsigned)_countof(input)); + + int i = 0; + while (i < count && strcmp(students[i].id, input) != 0) { + i++; + } + + if (i == count) { + printf("Student not found.\n"); + } + else { + printf("Id: "); + scanf_s("%9s", students[i].id, (unsigned)_countof(students[i].id)); + printf("Class: "); + scanf_s("%9s", students[i].clas, (unsigned)_countof(students[i].clas)); + printf("Name: "); + scanf_s("%9s", students[i].name, (unsigned)_countof(students[i].name)); + printf("Score1: "); + scanf_s("%lf", &students[i].score1); + printf("Score2: "); + scanf_s("%lf", &students[i].score2); + printf("Score3: "); + scanf_s("%lf", &students[i].score3); + + students[i].score = students[i].score1 + students[i].score2 + students[i].score3; // Fixed here + printf("Student information updated successfully.\n"); + } +} + +void queryStudentInfo(Student students[], int count) { + char queryClass[MAX_STRING]; + printf("请输入要查询的班级: "); + scanf_s("%9s", queryClass, (unsigned)_countof(queryClass)); + + printf("查询结果:\n"); + for (int i = 0; i < count; i++) { + if (strcmp(students[i].clas, queryClass) == 0) { + printf("%s %s %s %.1lf %.1lf %.1lf %.1lf\n", students[i].id, students[i].clas, students[i].name, + students[i].score1, students[i].score2, students[i].score3, students[i].score); + } + } +} + + + + + + + +