复杂的学生签到考勤系统C语言代码
时间: 2023-08-04 21:07:08 浏览: 107
以下是一个简单的基于C语言的学生签到考勤系统代码。这个代码实现了基本的签到功能,包括输入学生信息、保存学生信息、识别学生信息、记录签到信息等。
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENT 1000
#define MAX_NAME 30
struct Student {
char name[MAX_NAME];
int id;
int age;
char gender;
int isPresent;
};
// 根据名字查找学生
int findStudentByName(struct Student students[], int n, char name[]) {
for (int i = 0; i < n; i++) {
if (strcmp(students[i].name, name) == 0) {
return i;
}
}
return -1;
}
// 根据ID查找学生
int findStudentById(struct Student students[], int n, int id) {
for (int i = 0; i < n; i++) {
if (students[i].id == id) {
return i;
}
}
return -1;
}
// 添加学生
void addStudent(struct Student students[], int *n) {
struct Student student;
printf("请输入学生姓名:");
scanf("%s", student.name);
printf("请输入学生ID:");
scanf("%d", &student.id);
printf("请输入学生年龄:");
scanf("%d", &student.age);
printf("请输入学生性别:");
scanf("%s", &student.gender);
student.isPresent = 0;
students[*n] = student;
(*n)++;
}
// 识别学生信息
void recognizeStudent(struct Student students[], int n) {
char name[MAX_NAME];
printf("请输入学生姓名:");
scanf("%s", name);
int index = findStudentByName(students, n, name);
if (index == -1) {
printf("未找到该学生!\n");
} else {
printf("学生信息:\n");
printf("姓名:%s\n", students[index].name);
printf("ID:%d\n", students[index].id);
printf("年龄:%d\n", students[index].age);
printf("性别:%c\n", students[index].gender);
}
}
// 记录签到信息
void recordAttendance(struct Student students[], int n) {
char name[MAX_NAME];
printf("请输入学生姓名:");
scanf("%s", name);
int index = findStudentByName(students, n, name);
if (index == -1) {
printf("未找到该学生!\n");
} else {
students[index].isPresent = 1;
printf("学生:%s 签到成功!\n", name);
}
}
// 显示所有学生信息
void showAllStudents(struct Student students[], int n) {
printf("所有学生信息:\n");
for (int i = 0; i < n; i++) {
printf("姓名:%s,ID:%d,年龄:%d,性别:%c,是否签到:%s\n", students[i].name, students[i].id, students[i].age, students[i].gender, students[i].isPresent ? "是" : "否");
}
}
int main() {
struct Student students[MAX_STUDENT];
int n = 0;
int choice;
do {
printf("请选择操作:\n");
printf("1.添加学生\n");
printf("2.识别学生信息\n");
printf("3.记录签到信息\n");
printf("4.显示所有学生信息\n");
printf("5.退出\n");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent(students, &n);
break;
case 2:
recognizeStudent(students, n);
break;
case 3:
recordAttendance(students, n);
break;
case 4:
showAllStudents(students, n);
break;
case 5:
break;
default:
printf("无效操作!\n");
break;
}
} while (choice != 5);
return 0;
}
```
这个代码使用结构体存储学生信息,通过输入进行添加学生、识别学生信息、记录签到信息等操作。同时,代码也提供了一个简单的菜单来帮助用户进行操作选择。
阅读全文