From 5c47bea36ce8a5d416ed84fa23492a3326577293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=9F=B9=E6=AF=85?= <3020727885@qq.com> Date: Mon, 17 Apr 2023 19:31:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E6=88=90=E7=BB=A9=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 5 +++ 学生成绩管理系统 | 86 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 学生成绩管理系统 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2a0d09e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "创建学生基本信息": "c" + } +} \ No newline at end of file diff --git a/学生成绩管理系统 b/学生成绩管理系统 new file mode 100644 index 0000000..cc52f1c --- /dev/null +++ b/学生成绩管理系统 @@ -0,0 +1,86 @@ +#include +#include +#include +#define MAX_LEN 10 // 字符串最大长度 +#define STU_NUM 30 // 最多的学生人数 +#define COURSE_NUM 6 // 最多的考试科目数 +typedef struct student +{ + long num; // 每个学生的学号 + char name[MAX_LEN]; // 每个学生的姓名 + float score[COURSE_NUM]; // 每个学生COURSE_NUM门功课的成绩 + float sum; // 每个学生的总成绩 + float aver; // 每个学生的平均成绩 +}STU; +int Menu(void); +void ReadScore(STU stu[], int n, int m); +void AverSumofEveryStudent(STU stu[], int n, int m); +void AverSumofEveryCourse(STU stu[], int n, int m); +void SortbyScore(STU stu[],int n,int m,int (*compare)(float a,float b)); +int Ascending(float a, float b); +int Descending(float a, float b); +void SwapFloat(float *x, float *y); +void SwapLong(long *x, long *y); +void SwapChar(char x[], char y[]); +void AsSortbyNum(STU stu[], int n, int m); +void SortbyName(STU stu[], int n, int m); +void SearchbyNum(STU stu[], int n, int m); +void SearchbyName(STU stu[], int n, int m); +void StatisticAnalysis(STU stu[], int n, int m); +void PrintScore(STU stu[], int n, int m); +void WritetoFile(STU record[], int n, int m); +void ReadfromFile(STU record[], int *n, int *m); +int main(void) +{ + char ch; + int n = 0, m = 0; + STU stu[STU_NUM]; +printf("Input student number(n<%d):", STU_NUM); + scanf("%d", &n); +printf("Input course number(m<=%d):",COURSE_NUM); + scanf("%d", &m); + while (1) + { + ch = Menu(); // 显示菜单,并读取用户输入 + switch (ch) + { + case 1:ReadScore(stu, n, m); + break; + case 2: AverSumofEveryCourse(stu, n, m); + break; + case 3: AverSumofEveryStudent(stu, n, m); + break; + case 4: SortbyScore(stu, n, m, Descending); + printf("\nSort in descending order by score:\n"); + PrintScore(stu, n, m); + break; + case 5: SortbyScore(stu, n, m, Ascending); + printf("\nSort in ascending order by score:\n"); + PrintScore(stu, n, m); + break; + case 6: AsSortbyNum(stu, n, m); + printf("\nSort in ascending order by number:\n"); + PrintScore(stu, n, m); + break; + case 7: SortbyName(stu, n, m); + printf("\nSort in dictionary order by name:\n"); + PrintScore(stu, n, m); + break; + case 8: SearchbyNum(stu, n, m); + break; + case 9: SearchbyName(stu, n, m); + break; + case 10: StatisticAnalysis(stu, n, m); + break; + case 11:PrintScore(stu, n, m); + break; +case 12:WritetoFile(stu, n, m); + break; + case 13:ReadfromFile(stu, &n, &m); + break; + case 0: printf("End of program!"); + exit(0); + default:printf("Input error!"); + } + } + return 0;} \ No newline at end of file