C++-----------酒店客房管理系统

酒店客房管理系统 要求:

1.客房信息管理:包括客房的编号、类型、价格、状态等信息的录入和修改;

2.顾客信息管理:包括顾客的基本信息、预订信息等的管理;

3.客房预订:客户可以根据需要进行客房的预订,系统会自动判断客房的可用情况;

4.入住管理:客户入住时需要进行登记,同时系统会自动更改客房的状态信息;

*5.结账管理:客户结账需要进行登记,同时系统会自动更改客房的状态信息;

*6.统计报表:包括客房的使用情况、收入情况等的统计报表。

5和6 功能可选 使用文件保存信息

类

bash 复制代码
在这里插入代码片
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <map>
#include <string>

// 客房类
class Room {
public:
    int number;
    std::string type;
    double price;
    std::string status;  // "available", "occupied", "reserved"

    Room(int num, std::string t, double p) : number(num), type(t), price(p), status("available") {}
};

// 顾客类
class Customer {
public:
    std::string name;
    std::string contact;
    int roomNumber;
    std::string checkInDate;
    std::string checkOutDate;

    Customer(std::string n, std::string c, int room, std::string in, std::string out)
        : name(n), contact(c), roomNumber(room), checkInDate(in), checkOutDate(out) {}
};

// 客房信息管理
class RoomManagement {
private:
    std::vector<Room> rooms;
    std::string roomFilePath = "rooms.txt";

    void saveRoomsToFile() {
        std::ofstream file(roomFilePath);
        for (const auto& room : rooms) {
            file << room.number << "," << room.type << "," << room.price << "," << room.status << std::endl;
        }
        file.close();
    }

    void loadRoomsFromFile() {
        std::ifstream file(roomFilePath);
        std::string line;
        while (std::getline(file, line)) {
            std::istringstream iss(line);
            int number;
            std::string type;
            double price;
            std::string status;
            std::getline(iss, type, ',');
            iss >> number;
            iss.ignore();
            std::getline(iss, type, ',');
            iss >> price;
            iss.ignore();
            std::getline(iss, status, ',');
            rooms.push_back(Room(number, type, price));
        }
        file.close();
    }

public:
    RoomManagement() {
        loadRoomsFromFile();
    }

    void addRoom(int number, std::string type, double price) {
        rooms.push_back(Room(number, type, price));
        saveRoomsToFile();
    }

    void updateRoom(int number, std::string type, double price, std::string status) {
        for (auto& room : rooms) {
            if (room.number == number) {
                room.type = type;
                room.price = price;
                room.status = status;
                break;
            }
        }
        saveRoomsToFile();
    }

    std::vector<Room> getRooms() const {
        return rooms;
    }
};

// 顾客信息管理
class CustomerManagement {
private:
    std::vector<Customer> customers;
    std::string customerFilePath = "customers.txt";

    void saveCustomersToFile() {
        std::ofstream file(customerFilePath);
        for (const auto& customer : customers) {
            file << customer.name << "," << customer.contact << "," << customer.roomNumber << ","
                 << customer.checkInDate << "," << customer.checkOutDate << std::endl;
        }
        file.close();
    }

    void loadCustomersFromFile() {
        std::ifstream file(customerFilePath);
        std::string line;
        while (std::getline(file, line)) {
            std::istringstream iss(line);
            std::string name, contact, checkInDate, checkOutDate;
            int roomNumber;
            std::getline(iss, name, ',');
            std::getline(iss, contact, ',');
            iss >> roomNumber;
            iss.ignore();
            std::getline(iss, checkInDate, ',');
            std::getline(iss, checkOutDate, ',');
            customers.push_back(Customer(name, contact, roomNumber, checkInDate, checkOutDate));
        }
        file.close();
    }

public:
    CustomerManagement() {
        loadCustomersFromFile();
    }

    void addCustomer(std::string name, std::string contact, int roomNumber, std::string checkInDate, std::string checkOutDate) {
        customers.push_back(Customer(name, contact, roomNumber, checkInDate, checkOutDate));
        saveCustomersToFile();
    }

    void updateCustomer(int roomNumber, std::string name, std::string contact, std::string checkInDate, std::string checkOutDate) {
        for (auto& customer : customers) {
            if (customer.roomNumber == roomNumber) {
                customer.name = name;
                customer.contact = contact;
                customer.checkInDate = checkInDate;
                customer.checkOutDate = checkOutDate;
                break;
            }
        }
        saveCustomersToFile();
    }

    std::vector<Customer> getCustomers() const {
        return customers;
    }
};

// 客房预订
class RoomReservation {
private:
    RoomManagement& roomMgmt;
    CustomerManagement& customerMgmt;

public:
    RoomReservation(RoomManagement& rm, CustomerManagement& cm) : roomMgmt(rm), customerMgmt(cm) {}

    void reserveRoom(int roomNumber, std::string customerName, std::string customerContact, std::string checkInDate, std::string checkOutDate) {
        auto rooms = roomMgmt.getRooms();
        for (auto& room : rooms) {
            if (room.number == roomNumber && room.status == "available") {
                room.status = "reserved";
                roomMgmt.updateRoom(room.number, room.type, room.price, room.status);
                customerMgmt.addCustomer(customerName, customerContact, roomNumber, checkInDate, checkOutDate);
                std::cout << "Room " << roomNumber << " reserved successfully for " << customerName << std::endl;
                return;
            }
        }
        std::cout << "Room " << roomNumber << " is not available for reservation." << std::endl;
    }
};

// 入住管理
class CheckIn {
private:
    RoomManagement& roomMgmt;
    CustomerManagement& customerMgmt;

public:
    CheckIn(RoomManagement& rm, CustomerManagement& cm) : roomMgmt(rm), customerMgmt(cm) {}

    void checkInCustomer(int roomNumber) {
        auto rooms = roomMgmt.getRooms();
        for (auto& room : rooms) {
            if (room.number == roomNumber && room.status == "reserved") {
                room.status = "occupied";
                roomMgmt.updateRoom(room.number, room.type, room.price, room.status);
                std::cout << "Customer checked in to room " << roomNumber << std::endl;
                return;
            }
        }
        std::cout << "Room " << roomNumber << " is not in a reserved state for check - in." << std::endl;
    }
};

// 结账管理
class CheckOut {
private:
    RoomManagement& roomMgmt;
    CustomerManagement& customerMgmt;

public:
    CheckOut(RoomManagement& rm, CustomerManagement& cm) : roomMgmt(rm), customerMgmt(cm) {}

    void checkOutCustomer(int roomNumber) {
        auto rooms = roomMgmt.getRooms();
        for (auto& room : rooms) {
            if (room.number == roomNumber && room.status == "occupied") {
                room.status = "available";
                roomMgmt.updateRoom(room.number, room.type, room.price, room.status);
                std::cout << "Customer checked out from room " << roomNumber << std::endl;
                return;
            }
        }
        std::cout << "Room " << roomNumber << " is not in an occupied state for check - out." << std::endl;
    }
};

// 统计报表
class Statistics {
private:
    RoomManagement& roomMgmt;
    CustomerManagement& customerMgmt;

public:
    Statistics(RoomManagement& rm, CustomerManagement& cm) : roomMgmt(rm), customerMgmt(cm) {}

    void printRoomUsage() {
        auto rooms = roomMgmt.getRooms();
        std::cout << "Room Usage Statistics:" << std::endl;
        int availableCount = 0, occupiedCount = 0, reservedCount = 0;
        for (const auto& room : rooms) {
            if (room.status == "available") availableCount++;
            else if (room.status == "occupied") occupiedCount++;
            else if (room.status == "reserved") reservedCount++;
        }
        std::cout << "Available Rooms: " << availableCount << std::endl;
        std::cout << "Occupied Rooms: " << occupiedCount << std::endl;
        std::cout << "Reserved Rooms: " << reservedCount << std::endl;
    }

    void printIncome() {
        auto rooms = roomMgmt.getRooms();
        auto customers = customerMgmt.getCustomers();
        double totalIncome = 0;
        for (const auto& customer : customers) {
            for (const auto& room : rooms) {
                if (customer.roomNumber == room.number) {
                    totalIncome += room.price;
                    break;
                }
            }
        }
        std::cout << "Total Income: " << totalIncome << std::endl;
    }
};

主函数

bash 复制代码
在这里插入代码片
int main() {
    RoomManagement roomMgmt;
    CustomerManagement customerMgmt;
    RoomReservation reservation(roomMgmt, customerMgmt);
    CheckIn checkIn(roomMgmt, customerMgmt);
    CheckOut checkOut(roomMgmt, customerMgmt);
    Statistics stats(roomMgmt, customerMgmt);

    // 测试客房信息管理
    roomMgmt.addRoom(101, "Single", 80.0);
    roomMgmt.addRoom(102, "Double", 120.0);

    // 测试客房预订
    reservation.reserveRoom(101, "John Doe", "123 - 456 - 7890", "2025 - 02 - 15", "2025 - 02 - 17");

    // 测试入住管理
    checkIn.checkInCustomer(101);

    // 测试结账管理
    checkOut.checkOutCustomer(101);

    // 测试统计报表
    stats.printRoomUsage();
    stats.printIncome();

    return 0;
}
相关推荐
艾莉丝努力练剑1 小时前
【AI大模型接入SDK】项目总结
java·开发语言·前端·c++·人工智能·学习·架构
旖旎夜光2 小时前
面试题 01.02: 判定是否互为字符重排 (哈希表) —— 题解
c++·笔记·学习·算法·哈希表
Evand J2 小时前
【MATLAB例程,无人机避障7】基于RRT*与人工势场法(RRT*+APF)的多无人机二维动态路径规划与避障。附下载链接
开发语言·matlab·无人机·rtt·路径规划·人工势场
布莱克6052 小时前
Objective-C 基本语法详解:从零开始掌握 iOS 开发语言
开发语言·ios·objective-c·基础·语法
码途行者3 小时前
每天10分钟学Go:第24课 通道-协程之间的传送带
开发语言·后端·golang
白小飞不会飞3 小时前
【AUTOSAR】CP SOME/IP-TP
c++·嵌入式硬件·网络协议·车载系统·autosar
CoderYanger3 小时前
Java EE 进阶:14.案例综合练习-博客系统(第三弹) :用户登录+强制登录
java·服务器·开发语言·数据库·spring boot·java-ee·mybatis
CoderYanger9 小时前
Java EE 进阶:13. Spring事务和事务传播机制(第二弹)
java·开发语言·数据库·spring boot·后端·spring·java-ee
ShineWinsu14 小时前
对于Qt:信号量(QSemaphore)的解析
c++·qt·面试·笔试·客户端·线程安全·信号量
星恒随风14 小时前
从0实现C++ AI大模型接入SDK(八):SessionManager会话管理——智能指针、原子操作、线程安全与懒加载机制
linux·服务器·开发语言·c++·人工智能