Linux下C++酒店管理系統

来源:https://www.cnblogs.com/ikaros-521/archive/2019/08/23/11402668.html
-Advertisement-
Play Games

功能要求: ​ 相關源碼:碼雲:傳送門,GitHub:傳送門 相關圖片: 拆分版 make編譯 ​ ./hotel運行 ​ 輸入2,進入開房模塊 ​ 相關源碼: class.cpp 1 #include <fstream> 2 #include "tools.h" 3 #include "class ...


功能要求:

相關源碼:碼雲:傳送門,GitHub:傳送門

相關圖片:

拆分版

make編譯

./hotel運行

輸入2,進入開房模塊

相關源碼:

class.cpp

  1 #include <fstream>
  2 #include "tools.h"
  3 #include "class.h"
  4 
  5 using namespace std;
  6 
  7 Customer* cust[30];
  8 Room* room[30];
  9 
 10 
 11 int live; // 被訂房間數
 12 
 13 // 獲取room_num
 14 short Room::get_room_num(void)
 15 {
 16     return room_num;
 17 }
 18 
 19 // 返回房間的下標
 20 int Manage::room_index(short room_num)
 21 {
 22     short num = room_num;
 23     for(int i=0; i<30; i++)
 24     {
 25         if(num == room[i]->get_room_num())
 26         {
 27             return i;
 28         }
 29     }
 30     return -1;
 31 }
 32 
 33 // 返回顧客的下標
 34 int Manage::cust_index(short room_num)
 35 {
 36     short num = room_num;
 37     for(int i=0; i<30; i++)
 38     {
 39         if(num == cust[i]->room_num)
 40         {
 41             return i;
 42         }
 43     }
 44     return -1;
 45 }
 46 
 47 // 查詢剩餘房間
 48 void Manage::find_room(void)
 49 {
 50     for(int i=0; i<30; i++)
 51     {
 52         if(i == 10 || i == 20)
 53         {
 54             cout << endl;
 55         }
 56         if(room[i]->use != 0)
 57         {
 58             continue;
 59         }
 60         cout << room[i]->room_num << " ";
 61     }
 62     cout << endl;
 63 }
 64 
 65 // 開房
 66 void Manage::get_room(void)
 67 {
 68     cout << "現有房間如下" << endl;
 69     find_room();
 70     
 71 //    cout << "已經入住的人員" << endl;
 72 //    show_cust();
 73 
 74     cout << "請輸入您選擇的房間:";
 75     short room_num;
 76     cin >> room_num;
 77     int flag = used(room_num);
 78     if(flag == 1)
 79     {
 80         cout << "此房間不能使用,請重新選擇" << endl;
 81         getch();
 82         return;
 83     }
 84     else if(flag == -1)
 85     {
 86         cout << "此房間不存在,請重新選擇" << endl;
 87         getch();
 88         return;
 89     }
 90     else
 91     {
 92         cout << "您選擇的房間是:" << room_num << endl;
 93     }
 94 
 95     int index = room_index(room_num);
 96     short type = room[index]->room_type;
 97 
 98     cout << "請輸入您的姓名:";
 99     string name;
100     cin >> name;
101     cout << "請輸入您的身份證:";
102     string id;
103     cin >> id;
104     cout << "請輸入您的2位家屬(0,表示沒有)" << endl;
105     string family1,family2;
106     cin >> family1 >> family2;
107 
108     if(type == 1)
109     {
110         if(family1 != "0" || family2 != "0")
111         {
112             cout << "人數過多,開房失敗" << endl;
113             getch();
114             return;
115         }
116     }
117     else if(type == 2)
118     {
119         if(family1 != "0" && family2 != "0")
120         {
121             cout << "人數過多,開房失敗" << endl;
122             getch();
123             return;
124         }
125     }
126     else
127     {
128     }
129 
130     cout << "請輸入要訂的天數:";
131     short day;
132     cin >> day;
133     short pay = day*room[index]->price;
134     cout << "請支付" << pay << "" << endl;
135     short money = 0,change = 0;
136     cout << "收您:";
137     cin >> money;
138     cout << "" << endl;
139     change = money-pay;
140     if(change < 0)
141     {
142         cout << "餘額不足,請充值" << endl;
143         getch();        
144         return;
145     }
146     cout << "找您" << change << "" << endl;
147 
148     short floor = room_num/100;
149 
150     cust[live++] = new Customer(name,id,family1,family2,floor,room_num,day);
151 
152     cout << "已訂房間:" << live << endl;
153 
154     for(int i=0; i<30; i++)
155     {
156         if(room[i]->room_num == room_num)
157         {
158             room[i]->use = 1;
159         }
160     }
161 
162     cout << "開房成功,歡迎您的入住,祝你生活愉快!" << endl;
163     getch();
164 }
165 
166 // 使用情況
167 int Manage::used(short room_num)
168 {
169     short num = room_num;
170     for(int i=0; i<30; i++)
171     {
172         if(num == room[i]->room_num)
173         {
174             if(room[i]->use == 1)
175             {
176                 return 1;
177             }
178             else
179             {
180                 return 0;
181             }
182         }
183     }
184     return -1;
185 }
186 
187 // 顯示顧客
188 void Manage::show_cust(void)
189 {
190     for(int i=0; i<30; i++)
191     {
192         if(cust[i]->name == "0")
193         {
194             break;
195         }
196         else
197         {
198             cout << "姓名:" << cust[i]->name << "," << "房間:" << cust[i]->room_num << ",";
199 
200             string f1,f2;
201             f1 = cust[i]->family1;
202             f2 = cust[i]->family2;
203             cout << "家屬1:";
204             if(f1 == "0") cout << " ,";
205             else cout << f1 << ",";
206             cout << "家屬2:";
207             if(f2 == "0") cout << " ";
208             else cout << f2;
209         }
210     }
211 }
212 
213 // 房間價格
214 int Manage::room_price(short room_num)
215 {
216     short num = room_num;
217     for(int i=0; i<30; i++)
218     {
219         if(room[i]->room_num == num)
220         {
221             return room[i]->price;
222         }
223     }
224     return 0;
225 }
226 
227 // 續費
228 void Manage::renew_room(void)
229 {
230     cout << "請輸入你的房間號:";
231     short room_num;
232     cin >> room_num;
233     int flag = used(room_num);
234     if(flag == -1 || flag == 0)
235     {
236         cout << "您輸入的房間號有誤" << endl;
237         getch();
238         return;
239     }
240 
241     int index = cust_index(room_num);
242 
243     cout << "您的房間剩餘:" << cust[index]->day << "" << endl;
244 
245     cout << "請輸入你要續的天數:";
246     short day;
247     cin >> day;
248     short pay = day*room_price(room_num);
249     cout << "請支付" << pay << "" << endl;
250     short price = 0,change = 0;
251     cin >> price;
252     change = price-pay;
253     if(change < 0)
254     {
255         cout << "餘額不足,請充值" << endl;
256         getch();
257         return;
258     }
259     cout << "收您" << price <<"元,找您" << change << "" << endl;
260 
261     string rename = cust[index]->name,reid = cust[index]->id;
262     string refamily1=cust[index]->family1,refamily2=cust[index]->family2;
263     short refloor = cust[index]->floor,reday = cust[index]->day+day;
264     cust[index] = new Customer(rename,reid,refamily1,refamily2,refloor,room_num,reday);
265     
266     cout << "續費成功,房間的使用時間為:" << reday <<"" << endl;
267     getch();
268 
269 }
270 
271 // 退房
272 void Manage::cancel_room(void)
273 {
274     cout << "請輸入您的房間號:";
275     short room_num;
276     string name;
277     cin >> room_num;
278     cout << "請輸入您的姓名:";
279     cin >> name;
280     int flag = used(room_num);
281     if(flag == 0 || flag == -1)
282     {
283         cout << "您輸入的房間有誤。" << endl;
284         getch();
285         return;
286     }
287     else
288     {
289         short refloor = 0,retype = 0,reprice = 0;
290 
291         int i = cust_index(room_num);
292         if(i != -1)
293         {
294             if(cust[i]->name == name)
295             {
296                 short price = room[room_index(room_num)]->price;
297                 short change = cust[i]->day*price;
298                 cout << "退還您" << change << "" << endl;
299 
300                 cust[i] = new Customer("0","0","0","0",0,0,0);
301                 int j = room_index(room_num);
302                 refloor = room[j]->floor;
303                 retype = room[j]->room_type;
304                 reprice = room[j]->price;
305                 room[j] = new Room(refloor,room_num,retype,reprice,0);
306 
307                 cout << "退房成功,感謝您的光顧,歡迎下次光臨!"<< endl;
308                 live--;
309                 getch();
310                 return;
311             }
312             else
313             {
314                 //cout << cust[i]->name << endl;
315                 cout << "您輸入的相關信息有誤" << endl;
316                 getch();                
317                 return;
318             }
319         }
320         else
321         {
322             cout << "您輸入的信息有誤" << endl;
323             getch();
324             return;
325         }
326     }
327 }
328 
329 // 顧客初始化
330 void Manage::c_init(void)
331 {
332     fstream ci("data/cust.txt",ios::in);
333     if(!ci.good())
334     {
335         cout << "cust.txt數據載入異常" << endl;
336     }
337 
338     for(int i=0; i<30; i++)
339     {
340         string name,id,family1,family2;
341         short floor,room_num,day;
342         ci >> name >> id >> family1 >> family2;
343         ci >> floor >> room_num >> day;
344         cust[i] = new Customer(name,id,family1,family2,floor,room_num,day);
345         if(name != "0")
346         {
347             live++;
348         }
349     }
350 }
351 
352 // 房間初始化
353 void Manage::r_init(void)
354 {
355     live = 0;
356     fstream ri("data/room.txt",ios::in);
357     if(!ri.good())
358     {
359         cout << "room.txt數據載入異常" << endl;
360     }
361 
362     for(int i=0; i<30; i++)
363     {
364         short floor,room_num,room_type,price,use;
365         ri >> floor >> room_num;
366         ri >> room_type >> price >> use;
367         room[i] = new Room(floor,room_num,room_type,price,use);        
368     }
369 }
370 
371 // 數據保存
372 void Manage::save_data(void)
373 {
374     fstream co("data/cust.txt",ios::out);
375     fstream ro("data/room.txt",ios::out);
376 
377     for(int i=0; i<30; i++)
378     {
379         co << cust[i]->name << " " << cust[i]->id << " ";
380         co << cust[i]->family1 << " " << cust[i]->family2 << " ";
381         co << cust[i]->floor << " " << cust[i]->room_num << " ";
382         co << cust[i]->day << "\n";
383 
384         ro << room[i]->floor << " " << room[i]->room_num << " ";
385         ro << room[i]->room_type << " " << room[i]->price << " ";
386         ro << room[i]->use << "\n";
387     }
388 }
389 
390 // 菜單
391 void Manage::menu(void)
392 {
393     cout << "***歡迎使用酒店管理系統***" << endl;
394     cout << "   1、查詢房間" << endl;
395     cout << "   2、開房" << endl;
396     cout << "   3、續費" << endl;
397     cout << "   4、退房" << endl;
398     cout << "   0、退出系統" << endl;
399     cout << "-----------------------" << endl;
400 }

 

main.cpp

 

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 本篇概述 Django Admin後臺顯示 多對多欄位(如何) Django 模板 顯示 多對多欄位(如何) models代碼背景 一,Django Admin後臺顯示 多對多欄位 於admin.py文件中 二,Django 模板 顯示 多對多欄位 先與 視圖 views.py文件中 然後,(url ...
  • 1、文件上傳簡單流程分析圖: 2、Fastdfs介紹: Fastdfs由兩個角色組成: Tracker(集群):調度(幫你找到有空閑的Storage) Storage(集群):文件存儲(幫你保存文件或獲取需要的文件) 流程: 1.Storage和tracker 發送心跳連接。 2.客戶端請求trac ...
  • 在有些業務場景下,我們需要兩個完全相同卻彼此無關的java對象。比如使用原型模式、多線程編程等。對此,java提供了深拷貝的概念。通過深度拷貝可以從源對象完美複製出一個相同卻與源對象彼此獨立的目標對象。這裡的相同是指兩個對象的狀態和動作相同,彼此獨立是指改變其中一個對象的狀態不會影響到另外一個對象。 ...
  • 創建群自定義機器人 在指定釘釘群(或者隨便拉兩個人建個群,然後把別人T出去)的群設置里選擇 群機器人 自定義,如圖: 然後,添加機器人,設置名字,添加成功時如下圖: 其中webhook非常重要,下文詳述。點擊設置說明可以看相關使用文檔,文檔鏈接見本文末尾。 使用HTTP POST請求發送消息 直接向 ...
  • 題目描述 又是一年秋季時,陶陶家的蘋果樹結了n個果子。陶陶又跑去摘蘋果,這次她有一個a公分的椅子。當他手夠不著時,他會站到椅子上再試試。 這次與NOIP 2005普及組第一題不同的是:陶陶之前搬凳子,力氣只剩下s了。當然,每次摘蘋果時都要用一定的力氣。陶陶想知道在s<! more 輸入格式 第1行: ...
  • INTRODUCTION: 在一個無向圖中,如果有一個頂點集合,刪除這個頂點集合以及這個集合中所有頂點相關聯的邊以後,圖的連通分量增多,就稱這個點集為割點集合。 如果某個割點集合只含有一個頂點X(也即{X}是一個割點集合),那麼X稱為一個割點。--百度百科 首先,什麼是割點? 在一個有N個節點,M條 ...
  • 一、起源 1960年Lisp語言: 第一門真正使用記憶體動態分配和垃圾回收的語言。 二、概要 線程相關:程式計數器、虛擬機棧、本地方法棧,不需要考慮垃圾回收 Java堆、方法區:需要考慮垃圾回收 三、垃圾回收演算法 1 引用計數演算法 2 可達性分析演算法 垃圾收集演算法 1 標記-清除演算法 Mark-Swe ...
  • 個人博客搭建線上實施方案 實施方案 方案一:GithubPages 1. 創建 "Github" 賬號 2. 創建倉庫, 倉庫名為:.github.io 3. 將本地Hexo博客推送到GithubPages 3.1. 安裝 插件。在命令行(即Git Bash)運行以下命令即可: 3.2. 添加SSH ...
一周排行
    -Advertisement-
    Play Games
  • 概述:在C#中,++i和i++都是自增運算符,其中++i先增加值再返回,而i++先返回值再增加。應用場景根據需求選擇,首碼適合先增後用,尾碼適合先用後增。詳細示例提供清晰的代碼演示這兩者的操作時機和實際應用。 在C#中,++i 和 i++ 都是自增運算符,但它們在操作上有細微的差異,主要體現在操作的 ...
  • 上次發佈了:Taurus.MVC 性能壓力測試(ap 壓測 和 linux 下wrk 壓測):.NET Core 版本,今天計劃準備壓測一下 .NET 版本,來測試並記錄一下 Taurus.MVC 框架在 .NET 版本的性能,以便後續持續優化改進。 為了方便對比,本文章的電腦環境和測試思路,儘量和... ...
  • .NET WebAPI作為一種構建RESTful服務的強大工具,為開發者提供了便捷的方式來定義、處理HTTP請求並返迴響應。在設計API介面時,正確地接收和解析客戶端發送的數據至關重要。.NET WebAPI提供了一系列特性,如[FromRoute]、[FromQuery]和[FromBody],用 ...
  • 原因:我之所以想做這個項目,是因為在之前查找關於C#/WPF相關資料時,我發現講解圖像濾鏡的資源非常稀缺。此外,我註意到許多現有的開源庫主要基於CPU進行圖像渲染。這種方式在處理大量圖像時,會導致CPU的渲染負擔過重。因此,我將在下文中介紹如何通過GPU渲染來有效實現圖像的各種濾鏡效果。 生成的效果 ...
  • 引言 上一章我們介紹了在xUnit單元測試中用xUnit.DependencyInject來使用依賴註入,上一章我們的Sample.Repository倉儲層有一個批量註入的介面沒有做單元測試,今天用這個示例來演示一下如何用Bogus創建模擬數據 ,和 EFCore 的種子數據生成 Bogus 的優 ...
  • 一、前言 在自己的項目中,涉及到實時心率曲線的繪製,項目上的曲線繪製,一般很難找到能直接用的第三方庫,而且有些還是定製化的功能,所以還是自己繪製比較方便。很多人一聽到自己畫就害怕,感覺很難,今天就分享一個完整的實時心率數據繪製心率曲線圖的例子;之前的博客也分享給DrawingVisual繪製曲線的方 ...
  • 如果你在自定義的 Main 方法中直接使用 App 類並啟動應用程式,但發現 App.xaml 中定義的資源沒有被正確載入,那麼問題可能在於如何正確配置 App.xaml 與你的 App 類的交互。 確保 App.xaml 文件中的 x:Class 屬性正確指向你的 App 類。這樣,當你創建 Ap ...
  • 一:背景 1. 講故事 上個月有個朋友在微信上找到我,說他們的軟體在客戶那邊隔幾天就要崩潰一次,一直都沒有找到原因,讓我幫忙看下怎麼回事,確實工控類的軟體環境複雜難搞,朋友手上有一個崩潰的dump,剛好丟給我來分析一下。 二:WinDbg分析 1. 程式為什麼會崩潰 windbg 有一個厲害之處在於 ...
  • 前言 .NET生態中有許多依賴註入容器。在大多數情況下,微軟提供的內置容器在易用性和性能方面都非常優秀。外加ASP.NET Core預設使用內置容器,使用很方便。 但是筆者在使用中一直有一個頭疼的問題:服務工廠無法提供請求的服務類型相關的信息。這在一般情況下並沒有影響,但是內置容器支持註冊開放泛型服 ...
  • 一、前言 在項目開發過程中,DataGrid是經常使用到的一個數據展示控制項,而通常表格的最後一列是作為操作列存在,比如會有編輯、刪除等功能按鈕。但WPF的原始DataGrid中,預設只支持固定左側列,這跟大家習慣性操作列放最後不符,今天就來介紹一種簡單的方式實現固定右側列。(這裡的實現方式參考的大佬 ...