用结构体写一个学生学籍管理系统
时间: 2023-12-29 19:25:17 浏览: 51
好的,这里是一个简单的学生学籍管理系统的结构体实现:
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 100 // 最大学生数
typedef struct {
int id; // 学号
char name[20]; // 姓名
int age; // 年龄
char sex[5]; // 性别
int score; // 成绩
} Student;
typedef struct {
Student student[MAX_STUDENTS]; // 存储学生信息的数组
int count; // 当前学生数
} StudentList;
int main() {
StudentList list; // 创建一个学生列表
// 初始化学生列表
list.count = 0;
// 添加学生信息
Student s1 = { 1001, "张三", 20, "男", 90 };
list.student[list.count++] = s1;
Student s2 = { 1002, "李四", 21, "女", 85 };
list.student[list.count++] = s2;
// 输出学生信息
printf("学号\t姓名\t年龄\t性别\t成绩\n");
for (int i = 0; i < list.count; i++) {
Student s = list.student[i];
printf("%d\t%s\t%d\t%s\t%d\n", s.id, s.name, s.age, s.sex, s.score);
}
return 0;
}
```
这个实现使用了两个结构体,一个是 `Student` 结构体,表示一个学生的信息,包括学号、姓名、年龄、性别和成绩;另一个是 `StudentList` 结构体,表示一个学生列表,包括一个 `Student` 数组和一个计数器 `count`,用于记录当前学生数。
在 `main()` 函数中,我们首先创建了一个空的学生列表,然后依次添加了两个学生信息,并输出了所有学生的信息。这里只是一个简单的示例,实际上学生管理系统的功能要更加复杂,需要进行增删改查等操作,并且需要使用文件或数据库等方式进行持久化存储。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)