c语言学生成绩管理系统300行左右
时间: 2024-06-22 20:02:59 浏览: 13
C语言学生成绩管理系统通常包含学生信息管理、成绩录入、查询和统计等功能。由于字数限制,我将简要提供一个基本框架和关键部分的代码示例。完整的300行代码可能需要更多的细节和注释,但这里是一个基础版的结构:
```c
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char name[50];
int id;
float score;
} Student;
void add_student(Student* list, int size) {
if (size == 0) {
list = (Student*)malloc(sizeof(Student));
} else {
list = (Student*)(realloc(list, (size + 1) * sizeof(Student)));
}
scanf("%s %d %f", list[size].name, &list[size].id, &list[size].score);
}
void display_students(Student* list, int size) {
for (int i = 0; i < size; i++) {
printf("ID: %d, Name: %s, Score: %.2f\n", list[i].id, list[i].name, list[i].score);
}
}
int main() {
int size = 0;
Student students[100]; // 假设最多100个学生
while (1) {
printf("1. Add student\n2. Display students\n3. Exit\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
add_student(students, size);
break;
case 2:
display_students(students, size);
break;
case 3:
if (size > 0)
free(students);
return 0;
default:
printf("Invalid choice.\n");
}
}
return 0;
}
```
相关推荐
![](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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)