From 13ada78c9a7cbf60821a79c5744daad97c02b754 Mon Sep 17 00:00:00 2001 From: pecp45i32 Date: Sat, 23 Nov 2024 06:54:13 +0800 Subject: [PATCH] ADD file via upload --- step6.cpp | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 step6.cpp diff --git a/step6.cpp b/step6.cpp new file mode 100644 index 0000000..4d541b3 --- /dev/null +++ b/step6.cpp @@ -0,0 +1,166 @@ +#include +#include +#include + +int studentMember = 0; + +typedef struct storeInformation +{ + char stus[10]; + int classes; + char names[10]; + double mathGrade; + double physicsGrade; + double englishGrade; + int boolNew; +} stu; + +stu studentInformation[10]; + +void input(int i) { + scanf("%s", studentInformation[i].stus); + scanf("%d", &studentInformation[i].classes); + scanf("%s", studentInformation[i].names); + scanf("%lf", &studentInformation[i].mathGrade); + scanf("%lf", &studentInformation[i].physicsGrade); + scanf("%lf", &studentInformation[i].englishGrade); +} + +void inputStudentInformation(int n) { + for (int i = 0; i < n; i++) { + input(i); + studentMember++; + studentInformation[i].boolNew = 0; + printf("One student has been input!\n"); + } +} + +void insertedNew() { + int i = studentMember; + input(i); + studentMember++; + studentInformation[i].boolNew = 1; + printf("One student has been input!\n"); +} + +void informationClear(char a[100]) { + int i = 0; + for (i = 0; i < studentMember; i++) { + if (strcmp(a, studentInformation[i].stus) == 0 || strcmp(a, studentInformation[i].names) == 0) { + memset(&studentInformation[i], 0, sizeof(studentInformation[i])); + } + } +} + +void sortStudents() { + for (int i = 0; i < studentMember - 1; i++) { + for (int j = 0; j < studentMember - i - 1; j++) { + double totalScoreJ = studentInformation[j].mathGrade + studentInformation[j].physicsGrade + studentInformation[j].englishGrade; + double totalScoreJ1 = studentInformation[j + 1].mathGrade + studentInformation[j + 1].physicsGrade + studentInformation[j + 1].englishGrade; + + if (studentInformation[j].classes > studentInformation[j + 1].classes || + (studentInformation[j].classes == studentInformation[j + 1].classes && totalScoreJ < totalScoreJ1)) { + stu temp = studentInformation[j]; + studentInformation[j] = studentInformation[j + 1]; + studentInformation[j + 1] = temp; + } + } + } + printf("Students have been sorted!\n"); +} + +void printStudentOriginalScore() { + sortStudents(); + int classs = 0; + for (int i = 0; i < studentMember; i++) { + if (studentInformation[i].classes != 0) { + if (studentInformation[i].classes == classs) { + printf("%d %s %s %.1f %.1f %.1f %s\n", + studentInformation[i].classes, + studentInformation[i].stus, + studentInformation[i].names, + studentInformation[i].mathGrade, + studentInformation[i].physicsGrade, + studentInformation[i].englishGrade, + studentInformation[i].boolNew == 0 ? "" : studentInformation[i].boolNew == 1 ? "inserted" : "modified"); + } + else { + printf(" %s %s %.1f %.1f %.1f %s\n", + studentInformation[i].stus, + studentInformation[i].names, + studentInformation[i].mathGrade, + studentInformation[i].physicsGrade, + studentInformation[i].englishGrade, + studentInformation[i].boolNew == 0 ? "" : studentInformation[i].boolNew == 1 ? "inserted" : "modified"); + } + classs = studentInformation[i].classes; + studentInformation[i].boolNew = 0; + } + } + +} + +void modifyStudent() { + char a[10]; + printf("Are you sure(yes/no)"); + scanf("%s", &a); + if ((strcmp(a, "yes")) == 0) { + char stusToModify[10]; + printf("Enter the student number to modify, followed by new data ( 10001 2 Kobe 59 59 59):\n"); + scanf("%s", stusToModify); + + int found = 0; + for (int i = 0; i < studentMember; i++) { + if (strcmp(studentInformation[i].stus, stusToModify) == 0) { + found = 1; + scanf("%d %s %lf %lf %lf", + &studentInformation[i].classes, + studentInformation[i].names, + &studentInformation[i].mathGrade, + &studentInformation[i].physicsGrade, + &studentInformation[i].englishGrade); + studentInformation[i].boolNew = 2; + printf("Student data modified successfully!\n"); + break; + } + } + if (!found) { + printf("Student with number %s not found.\n", stusToModify); + } + } +} + +void manage() { + printf(" 1.Input\n"); + printf(" 2.Output\n"); + printf(" 3.Order\n"); + printf(" 4.Quit\n"); + char keywords; + keywords = getchar(); + switch (keywords) { + case 'i': + printf("Please input info of the three students\n"); + inputStudentInformation(3); + break; + case 'o': + printf("You are trying to Output info\n"); + break; + case 'm': + printf("You are trying to Make things ordered\n"); + break; + case 'q': + printf("You are about to Quit\n"); + break; + default: + printf("Wrong input\n"); + break; + } +} + +int main() { + char a[100]; + manage(); + modifyStudent(); + printStudentOriginalScore(); + return 0; +}