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

embedded/2025/2/19 16:56:18/

酒店客房管理系统 要求:
1.客房信息管理:包括客房的编号、类型、价格、状态等信息的录入和修改;
2.顾客信息管理:包括顾客的基本信息、预订信息等的管理;
3.客房预订:客户可以根据需要进行客房的预订,系统会自动判断客房的可用情况;
4.入住管理:客户入住时需要进行登记,同时系统会自动更改客房的状态信息;
*5.结账管理:客户结账需要进行登记,同时系统会自动更改客房的状态信息;
*6.统计报表:包括客房的使用情况、收入情况等的统计报表。

5和6 功能可选 使用文件保存信息
在这里插入图片描述

在这里插入代码片
#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;}
};

主函数

在这里插入代码片
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;
}

在这里插入图片描述


http://www.ppmy.cn/embedded/162378.html

相关文章

在vs code中运行python程序时,将解释器设置为uv虚拟环境构建的解释器。

在VS Code中运行Python程序时&#xff0c;正确配置虚拟环境解释器是项目依赖管理的重要环节。以下是如何使用uv工具创建虚拟环境并在VS Code中切换解释器的完整流程&#xff1a; 一、uv虚拟环境创建 安装uv工具 pip install uv创建虚拟环境 在项目根目录执行以下命令&#xff0…

借助 Docker 环境变量,实现1分钟上线在线客服系统

最新版本的客服系统 Docker 镜像加入了对环境变量的支持&#xff0c;可以在 docker run 时直接指定域名和IP&#xff0c;一键上线&#xff0c;不再需要进入容器内修改配置文件。 从 Docker Hub 下载服务器镜像 docker pull iccb1013/linkup:latest 用以下启动命令为例&#x…

用vue3写一个好看的wiki前端页面

以下是一个使用 Vue 3 Element Plus 实现的 Wiki 风格前端页面示例&#xff0c;包含现代设计、响应式布局和常用功能&#xff1a; <template><div class"wiki-container"><!-- 头部导航 --><el-header class"wiki-header"><d…

【开源项目】数字孪生哈尔滨CIM/BIM—开源工程及源码

飞渡科技数字孪生哈尔滨CIM管理平台&#xff0c;基于国产自研数字孪生引擎&#xff0c;以及物联网IOT、云计算等技术&#xff0c;集成新一代感知、网络、算力等基础设施数据&#xff0c;利用数字技术赋能城市规划、交通监测以及应急管理等业务领域&#xff0c;助力提升城市管理…

知识拓展:Python序列化模块 marshal 模块详解

Python marshal 模块学习笔记 1. 简介 marshal 是 Python 的内部序列化格式&#xff0c;主要用于序列化和反序列化 Python 对象。它是 Python 字节码&#xff08;.pyc文件&#xff09;使用的序列化格式&#xff0c;比 pickle 更原始和受限&#xff0c;但也更快速和安全。 http…

Node.js HTTP模块详解:创建服务器、响应请求与客户端请求

Node.js HTTP模块详解&#xff1a;创建服务器、响应请求与客户端请求 Node.js 的 http 模块是 Node.js 核心模块之一&#xff0c;它允许你创建 HTTP 服务器和客户端。以下是一些关键知识点和代码示例&#xff1a; 1. 创建 HTTP 服务器 使用 http.createServer() 方法可以创建…

数仓:核心概念,数仓系统(ETL,数仓分层,数仓建模),数仓建模方法(星型模型,雪花模型,星座模型)和步骤

数仓建模的核心概念 事实表&#xff08;Fact Table&#xff09;&#xff1a; 存储业务过程的度量值&#xff08;如销售额、订单数量等&#xff09;。 通常包含外键&#xff0c;用于关联维度表。 维度表&#xff08;Dimension Table&#xff09;&#xff1a; 存储描述性信息&…

传输层协议TCP ( 下 )

文章目录 前言序号与确认序号超时重传RTOJacobson算法内核中超时时间的计算 滑动窗口滑动窗口延迟应答流量控制 拥塞控制慢启动拥塞避免快重传快速恢复 保活机制参考资料 前言 TCP&#xff08;Transmission Control Protocol&#xff0c;传输控制协议&#xff09;是互联网最重要…