C语言开发的酒店管理系统
时间: 2023-10-08 22:08:01 浏览: 153
好的,酒店管理系统一般包括客房管理、订单管理、财务管理等模块,下面是一个简单的C语言实现的酒店管理系统的示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ROOMS 20 //最大房间数
#define MAX_NAME_LENGTH 20 //客户名字最大长度
#define MAX_ORDERS 100 //最大订单数
//定义订单结构体
typedef struct {
int room_number; //房间号
char customer_name[MAX_NAME_LENGTH]; //客户名字
int days; //入住天数
int price; //房费
} Order;
//定义房间结构体
typedef struct {
int number; //房间号
int price; //房间价格
int is_occupied; //是否被占用
char customer_name[MAX_NAME_LENGTH]; //客户名字
} Room;
//初始化房间
void init_rooms(Room* rooms, int n) {
int i;
for (i = 0; i < n; i++) {
rooms[i].number = i + 1;
rooms[i].price = 100;
rooms[i].is_occupied = 0;
strcpy(rooms[i].customer_name, "");
}
}
//打印房间信息
void print_rooms(Room* rooms, int n) {
int i;
printf("房间信息:\n");
for (i = 0; i < n; i++) {
printf("房间号:%d,价格:%d,是否占用:%s,客户名字:%s\n",
rooms[i].number, rooms[i].price, rooms[i].is_occupied ? "是" : "否", rooms[i].customer_name);
}
}
//查找房间
Room* find_room(Room* rooms, int n, int room_number) {
int i;
for (i = 0; i < n; i++) {
if (rooms[i].number == room_number)
return &rooms[i];
}
return NULL;
}
//添加订单
void add_order(Order* orders, int* count, int room_number, char* customer_name, int days, int price) {
orders[*count].room_number = room_number;
strcpy(orders[*count].customer_name, customer_name);
orders[*count].days = days;
orders[*count].price = price;
(*count)++;
}
//打印订单信息
void print_orders(Order* orders, int count) {
int i;
printf("订单信息:\n");
for (i = 0; i < count; i++) {
printf("房间号:%d,客户名字:%s,入住天数:%d,房费:%d\n",
orders[i].room_number, orders[i].customer_name, orders[i].days, orders[i].price);
}
}
//计算订单总金额
int calculate_total_price(Order* orders, int count) {
int i, total_price = 0;
for (i = 0; i < count; i++) {
total_price += orders[i].price;
}
return total_price;
}
int main() {
Room rooms[MAX_ROOMS]; //房间数组
int n = 10; //房间数
Order orders[MAX_ORDERS]; //订单数组
int order_count = 0; //订单数
int choice = 0, room_number, days, price;
char customer_name[MAX_NAME_LENGTH];
init_rooms(rooms, n);
while (1) {
printf("\n请选择操作:\n");
printf("1. 查看房间信息\n");
printf("2. 预定房间\n");
printf("3. 查看订单信息\n");
printf("4. 查看总金额\n");
printf("5. 退出\n");
scanf("%d", &choice);
switch (choice) {
case 1:
print_rooms(rooms, n);
break;
case 2:
printf("请输入房间号:");
scanf("%d", &room_number);
printf("请输入客户名字:");
scanf("%s", customer_name);
printf("请输入入住天数:");
scanf("%d", &days);
Room* room = find_room(rooms, n, room_number);
if (room == NULL) {
printf("房间不存在!\n");
}
else if (room->is_occupied) {
printf("房间已被占用!\n");
}
else {
room->is_occupied = 1;
strcpy(room->customer_name, customer_name);
price = days * room->price;
add_order(orders, &order_count, room_number, customer_name, days, price);
printf("预定成功!\n");
}
break;
case 3:
print_orders(orders, order_count);
break;
case 4:
printf("总金额:%d\n", calculate_total_price(orders, order_count));
break;
case 5:
exit(0);
default:
printf("选择无效!\n");
break;
}
}
return 0;
}
```
这只是一个简单的示例,实际的酒店管理系统需要更多的功能,比如客户管理、员工管理、报表统计等等。
阅读全文