From 6b8e6618d1531528bac4fd398f8bde559273ed82 Mon Sep 17 00:00:00 2001 From: pqzbgempc <2193876517@qq.com> Date: Wed, 20 Nov 2024 18:41:09 +0800 Subject: [PATCH] ADD file via upload --- xjxt8.cpp | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 xjxt8.cpp diff --git a/xjxt8.cpp b/xjxt8.cpp new file mode 100644 index 0000000..e154ec8 --- /dev/null +++ b/xjxt8.cpp @@ -0,0 +1,176 @@ +#include +#include +#define MAX_STUDENTS 100 +typedef struct +{ + char id[20]; + char mclass[20]; + char name[20]; + float score1, score2, score3; +} Student; +int numStudents=0; // 记录当前学生的数量 +Student students[MAX_STUDENTS]; +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() +{ + + printf("ID "); + scanf("%s", students[numStudents].id); + printf("class: "); + scanf("%s", &(students[numStudents].mclass)); + printf("name: "); + scanf("%s", students[numStudents].name); + printf("score1: "); + scanf("%f", &(students[numStudents].score1)); + printf("score2: "); + scanf("%f", &(students[numStudents].score2)); + printf("score3: "); + scanf("%f", &(students[numStudents].score3)); + numStudents++; +} + +void deleteStudent() +{ + char idOrName[20]; + scanf("%s", idOrName); + int i, j; + int found = 0; + for (i = 0; i < numStudents; i++) + { + if (strcmp(students[i].id, idOrName) == 0 || strcmp(students[i].name, idOrName) == 0) + { + found = 1; + for (j = i; j < numStudents - 1; j++) + { + students[j] = students[j + 1]; + } + numStudents--; + break; + } + } + for ( i = 0; i < numStudents; i++) + { + printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].mclass, students[i].name, students[i].score1, students[i].score2, students[i].score3); + } +} +void selectStudent() +{ + char idOrName[20]; + scanf("%s", idOrName); + int i,j; + int f=0; + for (i = 0; i < numStudents; i++) + { + if (strcmp(students[i].id, idOrName) == 0 || strcmp(students[i].name, idOrName) == 0) + { + f=1; + printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].mclass, students[i].name, students[i].score1, students[i].score2, students[i].score3); + } + } + if(f==0) printf("there is no eligible student\n"); +} + +void orderStudent() +{ + int i,j; + for (i = 0; i < numStudents; i++) + { + for (j=i+1;j students[j].mclass || (students[i].mclass == students[j].mclass && students[i].score1 + students[i].score2 + students[i].score3 < students[j].score1 + students[j].score2 + students[j].score3)) + { + Student temp = students[j]; + students[j] = students[i]; + students[i] = temp; + } + } + } + for ( i = 0; i < numStudents; i++) + { + printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].mclass, students[i].name, students[i].score1, students[i].score2, students[i].score3); + } +} +void printStudent() +{ + int i=0; + for (i = 0; i < numStudents; i++) + { + printf("%s %s %s %.1f %.1f %.1f\n", students[i].id, students[i].mclass, students[i].name, students[i].score1, students[i].score2, students[i].score3); + } +} + +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; + } + //showMenu(); + } +} +