From 4759435f937ebfb8b427c91fc3c67d1fab449c4a Mon Sep 17 00:00:00 2001 From: p9gzklfo6 Date: Fri, 22 Nov 2024 16:05:38 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E7=AE=80=E6=98=93=E5=AD=A6=E7=B1=8D?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 简易学籍系统.c | 294 ++++++++++++++++++++++++++++--------------- 1 file changed, 190 insertions(+), 104 deletions(-) diff --git a/简易学籍系统.c b/简易学籍系统.c index 8031fa3..2ae1659 100644 --- a/简易学籍系统.c +++ b/简易学籍系统.c @@ -1,104 +1,190 @@ -#include -#include -#include - -#define MAX_STUDENTS 100 - -typedef struct { - int id; - char name[50]; - float gaoshu; - float wuli; - float yingyu; -} Student; - -Student students[MAX_STUDENTS]; -int studentCount = 0; - -void addStudent() { - printf("You are trying to Input info\n"); - if (studentCount >= MAX_STUDENTS) { - printf("Cannot add more students. Maximum limit reached.\n"); - return; - } - Student newStudent; - printf("Enter ID: "); - scanf("%d", &newStudent.id); - printf("Enter Name: "); - scanf("%s", newStudent.name); - printf("Enter ɼ: "); - scanf("%f", &newStudent.gaoshu); - printf("Enter ɼ: "); - scanf("%f", &newStudent.wuli); - printf("Enter Ӣɼ: "); - scanf("%f", &newStudent.yingyu); - - students[studentCount++] = newStudent; - printf("Student added successfully!\n"); -} - -void deleteStudent() { - int id; - printf("You are trying to Output info\n"); - printf("Enter ID of the student to delete: "); - scanf("%d", &id); - - for (int i = 0; i < studentCount; i++) { - if (students[i].id == id) { - for (int j = i; j < studentCount - 1; j++) { - students[j] = students[j + 1]; - } - studentCount--; - printf("Student deleted successfully!\n"); - return; - } - } - - printf("Student not found!\n"); -} - -void displayStudents() { - printf("You are trying to Make things ordered\n"); - if (studentCount == 0) { - printf("No students to display.\n"); - return; - } - - printf("ID\tName\tɼ\tɼ\tӢɼ\tܳɼ\n"); - for (int i = 0; i < studentCount; i++) { - printf("%d\t%s\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n", students[i].id, students[i].name, students[i].gaoshu,students[i].wuli,students[i].yingyu,students[i].gaoshu+students[i].wuli+students[i].yingyu); - } -} - -int main() { - int choice; - int running = 1; // ѭı - - while (running) { printf("1234ʹöӦ\n"); - printf(" 1. Input\n"); - printf(" 2. Output\n"); - printf(" 3. Order\n"); - printf(" 4. Quit\n"); - printf("Enter your choice: "); - scanf("%d", &choice); - - switch (choice) { - case 1: - addStudent(); - break; - case 2: - deleteStudent(); - break; - case 3: - displayStudents(); - break; - case 4: - running = 0; // Ϊ0˳ѭ - break; - default: - printf("Wrong input.\n"); - } - } - - return 0; -} +#include +#include +#include + +#define MAX_STUDENTS 100 + +typedef struct { + int id; + char name[50]; + float gaoshu; + float wuli; + float yingyu; + int banji; +} Student; + +Student students[MAX_STUDENTS]; +int studentCount = 0; + +void addStudent() { + char panduan; + printf("You are trying to Input info\n"); + if (studentCount >= MAX_STUDENTS) { + printf("Cannot add more students. Maximum limit reached.\n"); + return; + } + Student newStudent; + printf("Enter ID: "); + scanf("%d", &newStudent.id); + printf("Enter Name: "); + scanf("%s", newStudent.name); + printf("Enter Class: "); + scanf("%d",&newStudent.banji); + printf("Enter ɼ: "); + scanf("%f", &newStudent.gaoshu); + printf("Enter ɼ: "); + scanf("%f", &newStudent.wuli); + printf("Enter Ӣɼ: "); + scanf("%f", &newStudent.yingyu); + + students[studentCount++] = newStudent; + printf("Student added successfully!\n"); + printf("continue?"); + +} + +void deleteStudent() { + int id; + printf("You are trying to Output info\n"); + printf("Enter ID of the student to delete: "); + scanf("%d", &id); + + for (int i = 0; i < studentCount; i++) { + if (students[i].id == id) { + for (int j = i; j < studentCount - 1; j++) { + students[j] = students[j + 1]; + } + studentCount--; + printf("Student deleted successfully!\n"); + return; + } + } + + printf("Student not found!\n"); +} + +void selectStudent(){ + int xuan; + printf("Input Id or Class:"); + scanf("%d",&xuan); + for (int i = 0; i < studentCount; i++) { + if(xuan==students[i].id||xuan==students[i].banji) + { + printf("%d\t%s\t%d\t%.2f\t%.2f\t%.2f\t%.2f\n", students[i].id, students[i].name, students[i].banji,students[i].gaoshu,students[i].wuli,students[i].yingyu,students[i].gaoshu+students[i].wuli+students[i].yingyu); + } + } + printf("continue?"); +} + +void orderStudents() { + int i, j; + Student temp; + for (i = 0; i < studentCount - 1; i++) { + for (j = i + 1; j < studentCount; j++) { + if (students[i].banji > students[j].banji) { + temp = students[i]; + students[i] = students[j]; + students[j] = temp; + } + else if (students[i].banji == students[j].banji) { + float totalScoreI = students[i].gaoshu + students[i].wuli + students[i].yingyu; + float totalScoreJ = students[j].gaoshu + students[j].wuli + students[j].yingyu; + if (totalScoreI < totalScoreJ) { + temp = students[i]; + students[i] = students[j]; + students[j] = temp; + } + } + } + } + printf("ID\tName\t༶\tɼ\tɼ\tӢɼ\tܳɼ\n"); + for (int i = 0; i < studentCount; i++) + { + printf("%d\t%s\t%d\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n", students[i].id, students[i].name, students[i].banji,students[i].gaoshu,students[i].wuli,students[i].yingyu,students[i].gaoshu+students[i].wuli+students[i].yingyu); + } +} + +void displayStudents() +{ + printf("You are trying to Make things ordered\n"); + if (studentCount == 0) { + printf("No students to display.\n"); + return; + } + + printf("ID\tName\t༶\tɼ\tɼ\tӢɼ\tܳɼ\n"); + for (int i = 0; i < studentCount; i++) + { + printf("%d\t%s\t%d\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n", students[i].id, students[i].name, students[i].banji,students[i].gaoshu,students[i].wuli,students[i].yingyu,students[i].gaoshu+students[i].wuli+students[i].yingyu); + } +} + +int main() { + int choice; + int running = 1; // ѭı + + while (running) { printf("1234, 5, 6ʹöӦ\n"); + printf(" 1. Input\n"); + printf(" 2. Output\n"); + printf(" 3. select\n"); + printf(" 4. order\n"); + printf(" 5. output\n"); + printf(" 6. Quit\n"); + printf("Enter your choice: "); + scanf("%d", &choice); + char panduan[3]; + + + switch (choice) { + case 1: + addStudent(); + loop: + scanf("%s",panduan); + if(strcmp(panduan,"yes")==0) + { + addStudent(); + goto loop; + } + else + break; + case 2: + deleteStudent(); + scanf("%s",panduan); + if(strcmp(panduan,"yes")==0) + { + deleteStudent(); + } + else + break; + case 3: + selectStudent(); + loop3: + scanf("%s",panduan); + if(strcmp(panduan,"yes")==0) + { + selectStudent(); + goto loop3; + } + else + break; + case 4: + orderStudents(); + break; + case 5: + displayStudents(); + break; + case 6: + running = 0; + break; + default: + printf("Wrong input.\n"); + } + } + + return 0; +} + } + } + + return 0; +}