生成c语言代码:对学生成绩管理的简单模拟,用菜单选择方式完成下列功能: 输入学生数据; 输出学生数据;学生数据查询;添加学生数据;修改学生数据;删除学生数据,学生成绩统计,其中学生成绩统计功能对给出 n 个学生的考试成绩(每条信息由姓名和分数组成)。
时间: 2024-03-28 22:39:22 浏览: 44
学生成绩管理系统(c语言实现)
5星 · 资源好评率100%
以下是对学生成绩管理的简单模拟的C语言代码:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
struct Student {
char name[20];
int score;
};
struct Student students[MAX_STUDENTS];
int num_students = 0;
void input_student_data() {
printf("请输入学生姓名和成绩(用空格分隔):\n");
scanf("%s %d", students[num_students].name, &students[num_students].score);
num_students++;
printf("输入成功!\n");
}
void output_student_data() {
printf("学生数据如下:\n");
for (int i = 0; i < num_students; i++) {
printf("%s %d\n", students[i].name, students[i].score);
}
}
void search_student_data() {
char name[20];
printf("请输入要查询的学生姓名:\n");
scanf("%s", name);
for (int i = 0; i < num_students; i++) {
if (strcmp(students[i].name, name) == 0) {
printf("%s %d\n", students[i].name, students[i].score);
return;
}
}
printf("未找到该学生!\n");
}
void add_student_data() {
printf("请输入要添加的学生姓名和成绩(用空格分隔):\n");
scanf("%s %d", students[num_students].name, &students[num_students].score);
num_students++;
printf("添加成功!\n");
}
void modify_student_data() {
char name[20];
printf("请输入要修改的学生姓名:\n");
scanf("%s", name);
for (int i = 0; i < num_students; i++) {
if (strcmp(students[i].name, name) == 0) {
printf("请输入修改后的学生姓名和成绩(用空格分隔):\n");
scanf("%s %d", students[i].name, &students[i].score);
printf("修改成功!\n");
return;
}
}
printf("未找到该学生!\n");
}
void delete_student_data() {
char name[20];
printf("请输入要删除的学生姓名:\n");
scanf("%s", name);
for (int i = 0; i < num_students; i++) {
if (strcmp(students[i].name, name) == 0) {
for (int j = i; j < num_students - 1; j++) {
strcpy(students[j].name, students[j+1].name);
students[j].score = students[j+1].score;
}
num_students--;
printf("删除成功!\n");
return;
}
}
printf("未找到该学生!\n");
}
void statistics_student_data() {
int sum = 0;
int max_score = students[0].score;
int min_score = students[0].score;
for (int i = 0; i < num_students; i++) {
sum += students[i].score;
if (students[i].score > max_score) {
max_score = students[i].score;
}
if (students[i].score < min_score) {
min_score = students[i].score;
}
}
printf("学生总数:%d\n", num_students);
printf("平均分数:%d\n", sum / num_students);
printf("最高分数:%d\n", max_score);
printf("最低分数:%d\n", min_score);
}
void menu() {
printf("**********学生成绩管理系统**********\n");
printf("1.输入学生数据\n");
printf("2.输出学生数据\n");
printf("3.学生数据查询\n");
printf("4.添加学生数据\n");
printf("5.修改学生数据\n");
printf("6.删除学生数据\n");
printf("7.学生成绩统计\n");
printf("8.退出\n");
printf("请选择操作:\n");
}
int main() {
int choice = 0;
while (1) {
menu();
scanf("%d", &choice);
switch (choice) {
case 1:
input_student_data();
break;
case 2:
output_student_data();
break;
case 3:
search_student_data();
break;
case 4:
add_student_data();
break;
case 5:
modify_student_data();
break;
case 6:
delete_student_data();
break;
case 7:
statistics_student_data();
break;
case 8:
printf("退出成功!\n");
return 0;
default:
printf("输入有误,请重新输入!\n");
break;
}
}
return 0;
}
```
阅读全文