日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

基于C++的酒店管理系统

發(fā)布時間:2024/3/24 c/c++ 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于C++的酒店管理系统 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

酒店管理系統(tǒng):

前提:樓層,房間編號,房間類型,價格 開房:姓名,房間,隨行人員,押金,時長 續(xù)費:延時,修改類型 退房:押金,消費

實現(xiàn):在class.h中構(gòu)建出房間以及顧客的兩個類以及訪問和修改類中私有成員的成員函數(shù),然后在class.cpp中實現(xiàn)這些成員函數(shù),func中實現(xiàn)開房、續(xù)費、查詢、退房等具體的功能函數(shù)。

main.c

#include <iostream> #include "class.h" #include "func.h" using namespace std;extern Room* room[40]; extern Customer* customer[40];int main() {room_init();run(); }

class.h

#ifndef CLASS_H #define CLASS_H#include <iostream> #include <string.h>using namespace std;class Room {int room_number;int type;int price;bool empty; public:Room(int room_number=0,int type=0,int price =0){this->room_number = room_number;this->type = type;this->price = price;this->empty = true;}void room_change(void); bool room_empty(void);void room_show(void);int get_price(void);int get_room_number(void); };class Customer {char* name;int room_number;int price;int deposit;int time;char* accname; public:Customer(char* name,int room_number,int price,int deposit,int time,char* accname){this->name = new char[strlen(name)+1];this->accname = new char[strlen(accname)+1];strcpy(this->name,name);strcpy(this->accname,accname);this->room_number = room_number;this->price = price;this->deposit = deposit;this->time = time;}void customer_change1(int _time);void customer_change2(int _number,int _time,int _price);void customer_show(void);char* get_name(void);int get_room_number(void); };#endif//CLASS_H

class.cpp

#include "class.h" #include <fstream>void Room::room_change(void) {if (empty == true){empty = false;}else{empty = true;} }bool Room::room_empty(void) {if (empty == true){return true;} }void Room::room_show(void) {cout << room_number << endl;cout << type << endl;cout << price << endl;if (empty == true){cout << "空" << endl;}else{cout << "滿" << endl;} }int Room::get_price(void) {return price; }int Room::get_room_number(void) {return room_number; }void Customer::customer_change1(int _time) {int time1=time;int price1=price;time = _time+time1;price = (price1/time1)*time; }void Customer::customer_change2(int _number,int _time,int _price) {time = _time;price += _price;room_number = _number; }void Customer::customer_show(void) {cout << "------------------------------" << endl;cout << "姓名:" << name << endl;cout << "房號:" << room_number << endl;cout << "消費金額:" << price << endl;cout << "押金:" << deposit << endl;cout << "時間:" << time;if (room_number/100 == 1){cout << "小時" << endl;}else{cout << "天" << endl;}if (0 == strcmp(accname,"null")){cout << "無隨行人員" << endl;}else{cout << "隨行人員:" << accname << endl;}cout << "------------------------------" << endl; }char* Customer::get_name(void) {return name; }int Customer::get_room_number(void) {return room_number; }

func.h

#ifndef FUNC_H #define FUNC_Hvoid run(void); void room_init(void); void open(void); void query(void); void out(void); void menu1(void); void menu2(void);#endif//FUNC_H

func.cpp

#include "func.h" #include "class.h" #include "tools.h" #include <stdlib.h>int num=0; Room* room[40]; Customer* customer[40];void run(void) {while(1){system("clear");menu1();switch(get_cmd('1','4')){case '1':open();break;case '2':query();break;case '3':out();break;case '4':return;}} }void room_init(void) {for(int i=1;i<=4;i++){for(int j=1;j<=10;j++){if (i==1){room[(i-1)*10+j] = new Room(i*100+j,i,20);}if (i==2){room[(i-1)*10+j] = new Room(i*100+j,i,100);}if (i==3){room[(i-1)*10+j] = new Room(i*100+j,i,200);}if (i==4){room[(i-1)*10+j] = new Room(i*100+j,i,300); }}} }void open(void) {char name[20];int room_number;int price;int deposit;int time;char accname[20];cout << "請輸入您的姓名" << endl;cin >> name;menu2();int n=0;cin >> n;if (n == 5) {return;}for(int i=1+10*(n-1);i<=10+10*(n-1);i++){if (room[i]->room_empty() == true){room_number = room[i]->get_room_number();deposit = 100;if (n == 1){cout << "請輸入要住幾小時的鐘點房" << endl;}else{cout << "請輸入要住的天數(shù)" << endl;}cin >> time;price = time*(room[i]->get_price());char c;while(1){cout << "是否有隨行人員(限1個) (y/n)" << endl;cin >> c;if (c == 'y'|c == 'n'){break;}cout << "輸入格式錯誤" << endl;}if (c == 'y'){cout << "請輸入隨行人員的姓名" << endl;cin >>accname;}else {strcpy(accname,"null");}customer[num++] = new Customer(name,room_number,price,deposit,time,accname);room[i]->room_change();break;}if (i == 10+10*(n-1)){cout << "抱歉,房間已滿!" << endl;}} } void query(void) {char name[20];cout << "請輸入您的姓名" << endl;cin >> name;for(int i=0;i<num;i++){if (0 == strcmp(customer[i]->get_name(),name)){customer[i]->customer_show();cout << "1、當前房間續(xù)費" << endl;cout << "2、換一種房間" << endl;cout << "3、返回" << endl;switch (get_cmd('1','3')){case '1':{int time = 0;if (customer[i]->get_room_number()/100 == 1){cout << "請輸入要續(xù)費的小時:" << endl;}else{cout << "請輸入要續(xù)費的天數(shù):" << endl;}cin >> time;customer[i]->customer_change1(time);cout << "續(xù)費成功!" << endl;break;}case '2':{menu2();int time=0;int n=0;int number=0;int price=0;cin >> n;if (n == 5) {return;}for(int j=1+10*(n-1);j<=10+10*(n-1);j++){if (room[j]->room_empty() == true){if (n == 1){cout << "請輸入要住幾小時的鐘點房" << endl;}else{cout << "請輸入要住的天數(shù)" << endl;}cin >> time;price = time*(room[j]->get_price());number = room[j]->get_room_number();room[j]->room_change();int _number = customer[i]->get_room_number();_number = (_number/100-1)*10+_number%100;room[_number]->room_change();customer[i]->customer_change2(number,time,price);break;}if (j == 10+10*(n-1)){cout << "抱歉,該種房間已滿!" << endl;}}}case '3':return;}}}cout << "無該顧客" << endl; }void out(void) {char name[20];cout << "請輸入您的姓名" << endl;cin >> name;for(int i=0;i<num;i++){if (0 == strcmp(customer[i]->get_name(),name)){int number = customer[i]->get_room_number();number = (number/100-1)*10+number%100;room[number]->room_change();cout << "退回您的100元押金,歡迎再次光臨" << endl;Customer *p =customer[i];delete p;for(int j=i;j<num;j++){customer[j]=customer[j+1];}customer[--num]=NULL;return;} }cout << "無該顧客" << endl; } void menu1(void) {cout << "*****歡迎來到指針賓館*****" << endl;cout << "1、開房" << endl;cout << "2、查詢及續(xù)費" << endl;cout << "3、退房" << endl;cout << "4、退出" << endl;cout << "************************" << endl; } void menu2(void) {cout << "************************" << endl;cout << "1、鐘點房 20/hour" << endl;cout << "2、標間 100/day" << endl;cout << "3、高級標間 200/day" << endl;cout << "4、豪華套房 300/day" << endl;cout << "5、退出" << endl;cout << "************************" << endl; }

tools.h

#ifndef TOOLS_H #define TOOLS_H#include <getch.h> char get_cmd(char start,char end);void clear_stdin(void);#endif//TOOLS_H

tools.cpp

#include "tools.h"//獲取指令 char get_cmd(char start,char end) {clear_stdin();printf("請輸入指令:");for(;;){char val = getch();if(val >= start && val <= end){printf("%c\n",val);return val;}} }//清理輸入緩沖區(qū) void clear_stdin(void) {stdin->_IO_read_ptr = stdin->_IO_read_end; }

總結(jié)

以上是生活随笔為你收集整理的基于C++的酒店管理系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。