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

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

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Visonpro 检测是否有缺齿

一、效果展示 二、上面是原展开工具CogPolarUnwrapTool&#xff1b; 第二种方法&#xff1a; 用Blob 和 CogCopyRegionTool 三、 用预处理工具 加减常数&#xff0c;让图片变得更亮点 四、圆展开工具 五、模板匹配 六、代码分解 1.创建集合和文子显示工具 CogGraphicCollec…

线性表之顺序表

目录 一 线性表 1概念&#xff1a; 2分类 3特点 二 顺序表 1概念 2结构 3分类 4静态线性表&#xff08;使用定长数组存储元素&#xff09; 4.1结构 4.2 静态顺序表缺陷 5 动态顺序表&#xff08;利用动态内存管理实现内存的变化&#xff09; 5.1结构【因为动态顺序表的…

IoTDB 常见问题 QA 第五期

关于 IoTDB 的 Q & A 情人节之际&#xff0c;让 IoTDB Q&A 陪您一起共度解惑&#xff01;我们将定期汇总我们将定期汇总社区讨论频繁的问题&#xff0c;并展开进行详细回答&#xff0c;通过积累常见问题“小百科”&#xff0c;方便大家使用 IoTDB。 Q1&#xff1a;导入…

【NLP】文本预处理

目录 一、文本处理的基本方法 1.1 分词 1.2 命名体实体识别 1.3 词性标注 二、文本张量的表示形式 2.1 one-hot编码 2.2 word2vec 模型 2.2.1 CBOW模式 2.2.2 skipgram模式 2.3 词嵌入word embedding 三、文本数据分析 3.1 标签数量分布 3.2 句子长度分布 3.3 词…

1-16 tortoiseGit分支与Git操作

1-1 创建分支 什么时候需要开分支&#xff1f; - 隔离线上版本和开发版本 - 大功能开发&#xff0c;不想影响到其他人&#xff0c;自己独立开个分支去开发 SVN经典目录结构&#xff1a; - trunk-------------------------开发中的文件 - bran…

4090单卡挑战DeepSeek r1 671b:尝试量化后的心得的分享

引言&#xff1a; 最近&#xff0c;DeepSeek-R1在完全开源的背景下&#xff0c;与OpenAI的O1推理模型展开了激烈竞争&#xff0c;引发了广泛关注。为了让更多本地用户能够运行DeepSeek&#xff0c;我们成功将R1 671B参数模型从720GB压缩至131GB&#xff0c;减少了80%&#xff…

frp与云服务器内网穿透

最近想使用一个便宜的云服务器进行内网穿透&#xff0c;访问到本地电脑 之前使用ssh一直没成功&#xff0c;原因还没分析出来&#xff0c;后来换了一种方法&#xff0c;使用frp来进行内网穿透 frp内网穿透搭建 frp简介 frp 是一个专注于内网穿透的高性能的反向代理应用&…

题海拾贝:英语作文(map)

Hello大家好&#xff01;很高兴我们又见面啦&#xff01;给生活添点passion&#xff0c;开始今天的编程之路&#xff01; 我的博客&#xff1a;<但凡. 我的专栏&#xff1a;《编程之路》、《数据结构与算法之美》、《题海拾贝》 欢迎点赞&#xff0c;关注&#xff01; 1、题…

matlab欠驱动船舶模型预测控制

1、内容简介 matlab135-欠驱动船舶模型预测控制 可以交流、咨询、答疑 2、内容说明 略 针对在风 、 浪 、 流时变干扰下欠驱动水面船舶的轨迹跟踪控制问题 &#xff0c; 设计了一种基于模型 预测控制的轨迹跟踪控制器 &#xff0e; 考虑到欠驱动船舶在没有横向驱动力情况下…

2025年-数据库排名

2025年-数据库排名 https://db-engines.com/en/ranking RADB 完整排名 TOP 10 向量 DBMS 的 DB-Engines 排名 关系型 DBMS 的 DB-Engines 排名 搜索引擎的 DB-Engines 排名 键值存储的 DB-Engines 排名 文档存储的 DB-Engines 排名 图形 DBMS 的 DB-Engines 排名 时间序列 DBM…

sib报错:com.*.xctrunner is not in your device!

1、问题描述 在使用sonic集成IOS设备的时候,我们需要通过sonic-agent服务去识别IOS设备。但是在识别的时候提示如下问题: 本质就是在你这个设备中找不到这个设备也就是找不到WebDriverAgentRunner,但是确实安装了,甚至appium可以正常的调用。 或执行如下命令的时候报错:…

rabbitmq五种模式的总结——附java-se实现(详细)

rabbitmq五种模式的总结 完整项目地址&#xff1a;https://github.com/9lucifer/rabbitmq4j-learning 一、简单模式 &#xff08;一&#xff09;简单模式概述 RabbitMQ 的简单模式是最基础的消息队列模式&#xff0c;包含以下两个角色&#xff1a; 生产者&#xff1a;负责发…

LangChain大模型应用开发:提示词工程应用与实践

介绍 大家好&#xff0c;博主又来给大家分享知识了。今天给大家分享的内容是LangChain提示词工程应用与实践。 在如今火热的大语言模型应用领域里&#xff0c;LangChain可是一个相当强大且实用的工具。而其中的提示词(Prompt)&#xff0c;更是我们与语言模型进行有效沟通的关…

4.buuctf [SWPU2019]Web1及知识点

进入题目页面如下 猜测是二次注入 先注册一个账号 再登录&#xff0c;页面如下 点击申请发布广告 页面如上&#xff0c;存在注入点&#xff0c;尝试 判读是整数型注入还是字符型注入 猜解字段数&#xff0c;尝试发现or,#,空格等被过滤了&#xff0c;只能一个一个试 使用联合…

Lua笔记

Lua语法 --注释 #字符串长度、table从1开始连续元素的长度 ..字符串拼接 逻辑运算符 and or not 条件语句 if xxx then elseif yyy then else end 循环语句 for i1,xxx do end xLua AppDomain does not contain a definition for DefineDynamicAssembly&#xff…

开业盛典活动策划方案拆解

道叔来给大家详细剖析咱们方案库里刚收录的这份《蜀大侠火锅店武侠风开业盛典活动策划方案》了&#xff0c;保证让你看完直呼过瘾&#xff0c;收获满满&#xff01; 一、主题创意&#xff1a;武侠风&#xff0c;直击人心 首先&#xff0c;咱们得夸一下这活动的主题——“XXX‘…

三、Unity基础(主要框架)

一、Unity场景概念 如果把游戏运行过程理解成表演&#xff0c;那么场景就是舞台&#xff1b; 场景本质上是一个配置文件&#xff0c;这个配置文件决定了场景中有哪些东西&#xff1b; 二、Scene和Game窗口 1、Scene 滚轮缩放、拖动 单独选中也可以 最下面这个是全能工具…

微软官方出品GPT大模型编排工具:7个开源项目

今天一起盘点下&#xff0c;12月份推荐的7个.Net开源项目&#xff08;点击标题查看详情&#xff09;。 1、一个浏览器自动化操作的.Net开源库 这是一个基于 Google 开源的 Node.js 库 Puppeteer 的 .NET 开源库&#xff0c;方便开发人员使用无头 Web 浏览器抓取 Web、检索 Ja…

C++笔记之类型大小、变量大小,vector与string在栈上内存、堆上内存和总内存的关系

C++笔记之类型大小、变量大小,vector与string在栈上内存、堆上内存和总内存的关系 code review! 文章目录 C++笔记之类型大小、变量大小,vector与string在栈上内存、堆上内存和总内存的关系1.`std::vector<float>` 的内存占用2.`std::vector<float>` 的 `capaci…

华为昇腾920b服务器部署DeepSeek翻车现场

最近到祸一台HUAWEI Kunpeng 920 5250&#xff0c;先看看配置。之前是部署的讯飞大模型&#xff0c;发现资源利用率太低了。把5台减少到3台&#xff0c;就出了他 硬件配置信息 基本硬件信息 按照惯例先来看看配置。一共3块盘&#xff0c;500G的系统盘&#xff0c; 2块3T固态…