用c语言实现功能要求 基本要求:(1)试设计一个学生成绩信息管理系统,使之能提供以下功能: (2)按学期、班级完成对学生成绩的录入功能、修改(3)按班级统计学生的成绩,求学生的总分及平均分,并排序(4)能查询学生成绩,不及格科目及学生名单(5)按班级输出学生的成绩单
时间: 2024-03-30 11:33:51 浏览: 116
好的,我会尽力回答你的问题。
首先,你需要设计一个学生成绩信息管理系统,这个系统需要能够提供以下功能:
1. 录入学生成绩:可以按照学期、班级来录入学生成绩,也可以修改已有的学生成绩信息。
2. 统计学生成绩:可以按照班级来统计学生成绩,包括学生的总分、平均分,并且需要进行排序。
3. 查询学生成绩:可以查询学生成绩,包括不及格科目和学生名单。
4. 输出学生成绩单:可以按照班级来输出学生成绩单。
为了实现这些功能,你可以使用 C 语言来编写代码。下面是一个简单的实现:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_CLASS_SIZE 100
#define MAX_NAME_LENGTH 20
#define MAX_SUBJECTS 10
typedef struct {
char name[MAX_NAME_LENGTH];
int score[MAX_SUBJECTS];
int total;
float average;
} student;
typedef struct {
char name[MAX_NAME_LENGTH];
student students[MAX_CLASS_SIZE];
int size;
} class;
class classes[MAX_CLASS_SIZE];
int num_classes = 0;
void add_class() {
printf("Enter class name: ");
scanf("%s", classes[num_classes].name);
classes[num_classes].size = 0;
num_classes++;
}
void add_student() {
char class_name[MAX_NAME_LENGTH];
int i, j;
printf("Enter class name: ");
scanf("%s", class_name);
for (i = 0; i < num_classes; i++) {
if (strcmp(classes[i].name, class_name) == 0) {
printf("Enter student name: ");
scanf("%s", classes[i].students[classes[i].size].name);
printf("Enter student scores:\n");
for (j = 0; j < MAX_SUBJECTS; j++) {
printf("Subject %d: ", j+1);
scanf("%d", &classes[i].students[classes[i].size].score[j]);
classes[i].students[classes[i].size].total += classes[i].students[classes[i].size].score[j];
}
classes[i].students[classes[i].size].average = (float) classes[i].students[classes[i].size].total / MAX_SUBJECTS;
classes[i].size++;
printf("Student added.\n");
return;
}
}
printf("Class not found.\n");
}
void modify_student() {
char class_name[MAX_NAME_LENGTH], student_name[MAX_NAME_LENGTH];
int i, j;
printf("Enter class name: ");
scanf("%s", class_name);
for (i = 0; i < num_classes; i++) {
if (strcmp(classes[i].name, class_name) == 0) {
printf("Enter student name: ");
scanf("%s", student_name);
for (j = 0; j < classes[i].size; j++) {
if (strcmp(classes[i].students[j].name, student_name) == 0) {
printf("Enter new scores:\n");
for (j = 0; j < MAX_SUBJECTS; j++) {
printf("Subject %d: ", j+1);
scanf("%d", &classes[i].students[j].score[j]);
classes[i].students[j].total += classes[i].students[j].score[j];
}
classes[i].students[j].average = (float) classes[i].students[j].total / MAX_SUBJECTS;
printf("Student modified.\n");
return;
}
}
printf("Student not found.\n");
return;
}
}
printf("Class not found.\n");
}
void print_student_scores() {
char class_name[MAX_NAME_LENGTH];
int i, j;
printf("Enter class name: ");
scanf("%s", class_name);
for (i = 0; i < num_classes; i++) {
if (strcmp(classes[i].name, class_name) == 0) {
for (j = 0; j < classes[i].size; j++) {
printf("%s: ", classes[i].students[j].name);
for (j = 0; j < MAX_SUBJECTS; j++) {
printf("%d ", classes[i].students[j].score[j]);
}
printf("Total: %d, Average: %.2f\n", classes[i].students[j].total, classes[i].students[j].average);
}
return;
}
}
printf("Class not found.\n");
}
void print_student_list() {
char class_name[MAX_NAME_LENGTH];
int i, j;
printf("Enter class name: ");
scanf("%s", class_name);
for (i = 0; i < num_classes; i++) {
if (strcmp(classes[i].name, class_name) == 0) {
printf("Student list:\n");
for (j = 0; j < classes[i].size; j++) {
printf("%s\n", classes[i].students[j].name);
}
return;
}
}
printf("Class not found.\n");
}
void print_menu() {
printf("1. Add class\n");
printf("2. Add student\n");
printf("3. Modify student\n");
printf("4. Print student scores\n");
printf("5. Print student list\n");
printf("6. Quit\n");
}
int main() {
int choice;
do {
print_menu();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_class();
break;
case 2:
add_student();
break;
case 3:
modify_student();
break;
case 4:
print_student_scores();
break;
case 5:
print_student_list();
break;
case 6:
printf("Goodbye.\n");
break;
default:
printf("Invalid choice.\n");
break;
}
} while (choice != 6);
return 0;
}
```
这段代码实现了一个简单的学生成绩管理系统,包括添加班级、添加学生、修改学生、打印学生成绩和打印学生名单等功能。你可以根据自己的需求对代码进行修改和扩展。
阅读全文