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

news/2025/2/15 12:25:27/

酒店客房管理系统 要求:
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/news/1572235.html

相关文章

/etc/sysctl.conf——系统的配置文件

用户级修改 控制当前会话的文件描述符数量(一般打开一个终端就是一个会话) # 设置软限制&#xff08;当前会话中可使用的最大文件描述符数&#xff09; ulimit -Sn 65535 # 设置硬限制&#xff08;软限制的上限&#xff09; ulimit -Hn 65535控制核文件大小 ulimit -c unlim…

STL语言在工业自动化中的价值与应用场景分析

STL语言在工业自动化中的价值与应用场景分析 引言 作为西门子PLC编程的核心语言&#xff0c;STL&#xff08;Statement List&#xff09;凭借其底层控制能力&#xff0c;长期在工业自动化领域占据重要地位。然而&#xff0c;随着LAD、FBD、SCL等高级语言的普及&#xff0c;关…

算法跟练第十弹——栈与队列

文章目录 part01 逆波兰表达式求值part02 滑动窗口最大值part03 前 K 个高频元素归纳&#xff1a;将字符串转转换成整数&#xff1a;LinkedListMap遍历优先级队列的比较器 跟着代码随想录刷题的第十天。 代码随想录链接&#xff1a;代码随想录 part01 逆波兰表达式求值 题目链接…

缓存的介绍

相关面试题 &#xff1a; ● 为什么要用缓存&#xff1f; ● 本地缓存应该怎么做&#xff1f; ● 为什么要有分布式缓存?/为什么不直接用本地缓存? ● 为什么要用多级缓存&#xff1f; ● 多级缓存适合哪些业务场景&#xff1f; 缓存思想 空间换时间(索引&#xff0c;集群&a…

Jenkins+gitee 搭建自动化部署

Jenkinsgitee 搭建自动化部署 环境说明&#xff1a; 软件版本备注CentOS8.5.2111JDK1.8.0_211Maven3.8.8git2.27.0Jenkins2.319最好选稳定版本&#xff0c;不然安装插件有点麻烦 一、安装Jenkins程序 1、到官网下载相应的版本war或者直接使用yum安装 Jenkins官网下载 直接…

Docker 存储管理:卷、绑定挂载、临时存储

Docker 提供了多种存储方式&#xff0c;用于容器中的数据存储。根据不同的使用场景&#xff0c;Docker 提供了 卷&#xff08;Volumes&#xff09;、绑定挂载&#xff08;Bind Mounts&#xff09; 和 临时存储&#xff08;Tmpfs&#xff09; 等存储方式。每种存储方式有不同的特…

零基础开发自己的微信小程序(工具箱之父)(二)

完整界面如下&#xff0c;以上线微信小程序&#xff0c;大家可以前往微信小程序搜索工具箱之父即可体验 第三阶段&#xff0c;安装cursor 下载cursor 打开你创建的微信小程序界面 按ctrl加i调出框 它就会帮你打工了&#xff0c;然后有错误复制给它就行 我们可以选择我们的大模…

基于Docker-compose的禅道部署实践:自建MySQL与Redis集成及故障排查指南

基于Docker-compose的禅道部署实践&#xff1a;自建MySQL与Redis集成及故障排查指南 禅道镜像版本&#xff1a;easysoft/zentao:21.4 Redis版本&#xff1a;redis:6.2.0 Mysql版本&#xff1a;mysql:8.0.35 文章目录 **基于Docker-compose的禅道部署实践&#xff1a;自建MySQL与…