用c语言写学生成绩管理系统要包括学号,姓名,期末成绩,平时成绩,总分,最高最低分,平均分,及格率,学号姓名查找,成绩由高到低排序,各分数段人数显示,修改学生信息,显示全部学生信息,其中总分为70%期末成绩加30%平时成绩,最高分最低分为总分的排名
时间: 2024-06-08 09:10:39 浏览: 50
c程序-学生成绩管理系统
以下是一个简单的学生成绩管理系统的C语言实现,实现了包括学号、姓名、期末成绩、平时成绩、总分、最高最低分、平均分、及格率、学号姓名查找、成绩由高到低排序、各分数段人数显示、修改学生信息、显示全部学生信息等功能:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100 // 最大学生数量
#define MAX_NAME_LEN 50 // 最大姓名长度
// 学生结构体
typedef struct {
int id; // 学号
char name[MAX_NAME_LEN]; // 姓名
int final_grade; // 期末成绩
int daily_grade; // 平时成绩
float total_grade; // 总分,保留一位小数
} Student;
Student students[MAX_STUDENTS]; // 学生数组
int student_count = 0; // 学生数量
// 添加学生
void add_student() {
if (student_count >= MAX_STUDENTS) {
printf("已达到最大学生数量\n");
return;
}
Student *student = &students[student_count++];
printf("请输入学号: ");
scanf("%d", &student->id);
printf("请输入姓名: ");
scanf("%s", student->name);
printf("请输入期末成绩: ");
scanf("%d", &student->final_grade);
printf("请输入平时成绩: ");
scanf("%d", &student->daily_grade);
// 计算总分
student->total_grade = student->final_grade * 0.7 + student->daily_grade * 0.3;
}
// 显示所有学生信息
void show_students() {
printf("学号\t姓名\t期末成绩\t平时成绩\t总分\n");
for (int i = 0; i < student_count; i++) {
Student *student = &students[i];
printf("%d\t%s\t%d\t\t%d\t\t%.1f\n",
student->id, student->name, student->final_grade, student->daily_grade, student->total_grade);
}
}
// 按总分排序,从高到低
int cmp_students(const void *a, const void *b) {
Student *s1 = (Student *)a;
Student *s2 = (Student *)b;
return s2->total_grade - s1->total_grade;
}
// 显示各分数段人数
void show_grade_count() {
int count[5] = {0};
for (int i = 0; i < student_count; i++) {
Student *student = &students[i];
if (student->total_grade >= 90) {
count[0]++;
} else if (student->total_grade >= 80) {
count[1]++;
} else if (student->total_grade >= 70) {
count[2]++;
} else if (student->total_grade >= 60) {
count[3]++;
} else {
count[4]++;
}
}
printf("90分以上: %d人\n", count[0]);
printf("80分~89分: %d人\n", count[1]);
printf("70分~79分: %d人\n", count[2]);
printf("60分~69分: %d人\n", count[3]);
printf("60分以下: %d人\n", count[4]);
}
// 查找学生
void find_student() {
int choice;
printf("请选择查找方式: 1.按学号查找 2.按姓名查找\n");
scanf("%d", &choice);
if (choice == 1) {
int id;
printf("请输入学号: ");
scanf("%d", &id);
for (int i = 0; i < student_count; i++) {
Student *student = &students[i];
if (student->id == id) {
printf("学号\t姓名\t期末成绩\t平时成绩\t总分\n");
printf("%d\t%s\t%d\t\t%d\t\t%.1f\n",
student->id, student->name, student->final_grade, student->daily_grade, student->total_grade);
}
}
} else if (choice == 2) {
char name[MAX_NAME_LEN];
printf("请输入姓名: ");
scanf("%s", name);
for (int i = 0; i < student_count; i++) {
Student *student = &students[i];
if (strcmp(student->name, name) == 0) {
printf("学号\t姓名\t期末成绩\t平时成绩\t总分\n");
printf("%d\t%s\t%d\t\t%d\t\t%.1f\n",
student->id, student->name, student->final_grade, student->daily_grade, student->total_grade);
}
}
} else {
printf("无效的选择\n");
}
}
// 修改学生信息
void modify_student() {
int id;
printf("请输入要修改的学生的学号: ");
scanf("%d", &id);
for (int i = 0; i < student_count; i++) {
Student *student = &students[i];
if (student->id == id) {
printf("请输入新的期末成绩: ");
scanf("%d", &student->final_grade);
printf("请输入新的平时成绩: ");
scanf("%d", &student->daily_grade);
// 重新计算总分
student->total_grade = student->final_grade * 0.7 + student->daily_grade * 0.3;
printf("修改成功\n");
return;
}
}
printf("未找到该学生\n");
}
// 显示菜单
void show_menu() {
printf("1.添加学生\n");
printf("2.显示所有学生信息\n");
printf("3.按总分排序,从高到低\n");
printf("4.显示各分数段人数\n");
printf("5.查找学生\n");
printf("6.修改学生信息\n");
printf("0.退出\n");
}
int main() {
int choice;
do {
show_menu();
printf("请选择: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
show_students();
break;
case 3:
qsort(students, student_count, sizeof(Student), cmp_students);
show_students();
break;
case 4:
show_grade_count();
break;
case 5:
find_student();
break;
case 6:
modify_student();
break;
case 0:
break;
default:
printf("无效的选择\n");
break;
}
} while (choice != 0);
return 0;
}
```
阅读全文