学生成绩管理系统c文件
时间: 2023-12-22 10:55:19 浏览: 22
抱歉,我无法提供完整的学生成绩管理系统 C 文件。但是,以下是一个基本的学生成绩管理系统的 C 代码示例,用于参考和学习:
```c
#include <stdio.h>
#include <stdlib.h>
#define MAX_STUDENTS 100
struct student {
int id;
char name[20];
int marks[5];
float average;
char grade;
};
struct student students[MAX_STUDENTS];
int num_students = 0;
void print_menu() {
printf("1. Add student\n");
printf("2. Display all students\n");
printf("3. Search for a student\n");
printf("4. Calculate average and grade for all students\n");
printf("5. Exit\n");
}
void add_student() {
if (num_students == MAX_STUDENTS) {
printf("Maximum number of students reached.\n");
return;
}
struct student s;
printf("Enter student ID: ");
scanf("%d", &s.id);
printf("Enter student name: ");
scanf("%s", s.name);
for (int i = 0; i < 5; i++) {
printf("Enter marks for subject %d: ", i + 1);
scanf("%d", &s.marks[i]);
}
students[num_students++] = s;
}
void display_all_students() {
if (num_students == 0) {
printf("No students found.\n");
return;
}
printf("ID\tName\tSubject 1\tSubject 2\tSubject 3\tSubject 4\tSubject 5\n");
printf("--------------------------------------------------------------------------------\n");
for (int i = 0; i < num_students; i++) {
struct student s = students[i];
printf("%d\t%s\t", s.id, s.name);
for (int j = 0; j < 5; j++) {
printf("%d\t\t", s.marks[j]);
}
printf("\n");
}
}
void search_student() {
int id;
printf("Enter student ID: ");
scanf("%d", &id);
for (int i = 0; i < num_students; i++) {
struct student s = students[i];
if (s.id == id) {
printf("ID\tName\tSubject 1\tSubject 2\tSubject 3\tSubject 4\tSubject 5\n");
printf("--------------------------------------------------------------------------------\n");
printf("%d\t%s\t", s.id, s.name);
for (int j = 0; j < 5; j++) {
printf("%d\t\t", s.marks[j]);
}
printf("\n");
return;
}
}
printf("Student not found.\n");
}
void calculate_average_and_grade() {
if (num_students == 0) {
printf("No students found.\n");
return;
}
for (int i = 0; i < num_students; i++) {
struct student *s = &students[i];
int total_marks = 0;
for (int j = 0; j < 5; j++) {
total_marks += s->marks[j];
}
s->average = (float) total_marks / 5.0;
if (s->average >= 90) {
s->grade = 'A';
} else if (s->average >= 80) {
s->grade = 'B';
} else if (s->average >= 70) {
s->grade = 'C';
} else if (s->average >= 60) {
s->grade = 'D';
} else {
s->grade = 'F';
}
}
printf("ID\tName\tAverage\tGrade\n");
printf("----------------------------------\n");
for (int i = 0; i < num_students; i++) {
struct student s = students[i];
printf("%d\t%s\t%.2f\t%c\n", s.id, s.name, s.average, s.grade);
}
}
int main() {
int choice;
do {
print_menu();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
display_all_students();
break;
case 3:
search_student();
break;
case 4:
calculate_average_and_grade();
break;
case 5:
printf("Exiting...\n");
break;
default:
printf("Invalid choice. Please try again.\n");
break;
}
} while (choice != 5);
return 0;
}
```
该代码实现了以下功能:
1. 添加学生信息
2. 显示所有学生信息
3. 搜索学生信息
4. 计算所有学生的平均分和等级
5. 退出程序
该代码仅供参考,您可以根据需要进行修改和优化。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)