机房预约管理系统c语言编写
时间: 2023-07-03 13:08:34 浏览: 89
机房预约管理系统可以分为两个部分,一个是前台用户操作界面,另一个是后台管理员操作界面。下面是一个简单的机房预约管理系统的c语言实现示例,你可以根据需要进行修改优化。
前台用户操作界面:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX_ROOM_NUM 10
#define MAX_NAME_LEN 20
#define MAX_TIME_SLOT 10
typedef struct {
char name[MAX_NAME_LEN];
int room_num;
int time_slot;
} Reservation;
int room_state[MAX_ROOM_NUM][MAX_TIME_SLOT]; // 机房预约状态,0表示空闲,1表示已预约
void init_room_state() { // 初始化机房预约状态
memset(room_state, 0, sizeof(room_state));
}
void print_menu() { // 打印操作菜单
printf("-------Menu-------\n");
printf("1. Make a reservation\n");
printf("2. Cancel a reservation\n");
printf("3. Check reservation status\n");
printf("4. Exit\n");
printf("-------------------\n");
}
int check_room_available(int room_num, int time_slot) { // 检查机房是否可用
if (room_num < 1 || room_num > MAX_ROOM_NUM) {
printf("Invalid room number!\n");
return 0;
}
if (time_slot < 1 || time_slot > MAX_TIME_SLOT) {
printf("Invalid time slot!\n");
return 0;
}
if (room_state[room_num - 1][time_slot - 1] == 1) {
printf("This room is not available at this time slot!\n");
return 0;
}
return 1;
}
void make_reservation() { // 预约机房
Reservation res;
printf("Please enter your name: ");
scanf("%s", res.name);
printf("Please enter the room number (1~%d): ", MAX_ROOM_NUM);
scanf("%d", &res.room_num);
printf("Please enter the time slot (1~%d): ", MAX_TIME_SLOT);
scanf("%d", &res.time_slot);
if (check_room_available(res.room_num, res.time_slot)) {
room_state[res.room_num - 1][res.time_slot - 1] = 1;
printf("Reservation successful!\n");
}
}
void cancel_reservation() { // 取消预约
char name[MAX_NAME_LEN];
int room_num, time_slot;
printf("Please enter your name: ");
scanf("%s", name);
for (int i = 0; i < MAX_ROOM_NUM; i++) {
for (int j = 0; j < MAX_TIME_SLOT; j++) {
if (room_state[i][j] == 1 && strcmp(name, ReservationList[i][j].name) == 0) {
room_num = i + 1;
time_slot = j + 1;
room_state[i][j] = 0;
printf("Reservation cancelled!\n");
return;
}
}
}
printf("You have no reservation!\n");
}
void check_reservation_status() { // 查看预约状态
printf("Room status:\n");
printf("Room\t");
for (int i = 1; i <= MAX_TIME_SLOT; i++) {
printf("%d\t", i);
}
printf("\n");
for (int i = 0; i < MAX_ROOM_NUM; i++) {
printf("%d\t", i + 1);
for (int j = 0; j < MAX_TIME_SLOT; j++) {
if (room_state[i][j] == 0) {
printf("O\t");
} else {
printf("X\t");
}
}
printf("\n");
}
}
int main() {
init_room_state();
int choice;
while (1) {
print_menu();
printf("Please enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
make_reservation();
break;
case 2:
cancel_reservation();
break;
case 3:
check_reservation_status();
break;
case 4:
return 0;
default:
printf("Invalid choice!\n");
}
}
return 0;
}
```
后台管理员操作界面:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX_ROOM_NUM 10
#define MAX_NAME_LEN 20
#define MAX_TIME_SLOT 10
typedef struct {
char name[MAX_NAME_LEN];
int room_num;
int time_slot;
} Reservation;
int room_state[MAX_ROOM_NUM][MAX_TIME_SLOT]; // 机房预约状态,0表示空闲,1表示已预约
void init_room_state() { // 初始化机房预约状态
memset(room_state, 0, sizeof(room_state));
}
void print_menu() { // 打印操作菜单
printf("-------Menu-------\n");
printf("1. Check reservation status\n");
printf("2. Exit\n");
printf("-------------------\n");
}
void check_reservation_status() { // 查看预约状态
printf("Room status:\n");
printf("Room\t");
for (int i = 1; i <= MAX_TIME_SLOT; i++) {
printf("%d\t", i);
}
printf("\n");
for (int i = 0; i < MAX_ROOM_NUM; i++) {
printf("%d\t", i + 1);
for (int j = 0; j < MAX_TIME_SLOT; j++) {
if (room_state[i][j] == 0) {
printf("O\t");
} else {
printf("X\t");
}
}
printf("\n");
}
}
int main() {
init_room_state();
int choice;
while (1) {
print_menu();
printf("Please enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
check_reservation_status();
break;
case 2:
return 0;
default:
printf("Invalid choice!\n");
}
}
return 0;
}
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)