主要内容:该系统实现对学生成绩的批量录入、修改、查询、浏览等功能。具体要求如下: 学生信息包括:学号、姓名、入学年月、4门课的成绩等8个成员,试设计学生成绩管理系统,使之能提供以下功能: 1、信息录入:录入每一位学生信息(包括学号、姓名、入学年月和4门课的成绩); 2、信息浏览:输出系统内所有学生的信息; 3、成绩修改:输入学号,修改该生某一门课的成绩; 4、分类查询:按学号或姓名查找学生,输出学生的成绩单; 5、统计学生总成绩:计算每个学生的总分及平均分,并根据学生的平均成绩进行排序;6、统计每门课程的成绩:计算每一门课程学生的及格率、优秀率等。 的c语言代码
时间: 2023-12-16 15:27:20 浏览: 127
以下是一个简单的学生成绩管理系统的C语言代码实现:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
#define MAX_NAME_LEN 20
typedef struct {
char id[10];
char name[MAX_NAME_LEN];
char start_date[10];
int scores[4];
int total_score;
float ave_score;
} Student;
typedef struct {
Student students[MAX_STUDENTS];
int count;
} StudentManager;
void init(StudentManager *manager) {
manager->count = 0;
}
void add(StudentManager *manager, Student student) {
manager->students[manager->count++] = student;
}
void print_header() {
printf("%5s %-10s %-10s %4s %4s %4s %4s %6s %6s\n", "No.", "ID", "Name", "Course1", "Course2", "Course3", "Course4", "Total", "Average");
}
void print_student(Student student, int index) {
printf("%5d %-10s %-10s %4d %4d %4d %4d %6d %6.2f\n", index, student.id, student.name, student.scores[0], student.scores[1], student.scores[2], student.scores[3], student.total_score, student.ave_score);
}
void print(StudentManager manager) {
print_header();
for (int i = 0; i < manager.count; i++) {
print_student(manager.students[i], i+1);
}
}
int find(StudentManager manager, char *key) {
for (int i = 0; i < manager.count; i++) {
if (strcmp(manager.students[i].id, key) == 0 || strcmp(manager.students[i].name, key) == 0) {
return i;
}
}
return -1;
}
void update(StudentManager *manager, char *id, int course, int score) {
int index = find(*manager, id);
if (index == -1) {
printf("Student not found.\n");
} else {
manager->students[index].scores[course-1] = score;
int total_score = 0;
for (int i = 0; i < 4; i++) {
total_score += manager->students[index].scores[i];
}
manager->students[index].total_score = total_score;
manager->students[index].ave_score = total_score / 4.0;
printf("Score updated.\n");
}
}
void sort(StudentManager *manager) {
for (int i = 0; i < manager->count-1; i++) {
for (int j = 0; j < manager->count-1-i; j++) {
if (manager->students[j].ave_score < manager->students[j+1].ave_score) {
Student temp = manager->students[j];
manager->students[j] = manager->students[j+1];
manager->students[j+1] = temp;
}
}
}
}
void print_course_stats(StudentManager manager, int course) {
int pass_count = 0, excellent_count = 0;
for (int i = 0; i < manager.count; i++) {
if (manager.students[i].scores[course-1] >= 60) {
pass_count++;
}
if (manager.students[i].scores[course-1] >= 90) {
excellent_count++;
}
}
printf("Course %d statistics: pass rate=%.2f%%, excellent rate=%.2f%%\n", course, pass_count*100.0/manager.count, excellent_count*100.0/manager.count);
}
int main() {
StudentManager manager;
init(&manager);
while (1) {
printf("\nStudent Score Management System\n");
printf("1. Add Student\n");
printf("2. View Students\n");
printf("3. Update Score\n");
printf("4. Find Student\n");
printf("5. Sort Students\n");
printf("6. Course Statistics\n");
printf("0. Exit\n");
printf("Enter your choice: ");
int choice;
scanf("%d", &choice);
switch (choice) {
case 0:
printf("Goodbye!\n");
exit(0);
case 1:
printf("Enter student ID: ");
char id[10];
scanf("%s", id);
printf("Enter student name: ");
char name[MAX_NAME_LEN];
scanf("%s", name);
printf("Enter start date (YYYY-MM-DD): ");
char start_date[10];
scanf("%s", start_date);
printf("Enter scores for 4 courses: ");
int scores[4];
for (int i = 0; i < 4; i++) {
scanf("%d", &scores[i]);
}
Student student = {0};
strcpy(student.id, id);
strcpy(student.name, name);
strcpy(student.start_date, start_date);
for (int i = 0; i < 4; i++) {
student.scores[i] = scores[i];
student.total_score += scores[i];
}
student.ave_score = student.total_score / 4.0;
add(&manager, student);
printf("Student added.\n");
break;
case 2:
print(manager);
break;
case 3:
printf("Enter student ID: ");
scanf("%s", id);
printf("Enter course number (1-4): ");
int course;
scanf("%d", &course);
printf("Enter new score: ");
int score;
scanf("%d", &score);
update(&manager, id, course, score);
break;
case 4:
printf("Enter student ID or name: ");
char key[20];
scanf("%s", key);
int index = find(manager, key);
if (index == -1) {
printf("Student not found.\n");
} else {
print_header();
print_student(manager.students[index], 1);
}
break;
case 5:
sort(&manager);
printf("Students sorted by average score.\n");
print(manager);
break;
case 6:
printf("Enter course number (1-4): ");
scanf("%d", &course);
print_course_stats(manager, course);
break;
default:
printf("Invalid choice.\n");
break;
}
}
return 0;
}
```
以上代码实现了一个简单的学生成绩管理系统,包括信息录入、信息浏览、成绩修改、分类查询、统计学生总成绩和每门课程的成绩等功能。其中采用了结构体存储学生信息,采用函数实现各种操作,以及采用排序算法对学生进行排序等。
阅读全文