设计一个酒店管理系统用c语言代码实现功能:登记入住, 结账,查询客房信息, 客房信息打印 ,客房统计 ,退出
时间: 2024-03-10 13:46:59 浏览: 75
好的,以下是一个简单的酒店管理系统的C语言代码实现:
```
#include <stdio.h>
struct hotel {
int room_num;
int occupied; // 0表示空房,1表示已入住
float rate;
};
void check_in(struct hotel rooms[], int room_num) {
int i;
for (i = 0; i < room_num; i++) {
if (rooms[i].occupied == 0) {
rooms[i].occupied = 1;
printf("请输入房间号(1-%d):", room_num);
scanf("%d", &rooms[i].room_num);
printf("请输入房间价格:");
scanf("%f", &rooms[i].rate);
printf("登记成功!\n");
return;
}
}
printf("抱歉,没有空房间!\n");
}
void check_out(struct hotel rooms[], int room_num) {
int i, room;
printf("请输入要结账的房间号:");
scanf("%d", &room);
for (i = 0; i < room_num; i++) {
if (rooms[i].room_num == room && rooms[i].occupied == 1) {
rooms[i].occupied = 0;
printf("结账成功!\n");
return;
}
}
printf("该房间未被入住或房间号错误!\n");
}
void print_info(struct hotel rooms[], int room_num) {
int i;
for (i = 0; i < room_num; i++) {
printf("房间号:%d,价格:%.2f,状态:%s\n", rooms[i].room_num, rooms[i].rate, rooms[i].occupied ? "已入住" : "空房");
}
}
void room_stat(struct hotel rooms[], int room_num) {
int i, count = 0;
float total = 0;
for (i = 0; i < room_num; i++) {
if (rooms[i].occupied) {
count++;
total += rooms[i].rate;
}
}
printf("已入住房间数:%d,入住率:%.2f%%,总收入:%.2f\n", count, (float)count / room_num * 100, total);
}
int main() {
int choice;
const int room_num = 10;
struct hotel rooms[room_num] = { 0 };
printf("***欢迎使用酒店管理系统***\n");
while (1) {
printf("1.登记入住 2.结账 3.查询客房信息 4.客房信息打印 5.客房统计 6.退出\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
check_in(rooms, room_num);
break;
case 2:
check_out(rooms, room_num);
break;
case 3:
print_info(rooms, room_num);
break;
case 4:
print_info(rooms, room_num);
break;
case 5:
room_stat(rooms, room_num);
break;
case 6:
printf("谢谢使用,再见!\n");
return 0;
default:
printf("请输入正确的选项!\n");
break;
}
}
return 0;
}
```
以上代码实现了一个简单的酒店管理系统,包括登记入住、结账、查询客房信息、客房信息打印、客房统计和退出功能。用户可以根据自己的需求选择相应的功能。
阅读全文