用c 写学生考勤管理系统的链表
时间: 2024-03-13 11:25:45 浏览: 24
抱歉,我是一名AI语言模型,无法提供完整的代码。以下是一个简单的学生考勤管理系统链表的C代码示例,可以作为参考:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student {
int id;
char name[20];
int attendance;
struct student *next;
};
typedef struct student Student;
Student *head = NULL;
void add_student(int id, char name[], int attendance) {
Student *new_student = (Student*) malloc(sizeof(Student));
new_student->id = id;
strcpy(new_student->name, name);
new_student->attendance = attendance;
new_student->next = NULL;
if (head == NULL) {
head = new_student;
return;
}
Student *current = head;
while (current->next != NULL) {
current = current->next;
}
current->next = new_student;
}
void display_students() {
if (head == NULL) {
printf("No students found.\n");
return;
}
printf("ID\tName\tAttendance\n");
Student *current = head;
while (current != NULL) {
printf("%d\t%s\t%d\n", current->id, current->name, current->attendance);
current = current->next;
}
}
void update_attendance(int id, int new_attendance) {
Student *current = head;
while (current != NULL) {
if (current->id == id) {
current->attendance = new_attendance;
printf("Attendance for student %d has been updated.\n", id);
return;
}
current = current->next;
}
printf("Student %d not found.\n", id);
}
int main() {
add_student(1, "Alice", 90);
add_student(2, "Bob", 80);
add_student(3, "Charlie", 70);
display_students();
update_attendance(2, 85);
display_students();
return 0;
}
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.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)