用C语言以列表的形式来进行一个学籍信息管理系统
时间: 2024-03-17 13:40:14 浏览: 23
好的,以下是一个简单的学籍信息管理系统的代码示例,使用单向链表来存储学生信息:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student {
char name[20];
int age;
char gender[5];
int id;
struct student* next;
} Student;
Student* create_student(char name[], int age, char gender[], int id)
{
Student* new_student = (Student*)malloc(sizeof(Student));
strcpy(new_student->name, name);
new_student->age = age;
strcpy(new_student->gender, gender);
new_student->id = id;
new_student->next = NULL;
return new_student;
}
void add_student(Student** head, Student* new_student)
{
if (*head == NULL) {
*head = new_student;
} else {
Student* current = *head;
while (current->next != NULL) {
current = current->next;
}
current->next = new_student;
}
}
void print_student(Student* student)
{
printf("Name: %s\n", student->name);
printf("Age: %d\n", student->age);
printf("Gender: %s\n", student->gender);
printf("ID: %d\n", student->id);
}
void print_all_students(Student* head)
{
Student* current = head;
while (current != NULL) {
print_student(current);
printf("\n");
current = current->next;
}
}
int main()
{
Student* head = NULL;
Student* alice = create_student("Alice", 18, "F", 1001);
add_student(&head, alice);
Student* bob = create_student("Bob", 19, "M", 1002);
add_student(&head, bob);
Student* charlie = create_student("Charlie", 20, "M", 1003);
add_student(&head, charlie);
print_all_students(head);
return 0;
}
```
这个代码示例实现了一个简单的学籍信息管理系统,可以添加、打印所有学生信息。你可以根据需求进行扩展,例如删除学生、按条件查询学生等功能。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)