还在为期末程序设计而烦恼吗,不要担心,大师帮你安利一波完整的的管理系统代码,对你有帮助记得加关注噢!
文章目录
一、学生成绩管理系统是什么?
二、信息管理的七个模块
1.Step one
2.Step Two
3.Step Three
4.Step four
5.Step five
6.Step Six
7.Next
总结
一、学生成绩管理系统是什么?
学生信息管理系统能够方便地查询和变更学生的基本数据(例如增删改查),节省大量工作时间,有效地提高学生信息管理的效率。今天要讲的是以下7个模块。
1. 学生信息输入模块。其中包括学生信息的输入和存储,同时考虑学号输入的健壮性,避免输入重复的学号。
2. 学生信息更新模块。提供对学生信息的修改和删除功能,同时也需要进行学号输入的检查,避免出现不合法的学号。
3. 成绩查询模块。可以按照学号或姓名查找学生信息,并输出学生的成绩信息。
4. 成绩统计模块。可以对所有学生的成绩按个人、按专业、按课程和按班级进行升序和降序的统计和排名,并输出成绩排名。
5. 成绩输出模块。可以按照不同的格式输出学生的成绩信息,包括按照学号、姓名、成绩等排序。
6. 系统帮助模块。提供系统使用的帮助信息,包括各个模块的使用方法和注意事项。
7. 退出系统模块。可以在任何时候退出系统。
二、信息管理的七个模块
1.Step one
数据结构设计:
在实现该系统之前,我们需要先设计一下需要用到的数据结构。我们可以定义一个结构体来表示学生的基本信息和成绩信息。
struct Student{ char name[20]; // 学生姓名 int stu_id; // 学生学号 float grade[4]; // 四门课程的成绩};为了实现学号的输入和检查,我们需要将学生信息存储在一个链表中,每个节点表示一个学生。struct Student_List{ struct Student student; struct Student_List *next;};
2.Step Two
学生信息输入模块:
我们需要设计一个函数来读入学生信息,将其存储在链表中。
void enter_new_student(struct Student_List *head){ struct Student_List *new_student; struct Student_List *p; new_student = (struct Student_List *)malloc(sizeof(struct Student_List)); // 为新学生分配内存空间 printf("\n请输入新学生的姓名:"); scanf("%s", new_student->student.name); printf("请输入学生学号:"); scanf("%d", &new_student->student.stu_id); p = head->next; while(p != NULL)// 检查学号是否重复 {if(p->student.stu_id == new_student->student.stu_id){ printf("学号重复,请重新输入:"); scanf("%d", &new_student->student.stu_id); p = head->next;}else{ p = p->next;} } printf("请输入四门功课的成绩:"); for(int i = 0; i student.grade[i]); } new_student->next = head->next;// 把新学生插入链表头部 head->next = new_student;}
3.Step Three
学生信息更新模块
我们需要实现一个函数来更新学生信息。首先,我们需要输入要更新的学生的学号。如果学号存在,则将学生的基本信息和成绩信息读入,然后更新到链表中。
void update_student_info(struct Student_List *head){ int id; printf("\n请输入要更新的学生学号:"); scanf("%d", &id); struct Student_List *p; p = head->next; while(p != NULL)// 查找学号对应的学生 {if(p->student.stu_id == id){ printf("请输入学生姓名:"); scanf("%s", p->student.name); printf("请输入四门功课的成绩:"); for(int i = 0; i student.grade[i]); } printf("学生信息已更新!\n"); return;}else{ p = p->next;} } printf("没有找到该学号对应的学生!\n");}
4.Step four
成绩查询模块
我们需要设计一个函数,可以按照学号或姓名查找学生信息。如果查到学生信息,则输出其基本信息和成绩信息。
void search_student_info(struct Student_List *head){ int choice; printf("\n请输入查询方式(1为按学号查询,2为按姓名查询):"); scanf("%d", &choice); if(choice == 1) {int id;printf("请输入学生学号:");scanf("%d", &id);struct Student_List *p;p = head->next;while(p != NULL)// 查找学号对应的学生{ if(p->student.stu_id == id) {printf("姓名:%s 学号:%d\n", p->student.name, p->student.stu_id);printf("语文成绩:%f 数学成绩:%f 英语成绩:%f 物理成绩:%f\n", p->student.grade[0], p->student.grade[1], p->student.grade[2], p->student.grade[3]);return; } else{p = p->next; }}printf("没有找到该学号对应的学生!\n"); } else if(choice == 2) {char name[20];printf("请输入学生姓名:");scanf("%s", name);struct Student_List *p;p = head->next;while(p != NULL)// 查找姓名对应的学生{ if(strcmp(p->student.name, name) == 0) {printf("姓名:%s 学号:%d\n", p->student.name, p->student.stu_id);printf("语文成绩:%f 数学成绩:%f 英语成绩:%f 物理成绩:%f\n", p->student.grade[0], p->student.grade[1], p->student.grade[2], p->student.grade[3]);return; } else{p = p->next; }}printf("没有找到该姓名对应的学生!\n"); } else{printf("输入有误,请重新输入!\n");search_student_info(head); }}
5.Step five
成绩统计模块
我们需要实现一个函数对所有学生的成绩按个人、按专业、按课程和按班级进行升序和降序的统计和排名,并输出成绩排名。
int cmp(const void *a, const void *b){ struct Student_List *p1 = *(struct Student_List **)a; struct Student_List *p2 = *(struct Student_List **)b; int sum1 = 0, sum2 = 0; for(int i = 0; i student.grade[i];sum2 += p2->student.grade[i]; } float avg1 = (float)sum1 / 4; float avg2 = (float)sum2 / 4; if(avg1 next; int nums = 0; // 统计学生总数 while(p != NULL) {nums++;p = p->next; } // 动态分配内存 struct Student_List **list = (struct Student_List **)malloc(nums * sizeof(struct Student_List *)); p = head->next; for(int i = 0; i next; } // 根据不同的排序方式调用快排函数 switch(choice) {case 1: qsort(list, nums, sizeof(struct Student_List *), cmp); break;case 2: break;case 3: break;case 4: break;case 5: break;default: printf("输入有误,请重新输入!\n"); rank_students(head); } // 按升序或降序输出结果 if(by_order == 1) {printf("名次 姓名平均分\n");for(int i = 0; i student.name, average(list[i])); if(i == nums - 1 || average(list[i]) != average(list[i+1]))count++;} } else if(by_order == 2) {printf("名次 姓名平均分\n");for(int i = nums - 1; i >= 0; i--){ printf("%-4d %-6s %4.2f\n", count, list[i]->student.name, average(list[i])); if(i == 0 || average(list[i]) != average(list[i-1]))count++;} } else{printf("输入有误,请重新输入!\n");rank_students(head); } // 释放内存 free(list);}// 计算学生平均分的函数float average(struct Student_List *p){ int sum = 0; for(int i = 0; i student.grade[i]; } return (float)sum / 4;}
6.Step Six
成绩输出模块
我们需要设计一个函数,可以按照不同的格式输出学生的成绩信息,包括按照学号、姓名、成绩等排序。
void print_students(struct Student_List *head){ int choice; printf("\n请选择要排序的方式(1为按学号排序,2为按姓名排序,3为按平均分排序,4为按语文成绩排序,5为按数学成绩排序,6为按英语成绩排序,7为按物理成绩排序):"); scanf("%d", &choice); struct Student_List **list = (struct Student_List **)malloc(nums * sizeof(struct Student_List *)); struct Student_List *p; p = head->next; // 构建链表节点的指针数组 for(int i = 0; i next; } // 根据不同的排序方式对链表节点的指针数组进行排序 switch(choice) {case 1: qsort(list, nums, sizeof(struct Student_List *), cmp_id); break;case 2: qsort(list, nums, sizeof(struct Student_List *), cmp_name); break;case 3: qsort(list, nums, sizeof(struct Student_List *), cmp); break;case 4: qsort(list, nums, sizeof(struct Student_List *), cmp_chinese); break;case 5: qsort(list, nums, sizeof(struct Student_List *), cmp_math); break;case 6: qsort(list, nums, sizeof(struct Student_List *), cmp_english); break;case 7: qsort(list, nums, sizeof(struct Student_List *), cmp_physics); break;default: printf("输入有误,请重新输入!\n"); print_students(head); } // 输出排序后的结果 printf("姓名学号平均分 语文 数学 英语 物理\n"); for(int i = 0; i student.name, list[i]->student.stu_id, average(list[i]), list[i]->student.grade[0], list[i]->student.grade[1], list[i]->student.grade[2], list[i]->student.grade[3]); } // 释放内存 free(list);}// 对学号进行比较的函数int cmp_id(const void *a, const void *b){ struct Student_List *p1 = *(struct Student_List **)a; struct Student_List *p2 = *(struct Student_List **)b; if(p1->student.stu_id student.stu_id)return -1; else if(p1->student.stu_id == p2->student.stu_id)return 0; elsereturn 1;}// 对姓名进行比较的函数int cmp_name(const void *a, const void *b){ struct Student_List *p1 = *(struct Student_List **)a; struct Student_List *p2 = *(struct Student_List **)b; return strcmp(p1->student.name, p2->student.name);}// 对语文成绩进行比较的函数int cmp_chinese(const void *a, const void *b){ struct Student_List *p1 = *(struct Student_List **)a; struct Student_List *p2 = *(struct Student_List **)b; if(p1->student.grade[0] > p2->student.grade[0])return -1; else if(p1->student.grade[0] == p2->student.grade[0])return 0; elsereturn 1;}// 对数学成绩进行比较的函数int cmp_math(const void *a, const void *b){ struct Student_List *p1 = *(struct Student_List **)a; struct Student_List *p2 = *(struct Student_List **)b; if(p1->student.grade[1] > p2->student.grade[1])return -1; else if(p1->student.grade[1] == p2->student.grade[1])return 0; elsereturn 1;}// 对英语成绩进行比较的函数int cmp_english(const void *a, const void *b){ struct Student_List *p1 = *(struct Student_List **)a; struct Student_List *p2 = *(struct Student_List **)b; if(p1->student.grade[2] > p2->student.grade[2])return -1; else if(p1->student.grade[2] == p2->student.grade[2])return 0; elsereturn 1;}// 对物理成绩进行比较的函数int cmp_physics(const void *a, const void *b){ struct Student_List *p1 = *(struct Student_List **)a; struct Student_List *p2 = *(struct Student_List **)b; if(p1->student.grade[3] > p2->student.grade[3])return -1; else if(p1->student.grade[3] == p2->student.grade[3])return 0; elsereturn 1;}
7.Next
以下是完整代码,且可以运行,有需要的小伙伴可以复制下来自己运行一下噢,如果有帮助的话,请给大师我点点赞,大师在此先行谢谢C友了!
#include #include #include #define MAX_STUDENTS 100#define MAX_NAME_LEN 30#define MAX_ID_LEN 20#define MAX_MAJOR_LEN 50#define MAX_COURSE_LEN 50#define GRADE_NUM 3struct student {char name[MAX_NAME_LEN];char id[MAX_ID_LEN];char major[MAX_MAJOR_LEN];float grades[GRADE_NUM];};struct student students[MAX_STUDENTS];int num_students = 0;void input_student_info();void update_student_info();void query_grades();void report_grades();void output_grades();void help();void exit_system();int main() {int choice = 0;while (1) {printf("==== Student Grade Management System ====\n");printf("1. Input Student Information\n");printf("2. Update Student Information\n");printf("3. Query Grades\n");printf("4. Report Grades\n");printf("5. Output Grades\n");printf("6. Help\n");printf("7. Exit\n");printf("Please enter your choice (1-7):\n");scanf("%d", &choice);switch (choice) {case 1:input_student_info();break;case 2:update_student_info();break;case 3:query_grades();break;case 4:report_grades();break;case 5:output_grades();break;case 6:help();break;case 7:exit_system();return 0;default:printf("Invalid choice!\n");break;}}}void input_student_info() {if (num_students >= MAX_STUDENTS) {printf("Too many students, cannot input more!\n");return;}struct student new_student;printf("Please enter the name of the student:\n");scanf("%s", new_student.name);printf("Please enter the ID of the student:\n");scanf("%s", new_student.id);for (int i = 0; i < num_students; i++) {if (strcmp(students[i].id, new_student.id) == 0) {printf("Duplicate ID, please input again!\n");return;}}printf("Please enter the major of the student:\n");scanf("%s", new_student.major);printf("Please enter the grades of the student (3 numbers separated by spaces):\n");scanf("%f %f %f", &new_student.grades[0], &new_student.grades[1], &new_student.grades[2]);students[num_students++] = new_student;printf("Student information input successful!\n");}void update_student_info() {char id[MAX_ID_LEN];printf("Please enter the ID of the student to be updated:\n");scanf("%s", id);int found = 0;for (int i = 0; i < num_students; i++) {if (strcmp(students[i].id, id) == 0) {found = 1;printf("1. Update Name\n");printf("2. Update Major\n");printf("3. Update Grades\n");printf("4. Delete Student\n");printf("Please enter your choice (1-4):\n");int choice = 0;scanf("%d", &choice);switch (choice) {case 1:printf("Please enter the new name of the student:\n");scanf("%s", students[i].name);printf("Name updated successful!\n");break;case 2:printf("Please enter the new major of the student:\n");scanf("%s", students[i].major);printf("Major updated successful!\n");break;case 3:printf("Please enter the new grades of the student (3 numbers separated by spaces):\n");scanf("%f %f %f", &students[i].grades[0], &students[i].grades[1], &students[i].grades[2]);printf("Grades updated successful!\n");break;case 4:for (int j = i + 1; j < num_students; j++) {students[j - 1] = students[j];}num_students--;printf("Student deleted successful!\n");break;default:printf("Invalid choice!\n");break;}break;}}if (!found) {printf("Student not found!\n");}}void query_grades() {printf("1. Query by ID\n");printf("2. Query by Name\n");printf("Please enter your choice (1-2):\n");int choice = 0;scanf("%d", &choice);switch (choice) {case 1:printf("Please enter the ID of the student:\n");char id[MAX_ID_LEN];scanf("%s", id);for (int i = 0; i < num_students; i++) {if (strcmp(students[i].id, id) == 0) {printf("Name: %s\n", students[i].name);printf("ID: %s\n", students[i].id);printf("Major: %s\n", students[i].major);printf("Grades: %.1f %.1f %.1f\n", students[i].grades[0], students[i].grades[1], students[i].grades[2]);return;}}printf("Student not found!\n");break;case 2:printf("Please enter the name of the student:\n");char name[MAX_NAME_LEN];scanf("%s", name);for (int i = 0; i < num_students; i++) {if (strcmp(students[i].name, name) == 0) {printf("Name: %s\n", students[i].name);printf("ID: %s\n", students[i].id);printf("Major: %s\n", students[i].major);printf("Grades: %.1f %.1f %.1f\n", students[i].grades[0], students[i].grades[1], students[i].grades[2]);return;}}printf("Student not found!\n");break;default:printf("Invalid choice!\n");break;}}void report_grades() {printf("1. By Name\n");printf("2. By Major\n");printf("3. By Course\n");printf("4. By Class\n");printf("Please enter your choice (1-4):\n");int choice = 0;scanf("%d", &choice);switch (choice) {case 1:printf("Report by Name:\n");printf("Name\tID\tGrades\tRank\n");for (int i = 0; i < num_students; i++) {float avg_grade = (students[i].grades[0] + students[i].grades[1] + students[i].grades[2]) / 3;int rank = 1;for (int j = 0; j avg_grade) {rank++;}}}printf("%s\t%s\t%.1f %.1f %.1f\t%d\n", students[i].name, students[i].id, students[i].grades[0], students[i].grades[1], students[i].grades[2], rank);}break;case 2:printf("Report by Major:\n");printf("Major\tCount\tAverage Grade\n");for (int i = 0; i < num_students; i++) {char *major = students[i].major;int count = 1;float total_grade = students[i].grades[0] + students[i].grades[1] + students[i].grades[2];for (int j = i + 1; j < num_students; j++) {if (strcmp(students[j].major, major) == 0) {count++;total_grade += students[j].grades[0] + students[j].grades[1] + students[j].grades[2];}}float avg_grade = total_grade / (count * 3);printf("%s\t%d\t%.1f\n", major, count, avg_grade);i += count - 1;}break;case 3: {printf("Please enter the course name:\n");char course[MAX_COURSE_LEN];scanf("%s", course);printf("Report by Course (%s):\n", course);printf("Name\tID\tGrade\n");for (int i = 0; i < num_students; i++) {printf("%s\t%s\t%.1f\n", students[i].name, students[i].id, students[i].grades[choice - 1]);}break;}case 4: {printf("Please enter the class name:\n");char class_name[MAX_MAJOR_LEN];scanf("%s", class_name);printf("Report by Class (%s):\n", class_name);printf("Name\tID\tGrades\tRank\n");for (int i = 0; i < num_students; i++) {if (strcmp(students[i].major, class_name) == 0) {float avg_grade = (students[i].grades[0] + students[i].grades[1] + students[i].grades[2]) / 3;int rank = 1;for (int j = 0; j avg_grade) {rank++;}}}printf("%s\t%s\t%.1f %.1f %.1f\t%d\n", students[i].name, students[i].id, students[i].grades[0], students[i].grades[1], students[i].grades[2], rank);}}break;}default:printf("Invalid choice!\n");break;}}void output_grades() {printf("1. By ID\n");printf("2. By Name\n");printf("3. By Grade\n");printf("Please enter your choice (1-3):\n");int choice = 0;scanf("%d", &choice);switch (choice) {case 1:printf("Output by ID:\n");for (int i = 0; i < num_students; i++) {printf("%s\t%s\t%.1f %.1f %.1f\n", students[i].id, students[i].name, students[i].grades[0], students[i].grades[1], students[i].grades[2]);}break;case 2:printf("Output by Name:\n");for (int i = 0; i < num_students; i++) {printf("%s\t%s\t%.1f %.1f %.1f\n", students[i].name, students[i].id, students[i].grades[0], students[i].grades[1], students[i].grades[2]);}break;case 3:printf("Output by Grade:\n");printf("Name\tID\tSum\tAverage\n");for (int i = 0; i < num_students; i++) {float sum_grade = students[i].grades[0] + students[i].grades[1] + students[i].grades[2];float avg_grade = sum_grade / 3;printf("%s\t%s\t%.1f\t%.1f\n", students[i].name, students[i].id, sum_grade, avg_grade);}break;default:printf("Invalid choice!\n");break;}}void help() {printf("Welcome to Student Grade Management System!\n");printf("1. Input Student Information: Input the name, ID, major and grades of a new student.\n");printf("2. Update Student Information: Update the name, major or grades of a student, or delete a student.\n");printf("3. Query Grades: Query the grades of a student by ID or name.\n");printf("4. Report Grades: Generate a report of the grades of all students, by name, major, course or class.\n");printf("5. Output Grades: Output the grades of all students, sorted by ID, name or grade.\n");printf("6. Help: Show this message.\n");printf("7. Exit: Exit the system.\n");}void exit_system() {printf("Thank you for using Student Grade Management System, see you next time!\n");}
总结
以上就是今天要讲的内容,本文仔细介绍了学生管理系统模块化的开发,提供了比较完整且有序的撰写思路,先前模块的思路仅供参考,最终以源码为准。如果觉得博主的文章能够帮到你,还记得点点关注,以下是博主的其它文章,有兴趣的小伙伴可以看看噢。