c语言代码,图书馆自习位预约 ,定义自习位信息, 包括自习位编号、所在楼层和室号、阅览室名称、配备的设施(有无电源、有无台灯等)、自习位状态(空/已预约)等 ,定义学生基本信息,包括学生学号、登录密码、学生姓名、卜学院等 ,模拟学生预约自 习位流程 ,统计指定日期段图书馆自习 位利用率 ,统计指安日期段学生 预约排行榜
时间: 2023-03-20 12:03:18 浏览: 71
下面是一个基于C语言的简单实现,用于管理图书馆的自习位预约系统:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX_STUDENTS 1000 // 最大学生数
#define MAX_SEATS 100 // 最大自习位数
// 自习位信息
struct Seat {
int id; // 自习位编号
int floor; // 自习位所在楼层
char room[20]; // 自习位室号
char library[20]; // 阅览室名称
int has_power; // 是否有电源
int has_lamp; // 是否有台灯
int is_reserved; // 自习位是否已经被预约
};
// 学生信息
struct Student {
char id[20]; // 学生学号
char password[20]; // 学生登录密码
char name[20]; // 学生姓名
char college[20]; // 学生所在学院
int reservations[MAX_SEATS]; // 学生预约的自习位编号
int num_reservations; // 学生已经预约的自习位数
};
// 所有学生和自习位
struct Seat seats[MAX_SEATS];
struct Student students[MAX_STUDENTS];
int num_seats = 0;
int num_students = 0;
// 显示自习位信息
void display_seat(struct Seat *seat) {
printf("ID:%d\n", seat->id);
printf("所在楼层:%d\n", seat->floor);
printf("室号:%s\n", seat->room);
printf("阅览室名称:%s\n", seat->library);
printf("是否有电源:%s\n", seat->has_power ? "有" : "无");
printf("是否有台灯:%s\n", seat->has_lamp ? "有" : "无");
printf("状态:%s\n", seat->is_reserved ? "已预约" : "空");
printf("\n");
}
// 显示学生信息
void display_student(struct Student *student) {
printf("学号:%s\n", student->id);
printf("姓名:%s\n", student->name);
printf("学院:%s\n", student->college);
printf("已预约自习位:\n");
for (int i = 0; i < student->num_reservations; i++) {
printf("%d ", student->reservations[i]);
}
printf("\n");
}
// 预约自习位
void reserve_seat(struct Seat *seat, struct Student *student) {
if (seat->is_reserved) {
printf("该自习位已经被预约!\n");
return;
}
if (student->num_reservations == MAX_SEATS) {
printf("你已经预约了%d个自习位,不能再预约了!\n", MAX_SEATS);
return;
}
seat->is_reserved = 1;
student->reservations[student->num_reservations++] = seat->id;
printf("预约成功!\n");
}
// 统计指定日期段自