C语言如何实现酒店预订管理系统

发布时间:2022-06-06 09:32:26 作者:zzz
来源:亿速云 阅读:176

C语言如何实现酒店预订管理系统

引言

酒店预订管理系统是一个用于管理酒店房间预订、客户信息、房间状态等的软件系统。通过该系统,酒店可以高效地管理房间资源,客户可以方便地进行预订和查询。本文将介绍如何使用C语言实现一个简单的酒店预订管理系统。

系统功能需求

在开始编写代码之前,我们需要明确系统的基本功能需求:

  1. 房间管理:包括房间的添加、删除、修改和查询。
  2. 客户管理:包括客户的添加、删除、修改和查询。
  3. 预订管理:包括房间的预订、取消预订、查询预订状态。
  4. 报表生成:生成房间状态报表、客户预订报表等。

数据结构设计

为了实现上述功能,我们需要设计合适的数据结构来存储房间和客户信息。

房间信息结构体

typedef struct {
    int room_id;        // 房间编号
    char type[50];      // 房间类型
    float price;        // 房间价格
    int is_booked;      // 是否被预订 (0: 未预订, 1: 已预订)
} Room;

客户信息结构体

typedef struct {
    int customer_id;    // 客户编号
    char name[100];     // 客户姓名
    char phone[20];     // 客户电话
    int room_id;        // 预订的房间编号
} Customer;

功能实现

1. 房间管理

添加房间

void add_room(Room rooms[], int *room_count) {
    Room new_room;
    printf("输入房间编号: ");
    scanf("%d", &new_room.room_id);
    printf("输入房间类型: ");
    scanf("%s", new_room.type);
    printf("输入房间价格: ");
    scanf("%f", &new_room.price);
    new_room.is_booked = 0;  // 默认未预订
    rooms[*room_count] = new_room;
    (*room_count)++;
    printf("房间添加成功!\n");
}

删除房间

void delete_room(Room rooms[], int *room_count, int room_id) {
    int index = -1;
    for (int i = 0; i < *room_count; i++) {
        if (rooms[i].room_id == room_id) {
            index = i;
            break;
        }
    }
    if (index != -1) {
        for (int i = index; i < *room_count - 1; i++) {
            rooms[i] = rooms[i + 1];
        }
        (*room_count)--;
        printf("房间删除成功!\n");
    } else {
        printf("未找到该房间!\n");
    }
}

2. 客户管理

添加客户

void add_customer(Customer customers[], int *customer_count) {
    Customer new_customer;
    printf("输入客户编号: ");
    scanf("%d", &new_customer.customer_id);
    printf("输入客户姓名: ");
    scanf("%s", new_customer.name);
    printf("输入客户电话: ");
    scanf("%s", new_customer.phone);
    printf("输入预订的房间编号: ");
    scanf("%d", &new_customer.room_id);
    customers[*customer_count] = new_customer;
    (*customer_count)++;
    printf("客户添加成功!\n");
}

删除客户

void delete_customer(Customer customers[], int *customer_count, int customer_id) {
    int index = -1;
    for (int i = 0; i < *customer_count; i++) {
        if (customers[i].customer_id == customer_id) {
            index = i;
            break;
        }
    }
    if (index != -1) {
        for (int i = index; i < *customer_count - 1; i++) {
            customers[i] = customers[i + 1];
        }
        (*customer_count)--;
        printf("客户删除成功!\n");
    } else {
        printf("未找到该客户!\n");
    }
}

3. 预订管理

预订房间

void book_room(Room rooms[], int room_count, Customer customers[], int customer_count) {
    int room_id, customer_id;
    printf("输入要预订的房间编号: ");
    scanf("%d", &room_id);
    printf("输入客户编号: ");
    scanf("%d", &customer_id);

    int room_index = -1, customer_index = -1;
    for (int i = 0; i < room_count; i++) {
        if (rooms[i].room_id == room_id) {
            room_index = i;
            break;
        }
    }
    for (int i = 0; i < customer_count; i++) {
        if (customers[i].customer_id == customer_id) {
            customer_index = i;
            break;
        }
    }

    if (room_index != -1 && customer_index != -1) {
        if (rooms[room_index].is_booked == 0) {
            rooms[room_index].is_booked = 1;
            customers[customer_index].room_id = room_id;
            printf("房间预订成功!\n");
        } else {
            printf("该房间已被预订!\n");
        }
    } else {
        printf("房间或客户不存在!\n");
    }
}

取消预订

void cancel_booking(Room rooms[], int room_count, Customer customers[], int customer_count) {
    int room_id, customer_id;
    printf("输入要取消预订的房间编号: ");
    scanf("%d", &room_id);
    printf("输入客户编号: ");
    scanf("%d", &customer_id);

    int room_index = -1, customer_index = -1;
    for (int i = 0; i < room_count; i++) {
        if (rooms[i].room_id == room_id) {
            room_index = i;
            break;
        }
    }
    for (int i = 0; i < customer_count; i++) {
        if (customers[i].customer_id == customer_id) {
            customer_index = i;
            break;
        }
    }

    if (room_index != -1 && customer_index != -1) {
        if (rooms[room_index].is_booked == 1 && customers[customer_index].room_id == room_id) {
            rooms[room_index].is_booked = 0;
            customers[customer_index].room_id = -1;
            printf("预订取消成功!\n");
        } else {
            printf("该房间未被该客户预订!\n");
        }
    } else {
        printf("房间或客户不存在!\n");
    }
}

4. 报表生成

生成房间状态报表

void generate_room_report(Room rooms[], int room_count) {
    printf("房间状态报表:\n");
    printf("房间编号\t房间类型\t价格\t状态\n");
    for (int i = 0; i < room_count; i++) {
        printf("%d\t\t%s\t\t%.2f\t%s\n", rooms[i].room_id, rooms[i].type, rooms[i].price, rooms[i].is_booked ? "已预订" : "未预订");
    }
}

生成客户预订报表

void generate_customer_report(Customer customers[], int customer_count) {
    printf("客户预订报表:\n");
    printf("客户编号\t客户姓名\t电话\t预订房间编号\n");
    for (int i = 0; i < customer_count; i++) {
        printf("%d\t\t%s\t\t%s\t%d\n", customers[i].customer_id, customers[i].name, customers[i].phone, customers[i].room_id);
    }
}

主菜单设计

为了方便用户操作,我们可以设计一个主菜单,用户可以通过选择不同的选项来执行相应的功能。

void display_menu() {
    printf("\n酒店预订管理系统\n");
    printf("1. 添加房间\n");
    printf("2. 删除房间\n");
    printf("3. 添加客户\n");
    printf("4. 删除客户\n");
    printf("5. 预订房间\n");
    printf("6. 取消预订\n");
    printf("7. 生成房间状态报表\n");
    printf("8. 生成客户预订报表\n");
    printf("0. 退出\n");
    printf("请选择操作: ");
}

主函数

最后,我们将所有功能整合到主函数中,通过循环和条件判断来实现用户交互。

int main() {
    Room rooms[100];
    Customer customers[100];
    int room_count = 0, customer_count = 0;
    int choice;

    while (1) {
        display_menu();
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                add_room(rooms, &room_count);
                break;
            case 2:
                printf("输入要删除的房间编号: ");
                int room_id;
                scanf("%d", &room_id);
                delete_room(rooms, &room_count, room_id);
                break;
            case 3:
                add_customer(customers, &customer_count);
                break;
            case 4:
                printf("输入要删除的客户编号: ");
                int customer_id;
                scanf("%d", &customer_id);
                delete_customer(customers, &customer_count, customer_id);
                break;
            case 5:
                book_room(rooms, room_count, customers, customer_count);
                break;
            case 6:
                cancel_booking(rooms, room_count, customers, customer_count);
                break;
            case 7:
                generate_room_report(rooms, room_count);
                break;
            case 8:
                generate_customer_report(customers, customer_count);
                break;
            case 0:
                printf("退出系统。\n");
                return 0;
            default:
                printf("无效的选择,请重新输入。\n");
        }
    }

    return 0;
}

结论

通过上述代码,我们实现了一个简单的酒店预订管理系统。该系统具备基本的房间管理、客户管理、预订管理以及报表生成功能。虽然这个系统相对简单,但它展示了如何使用C语言来实现一个实际应用系统的基本框架。未来可以根据需求进一步扩展和优化系统功能。

推荐阅读:
  1. 酒店管理系统
  2. 使用C语言怎么编写一个酒店管理系统

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

c语言

上一篇:vue相对路径与路径别名如何设置

下一篇:python面向对象如何实现学员管理系统

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》