用C语言写一个成绩管理系统
时间: 2023-12-29 10:00:57 浏览: 61
今天给大家分享一个C语言环境下开发的学生成绩管理系统 这个系统原理很简单:成绩的录入,输出,修改,排序,删除等等
很抱歉,作为AI语言模型,我无法为您编写可以运行的程序。但是,我可以为您提供一个成绩管理系统的框架,供您参考:
#include <stdio.h>
#include <stdlib.h>
#define MAX_STUDENTS 100 // 最大学生人数
#define MAX_NAME_LEN 20 // 学生姓名最大长度
// 学生结构体
typedef struct {
char name[MAX_NAME_LEN]; // 学生姓名
int math_score; // 数学成绩
int english_score; // 英语成绩
int programming_score; // 编程成绩
} Student;
// 学生数组
Student students[MAX_STUDENTS];
int num_students = 0; // 当前学生人数
// 添加学生
void add_student() {
// 判断是否已达到最大学生人数
if (num_students >= MAX_STUDENTS) {
printf("The maximum number of students has been reached.\n");
return;
}
// 输入学生信息
printf("Please enter the student's name: ");
scanf("%s", students[num_students].name);
printf("Please enter the math score: ");
scanf("%d", &students[num_students].math_score);
printf("Please enter the English score: ");
scanf("%d", &students[num_students].english_score);
printf("Please enter the programming score: ");
scanf("%d", &students[num_students].programming_score);
// 增加学生人数
num_students++;
}
// 显示所有学生信息
void show_students() {
printf("Name\tMath\tEnglish\tProgramming\n");
for (int i = 0; i < num_students; i++) {
printf("%s\t%d\t%d\t%d\n", students[i].name, students[i].math_score,
students[i].english_score, students[i].programming_score);
}
}
// 计算学生平均成绩
void calculate_average_scores() {
int total_math_score = 0;
int total_english_score = 0;
int total_programming_score = 0;
for (int i = 0; i < num_students; i++) {
total_math_score += students[i].math_score;
total_english_score += students[i].english_score;
total_programming_score += students[i].programming_score;
}
printf("Average Math Score: %d\n", total_math_score / num_students);
printf("Average English Score: %d\n", total_english_score / num_students);
printf("Average Programming Score: %d\n", total_programming_score / num_students);
}
// 主函数
int main() {
int choice = 0;
while (1) {
// 显示菜单
printf("\nMenu:\n");
printf("1. Add Student\n");
printf("2. Show All Students\n");
printf("3. Calculate Average Scores\n");
printf("4. Exit\n");
printf("Please enter your choice (1-4): ");
scanf("%d", &choice);
// 执行选择的操作
switch (choice) {
case 1:
add_student();
break;
case 2:
show_students();
break;
case 3:
calculate_average_scores();
break;
case 4:
printf("Goodbye!\n");
exit(0);
default:
printf("Invalid choice.\n");
break;
}
}
return 0;
}
阅读全文