c语言班级学生成绩管理系统(1) 输入一个班级的学生的基本信息(包括学号,姓名,性别,5门课程成绩)。 (2) 按姓名或者学号查找、修改、删除和保存各个学生的信息。 (3) 计算每个学生各门功课总分和平均分,按学号或总分排序输出每个学生的基本信息及总分、平均分和名次。 (4) 计算全班各门功课的平均分,显示每门课程中低于平均分的每一个学生的学号,姓名,性别,科目,成绩。 (5) 显示每门科目中,成绩在90分以上的学生信息,以及每门科目中不及格的学生信息。 (6) 用菜单进行管理 (7) 只有正确输入用户名密码才能使用此系统。 (8) 所有内容能够保存到文件中。下次进入系统是从文件中读取原有信息。的代码
时间: 2024-03-14 17:48:05 浏览: 161
抱歉,我是一名自然语言处理模型,无法提供完整的编程代码。但我可以给您提供思路和一些关键代码片段:
1. 学生信息的输入和保存:
```c
struct student {
char id[20];
char name[20];
char gender[10];
float score[5];
float total_score;
float average_score;
int rank;
};
struct student stu[100];
void input_info(int num) {
for (int i = 0; i < num; i++) {
printf("请输入第%d个学生的信息:\n", i+1);
printf("学号:");
scanf("%s", stu[i].id);
printf("姓名:");
scanf("%s", stu[i].name);
printf("性别:");
scanf("%s", stu[i].gender);
printf("五门课程成绩:");
for (int j = 0; j < 5; j++) {
scanf("%f", &stu[i].score[j]);
stu[i].total_score += stu[i].score[j];
}
stu[i].average_score = stu[i].total_score / 5;
stu[i].rank = 1;
}
}
void save_file(int num) {
FILE *fp;
fp = fopen("student_info.txt", "w");
for (int i = 0; i < num; i++) {
fprintf(fp, "%s %s %s ", stu[i].id, stu[i].name, stu[i].gender);
for (int j = 0; j < 5; j++) {
fprintf(fp, "%.1f ", stu[i].score[j]);
}
fprintf(fp, "%.1f %.1f %d\n", stu[i].total_score, stu[i].average_score, stu[i].rank);
}
fclose(fp);
}
```
2. 学生信息的查找、修改和删除:
```c
void search_info(int num, char *keyword) {
for (int i = 0; i < num; i++) {
if (strcmp(stu[i].id, keyword) == 0 || strcmp(stu[i].name, keyword) == 0) {
printf("学号\t姓名\t性别\t语文\t数学\t英语\t物理\t化学\t总分\t平均分\t名次\n");
printf("%s\t%s\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%d\n", stu[i].id, stu[i].name, stu[i].gender, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4], stu[i].total_score, stu[i].average_score, stu[i].rank);
return;
}
}
printf("未找到该学生的信息!\n");
}
void modify_info(int num, char *keyword) {
for (int i = 0; i < num; i++) {
if (strcmp(stu[i].id, keyword) == 0 || strcmp(stu[i].name, keyword) == 0) {
printf("请输入修改后的信息:\n");
printf("学号:");
scanf("%s", stu[i].id);
printf("姓名:");
scanf("%s", stu[i].name);
printf("性别:");
scanf("%s", stu[i].gender);
printf("五门课程成绩:");
for (int j = 0; j < 5; j++) {
scanf("%f", &stu[i].score[j]);
stu[i].total_score += stu[i].score[j];
}
stu[i].average_score = stu[i].total_score / 5;
stu[i].rank = 1;
printf("修改成功!\n");
return;
}
}
printf("未找到该学生的信息!\n");
}
void delete_info(int *num, char *keyword) {
for (int i = 0; i < *num; i++) {
if (strcmp(stu[i].id, keyword) == 0 || strcmp(stu[i].name, keyword) == 0) {
for (int j = i; j < *num - 1; j++) {
stu[j] = stu[j + 1];
}
(*num)--;
printf("删除成功!\n");
return;
}
}
printf("未找到该学生的信息!\n");
}
```
3. 学生信息的排序:
```c
void sort_by_id(int num) {
for (int i = 0; i < num; i++) {
for (int j = i + 1; j < num; j++) {
if (strcmp(stu[i].id, stu[j].id) > 0) {
struct student temp = stu[i];
stu[i] = stu[j];
stu[j] = temp;
}
}
}
}
void sort_by_total_score(int num) {
for (int i = 0; i < num; i++) {
for (int j = i + 1; j < num; j++) {
if (stu[i].total_score < stu[j].total_score) {
struct student temp = stu[i];
stu[i] = stu[j];
stu[j] = temp;
}
}
}
for (int i = 0; i < num; i++) {
if (i == 0) {
stu[i].rank = 1;
} else {
if (stu[i].total_score == stu[i - 1].total_score) {
stu[i].rank = stu[i - 1].rank;
} else {
stu[i].rank = i + 1;
}
}
}
}
```
4. 学生信息的统计和输出:
```c
void show_low_score(int num, float *avg_score) {
for (int i = 0; i < 5; i++) {
printf("成绩低于平均分的学生信息(%s):\n", course[i]);
for (int j = 0; j < num; j++) {
if (stu[j].score[i] < avg_score[i]) {
printf("%s\t%s\t%s\t%.1f\n", stu[j].id, stu[j].name, stu[j].gender, stu[j].score[i]);
}
}
}
}
void show_high_score(int num) {
for (int i = 0; i < 5; i++) {
printf("成绩在90分以上的学生信息(%s):\n", course[i]);
for (int j = 0; j < num; j++) {
if (stu[j].score[i] >= 90) {
printf("%s\t%s\t%s\t%.1f\n", stu[j].id, stu[j].name, stu[j].gender, stu[j].score[i]);
}
}
}
}
void show_failed(int num) {
for (int i = 0; i < 5; i++) {
printf("不及格的学生信息(%s):\n", course[i]);
for (int j = 0; j < num; j++) {
if (stu[j].score[i] < 60) {
printf("%s\t%s\t%s\t%.1f\n", stu[j].id, stu[j].name, stu[j].gender, stu[j].score[i]);
}
}
}
}
void calculate_avg_score(int num, float *avg_score) {
for (int i = 0; i < 5; i++) {
float sum = 0;
for (int j = 0; j < num; j++) {
sum += stu[j].score[i];
}
avg_score[i] = sum / num;
}
printf("五门课程的平均分分别为:%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n", avg_score[0], avg_score[1], avg_score[2], avg_score[3], avg_score[4]);
}
```
5. 用户名密码的验证:
```c
void login() {
char username[20], password[20];
printf("请输入用户名和密码:\n");
printf("用户名:");
scanf("%s", username);
printf("密码:");
scanf("%s", password);
if (strcmp(username, "admin") == 0 && strcmp(password, "123456") == 0) {
printf("登录成功!\n");
} else {
printf("用户名或密码错误!\n");
login();
}
}
```
6. 主菜单和文件读取:
```c
void main_menu() {
int num = 0;
float avg_score[5] = {0};
FILE *fp;
fp = fopen("student_info.txt", "r");
if (fp != NULL) {
while (!feof(fp)) {
fscanf(fp, "%s %s %s ", stu[num].id, stu[num].name, stu[num].gender);
for (int j = 0; j < 5; j++) {
fscanf(fp, "%f ", &stu[num].score[j]);
stu[num].total_score += stu[num].score[j];
}
stu[num].average_score = stu[num].total_score / 5;
stu[num].rank = 1;
num++;
}
fclose(fp);
}
login();
int choice;
while (1) {
printf("\n学生成绩管理系统\n");
printf("1、输入学生信息\n");
printf("2、按姓名或学号查找学生信息\n");
printf("3、修改学生信息\n");
printf("4、删除学生信息\n");
printf("5、计算每个学生各门功课总分和平均分并排序输出\n");
printf("6、计算全班各门功课的平均分并显示成绩低于平均分的学生信息\n");
printf("7、显示每门科目中,成绩在90分以上的学生信息和不及格的学生信息\n");
printf("8、保存信息到文件中\n");
printf("9、退出系统\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
input_info(num);
break;
case 2:
char keyword[20];
printf("请输入要查找的学生姓名或学号:");
scanf("%s", keyword);
search_info(num, keyword);
break;
case 3:
char modify_keyword[20];
printf("请输入要修改的学生姓名或学号:");
scanf("%s", modify_keyword);
modify_info(num, modify_keyword);
break;
case 4:
char delete_keyword[20];
printf("请输入要删除的学生姓名或学号:");
scanf("%s", delete_keyword);
delete_info(&num, delete_keyword);
break;
case 5:
sort_by_total_score(num);
printf("学号\t姓名\t性别\t语文\t数学\t英语\t物理\t化学\t总分\t平均分\t名次\n");
for (int i = 0; i < num; i++) {
printf("%s\t%s\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%d\n", stu[i].id, stu[i].name, stu[i].gender, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3], stu[i].score[4], stu[i].total_score, stu[i].average_score, stu[i].rank);
}
break;
case 6:
calculate_avg_score(num, avg_score);
show_low_score(num, avg_score);
break;
case 7:
show_high_score(num);
show_failed(num);
break;
case 8:
save_file(num);
printf("保存成功!\n");
break;
case 9:
return;
default:
printf("输入有误,请重新选择!\n");
break;
}
}
}
```
阅读全文