那你可以用c语言编写一个学生成绩管理系统吗 有数学 语文 英语 ,可以求每个学生的和,可以删除添加学生, 求最高分
时间: 2024-03-23 08:41:20 浏览: 58
是的,我可以用C语言编写一个学生成绩管理系统。下面是一个简单的实现,可以实现添加学生、删除学生、计算每个学生的总分、计算每个科目的最高分等功能。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAME_LEN 20
#define MAX_STUDENT_NUM 100
typedef struct student {
char name[MAX_NAME_LEN];
int math_score;
int chinese_score;
int english_score;
} Student;
Student students[MAX_STUDENT_NUM];
int student_count = 0;
void add_student() {
if (student_count >= MAX_STUDENT_NUM) {
printf("Too many students!\n");
return;
}
Student new_student;
printf("Please enter the name of the student: ");
scanf("%s", new_student.name);
printf("Please enter the math score of the student: ");
scanf("%d", &new_student.math_score);
printf("Please enter the Chinese score of the student: ");
scanf("%d", &new_student.chinese_score);
printf("Please enter the English score of the student: ");
scanf("%d", &new_student.english_score);
students[student_count++] = new_student;
printf("Student added successfully!\n");
}
void delete_student() {
char name[MAX_NAME_LEN];
printf("Please enter the name of the student you want to delete: ");
scanf("%s", name);
int found = 0;
for (int i = 0; i < student_count; i++) {
if (strcmp(students[i].name, name) == 0) {
found = 1;
for (int j = i; j < student_count - 1; j++) {
students[j] = students[j + 1];
}
student_count--;
printf("Student deleted successfully!\n");
break;
}
}
if (!found) {
printf("Student not found!\n");
}
}
void print_student(Student student) {
printf("%-10s%-10d%-10d%-10d\n", student.name, student.math_score, student.chinese_score, student.english_score);
}
void print_all_students() {
printf("%-10s%-10s%-10s%-10s\n", "Name", "Math", "Chinese", "English");
for (int i = 0; i < student_count; i++) {
print_student(students[i]);
}
}
int get_total_score(Student student) {
return student.math_score + student.chinese_score + student.english_score;
}
void calculate_total_score() {
printf("%-10s%-10s\n", "Name", "Total");
for (int i = 0; i < student_count; i++) {
printf("%-10s%-10d\n", students[i].name, get_total_score(students[i]));
}
}
int get_max_score(int (*get_score)(Student)) {
int max_score = -1;
for (int i = 0; i < student_count; i++) {
int score = get_score(students[i]);
if (score > max_score) {
max_score = score;
}
}
return max_score;
}
void calculate_max_score() {
printf("%-10s%-10d\n", "Math", get_max_score(&((int (*)(Student))get_total_score))));
printf("%-10s%-10d\n", "Chinese", get_max_score(&((int (*)(Student))&students[0].chinese_score))));
printf("%-10s%-10d\n", "English", get_max_score(&((int (*)(Student))&students[0].english_score))));
}
int main() {
while (1) {
printf("\n");
printf("1. Add student\n");
printf("2. Delete student\n");
printf("3. Print all students\n");
printf("4. Calculate total score\n");
printf("5. Calculate max score\n");
printf("6. Exit\n");
printf("Please enter your choice: ");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
delete_student();
break;
case 3:
print_all_students();
break;
case 4:
calculate_total_score();
break;
case 5:
calculate_max_score();
break;
case 6:
exit(0);
default:
printf("Invalid choice!\n");
}
}
return 0;
}
```
注意,这只是一个简单的实现,可能存在一些不足和漏洞。如果您需要更为完善的学生成绩管理系统,建议您根据自己的需求进行定制化开发。
阅读全文
相关推荐


















