- 浏览: 434673 次
文章分类
最新评论
我的第一个小项目
#ifdef HOTEL_H #define HOTEL_H /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// int menu(); //菜单选项 void add_hotel(); //增加酒店 void add_list(); //增加定单 void sum_list(); //取消定单 void findcty(); //查找城市 /////////////////////////////////////////////////////////////////////////////// class Hotel { private: int No; //酒店编号 string name; //酒店名称 string cty; //所在城市 int total_room; //总房数 int proom; //普通房数 int proom_empty; //普通空房数 double proom_money; //普通房价 int hroom; //高级房数 int hroom_empty; //高级空房数 double hroom_money; //高级房价 public: Hotel(); //初始化对象属性 ~Hotel(); //析构函数 void input(); //输入酒店信息 int turn(bool a); //根据布尔值返回空房间数目 void Dingdan(int strct,int strnum); //来定单时,修改对象基本属性 void output(); //输出酒店信息 void unDingdan(int strct,int strnum); //取消单时,修改对象基本属性 string turnname(){return name;} //返回酒店名称 string turncty(){return cty;} //返回城市名字 int num(int number){No=number;} //生成编号 /////////////////////////////////////////////////////////////////////////////// friend ostream& operator << (ostream &out,Hotel &hot) { out <<hot.No<<" "<<hot.name<<" "<<hot.cty<<" "<<hot.total_room <<" "<<hot.proom<<" "<<hot.proom_empty<<" "<<hot.proom_money <<" "<<hot.hroom<<" "<<hot.hroom_empty<<" "<<hot.hroom_money <<endl; return out; } /////////////////////////////////////////////////////////////////////////////// friend istream& operator >> (istream &in,Hotel &hot) { in >> hot.No >> hot.name >> hot.cty >> hot.total_room >>hot.proom >> hot.proom_empty >> hot.proom_money >>hot.hroom >> hot.hroom_empty >> hot.hroom_money; return in; } }; /////////////////////////////////////////////////////////////////////////////// int loadfile(list<Hotel> &list_hot); void savefile(list<Hotel> &list_hot); /////////////////////////////////////////////////////////////////////////////// class Yuding { private: int No; //定单编号 int hotelNo; //酒店编号 bool strct; //房间类型 int strnum; //定房数目 string name; //订者姓名 string tel; //联系电话 string email; //email地址 public: Yuding(); //构造函数 ~Yuding(); //析构函数 void input(list<Hotel>&,int&); //定单输入 void output(); //定单输出 void num(int number){No=number;} //自动编号 int rehotelNo(){return hotelNo;} //返回酒店编号 int restrct(){return strct;} //返回酒店类型 int restrnum(){return strnum;} //返回预定房间数量 /////////////////////////////////////////////////////////////////////////////// friend ostream& operator << (ostream &out,Yuding &yuding) { out <<" "<<yuding.No<<" "<<yuding.hotelNo<<" "<<yuding.strct <<" "<<yuding.name<<" "<<yuding.tel<<" "<<yuding.email<<endl; return out; } ///////////////////////////////////////////////////////////////////////////// friend istream& operator >> (istream &in,Yuding &yuding) { in >>yuding.No>>yuding.hotelNo>>yuding.strct>>yuding.name >>yuding.tel>>yuding.email; return in; } }; ///////////////////////////////////////////////////////////////////////////// inline int loadfile(list<Yuding> &list_hot); inline void savefile(list<Yuding> &list_hot); ///////////////////////////////////////////////////////////////////////////// class Yuding { private: int No; //定单编号 int hotelNo; //酒店编号 bool strct; //房间类型 int strnum; //定房数目 string name; //订者姓名 string tel; //联系电话 string email; //email地址 public: Yuding(); //构造函数 ~Yuding(); //析构函数 void input(list<Hotel> &hot,int &num) //定单输入 void output(); //定单输出 int num(int number){No=number;} //自动编号 int rehotelNo(){return hotelNo;} //返回酒店编号 int restrct(){return strct;} //返回酒店类型 int restrnum(){return strnum;} //返回预定房间数量 //////////////////////////////////////////////////////////////////////////// friend ostream& operator << (ostream &out,Yuding &yuding) { out <<" "<<yuding.No<<" "<<yuding.hotelNo<<" "<<yuding.strct<<" "<<yuding.name <<" "<<yuding.tel<<" "<<yuding.email<<endl; return out; } ///////////////////////////////////////////////////////////////////////////// friend istream& operator >> (istream &in,Yuding &yuding) { in >>yuding.No>>yuding.hotelNo>>yuding.strct>>yuding.name >>yuding.tel>>yuding.email; return in; } }; ///////////////////////////////////////////////////////////////////////////// inline int loadfile(list<Yuding> &list_hot); inline void savefile(list<Yuding> &list_hot); #endif /////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <string> #include <fstream> #include <iomanip> #include <list> using namespace std; ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// int menu(); //菜单选项 void add_hotel(); //增加酒店 void add_list(); //增加定单 void sum_list(); //取消定单 void findcty(); //查找城市 ////////////////////////////////////////////////////////////////////////// class Hotel { private: int No; //酒店编号 string name; //酒店名称 string cty; //所在城市 int total_room; //总房数 int proom; //普通房数 int proom_empty; //普通空房数 double proom_money; //普通房价 int hroom; //高级房数 int hroom_empty; //高级空房数 double hroom_money; //高级房价 public: Hotel(); //初始化对象属性 ~Hotel(); //析构函数 void input(); //输入酒店信息 int turn(bool a); //根据布尔值返回空房间数目 void Dingdan(int strct,int strnum); //来定单时,修改对象基本属性 void output(); //输出酒店信息 void unDingdan(int strct,int strnum); //取消单时,修改对象基本属性 string turnname(){return name;} //返回酒店名称 string turncty(){return cty;} //返回城市名字 int num(int number){No=number;} //生成编号 ///////////////////////////////////////////////////////////////////////// friend ostream& operator << (ostream &out,Hotel &hot) { out <<hot.No<<" "<<hot.name<<" "<<hot.cty<<" "<<hot.total_room <<" "<<hot.proom<<" "<<hot.proom_empty<<" "<<hot.proom_money <<" "<<hot.hroom<<" "<<hot.hroom_empty<<" "<<hot.hroom_money <<endl; return out; } ///////////////////////////////////////////////////////////////////////// friend istream& operator >> (istream &in,Hotel &hot) { in >> hot.No >> hot.name >> hot.cty >> hot.total_room >>hot.proom >> hot.proom_empty >> hot.proom_money >>hot.hroom >> hot.hroom_empty >> hot.hroom_money; return in; } }; /////////////////////////////////////////////////////////////////////////// int loadfile(list<Hotel> &list_hot); void savefile(list<Hotel> &list_hot); /////////////////////////////////////////////////////////////////////////// class Yuding { private: int No; //定单编号 int hotelNo; //酒店编号 bool strct; //房间类型 int strnum; //定房数目 string name; //订者姓名 string tel; //联系电话 string email; //email地址 public: Yuding(); //构造函数 ~Yuding(); //析构函数 void input(list<Hotel>&,int&); //定单输入 void output(); //定单输出 void num(int number){No=number;} //自动编号 int rehotelNo(){return hotelNo;} //返回酒店编号 int restrct(){return strct;} //返回酒店类型 int restrnum(){return strnum;} //返回预定房间数量 //////////////////////////////////////////////////////////////////////////// friend ostream& operator << (ostream &out,Yuding &yuding) { out <<" "<<yuding.No<<" "<<yuding.hotelNo<<" "<<yuding.strct <<" "<<yuding.name<<" "<<yuding.tel<<" "<<yuding.email<<endl; return out; } ///////////////////////////////////////////////////////////////////////////// friend istream& operator >> (istream &in,Yuding &yuding) { in >>yuding.No>>yuding.hotelNo>>yuding.strct>>yuding.name >>yuding.tel>>yuding.email; return in; } }; ///////////////////////////////////////////////////////////////////////////// inline int loadfile(list<Yuding> &list_hot); inline void savefile(list<Yuding> &list_hot); ////////////////////////////菜单选项////////////////////////////////////////////// /////PUTONG/// int menu() { const int b=85; int a; bool c=0; while(!c) { cout <<"/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n" << setfill(' ') << setw(100) << "欢迎使用星光酒店管理系统/n/n" << setfill(' ') << setw(86) << "请按Enter继续/n" << "/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n" <<endl; cin.get(); cout <<"/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n" <<setfill(' ') << setw(b) <<"1、添加酒店资料"<<endl<<endl; cout <<setfill(' ') << setw(b) <<"2、增 加 订 单 "<<endl<<endl; cout <<setfill(' ') << setw(b) <<"3、取 消 订 单 "<<endl<<endl; cout <<setfill(' ') << setw(b) <<"4、查寻城市酒店"<<endl<<endl; cout <<setfill(' ') << setw(b) <<"5、退出星光系统"<<endl<<endl<<endl<<endl; cout <<setfill(' ') << setw(b+1) <<"请输入数字选择/n"<<endl; cout << "/n/n/n/n/n/n/n/n/n/n/n/n/n/n"<<endl; cin>>a; if ((a<1)||(a>5)) { c=0; } else { c=1; } } return a; } ///////////////////////////增加酒店//////////////////////////////////////////////// void add_hotel() { list<Hotel> hot; loadfile(hot); for(list<Hotel>::iterator vec_hot=hot.begin();vec_hot!=hot.end();vec_hot++) { cout<<*vec_hot; } bool a=1; Hotel input; while(a) { input.input(); hot.push_back(input); bool b=1; string x; while(b) { cout <<"是否继续输入?(Y/N)ENTER"; cin>>x; if(x=="y"||x=="Y") { a=1; b=0; } else if(x=="n"||x=="N") { a=0; b=0; } else { b=1; cout <<"您输入的不正确请重新输入"<<endl; } } } savefile(hot); } //////////////////////////////增加定单///////////////////////////////////////// void add_list() { int num1,num2; list<Hotel> hot; list<Yuding> Yud; num2=loadfile(Yud); num1=loadfile(hot); if (num1<1) { cout <<"没有酒店信息,请录入后再使用预定系统"<<endl; exit(0); } for(list<Yuding>::iterator li_Yud=Yud.begin();li_Yud!=Yud.end();li_Yud++) { cout<<*li_Yud; } bool a=1; Yuding input; while(a) { input.input(hot,num1); Yud.push_back(input); bool b=1; char x; while(b) { cout <<"是否继续输入?(Y/N)ENTER确认:"; cin>>x; if(x==*"y"||x==*"Y") { a=1; b=0; } else if(x==*"n"||x==*"N") { a=0; b=0; } else { b=1; cout <<"您输入的不正确请重新输入"<<endl; } } } savefile(Yud); savefile(hot); } //////////////////////////////取消定单///////////////////////////////////////// void sum_list() { int num1,num2; list<Hotel> hot; list<Yuding> Yud; num2=loadfile(Yud); num1=loadfile(hot); if (num2<1) { cout <<"没有预定信息,请录入后再使用取消预定系统"<<endl; exit(0); } int abdc=0; bool b=1; while(b) { for(list<Yuding>::iterator li_Yud=Yud.begin();li_Yud!=Yud.end();li_Yud++) { li_Yud->output(); abdc++; if (abdc%20==0) { cout<<"按任意键继续"; cin.get(); } } cout <<"请输入取消定单的编号"<<endl; int number; cin >>number; if (number>num2) { cout<<"你输入的定单编号不存在请重新输入:"<<endl; b=1; break; } list<Yuding>::iterator li_Yud=Yud.begin(); Yuding temp; for (int i=1;i<number;i++) { li_Yud++; } temp=*li_Yud; list<Hotel>::iterator li_hot=hot.begin(); for(int i=1;i<temp.rehotelNo();i++) { li_hot++; } li_hot->unDingdan(temp.restrct(),temp.restrnum()); if (li_Yud!=Yud.end()) { Yud.erase(li_Yud); } else { Yud.pop_back(); } cout <<"是否继续?(y/n)"<<endl; string a; cin>>a; if (a=="y"||a=="Y") { b=1; } else { b=0; } savefile(hot); savefile(Yud); } } ///////////////////////////查找城市//////////////////////////////////////////// void findcty() { int num=0; list<Hotel> hot; loadfile(hot); savefile(hot); for(list<Hotel>::iterator vec_hot=hot.begin();vec_hot!=hot.end();vec_hot++) { cout<<*vec_hot; } bool a=1; string b; while(a) { cout <<"请输入想要查找的城市"<<endl; cin >> b; for(list<Hotel>::iterator li_hot=hot.begin();li_hot!=hot.end();li_hot++) { string c=li_hot->turncty(); if(b==c) { li_hot->output(); num++; } } if (num==0) { cout <<"没有找到你输入的城市/n"<<endl; } else { cout<<"一共找到"<<num<<"个酒店!"<<endl; } cout <<"是否继续查找?(y/n)/n"; cin>> b; if (b=="y"||b=="Y") { a=1; } else { a=0; } } } /////////////////////////////////////////////////////////////////////////////// ///////////////////////////////读取文件//////////////////////////////////////// inline int loadfile(list<Hotel> &list_hot) { ifstream infile("hot.dat"); int num=1; if (!infile) { cout <<"第一次运行程序吗?如果不是您的数据文件可能丢失!"<<endl; } else { Hotel temp; while (infile >> temp) { temp.num(num); list_hot.push_back(temp); num++; } infile.close(); infile.clear(); } return num-1; } ///////////////////////////////读取文件/////////////////////////////////////// inline int loadfile(list<Yuding> &list_hot) { ifstream infile("yud.dat"); int num=1; if (!infile) { cout <<"第一次运行程序吗?如果不是您的数据文件可能丢失!"<<endl; } else { Yuding temp; while (infile >> temp) { temp.num(num); list_hot.push_back(temp); num++; } infile.close(); infile.clear(); } return num-1; } /////////////////////////////写入文件///////////////////////////////////////// inline void savefile(list<Hotel> &list_hot) { ofstream outfile("hot.dat"); for(list<Hotel>::iterator li_hot=list_hot.begin();li_hot!=list_hot.end();li_hot++) { outfile<<*li_hot; } outfile.close(); outfile.clear(); } /////////////////////////////写入文件/////////////////////////////////////////// inline void savefile(list<Yuding> &list_hot) { ofstream outfile("yud.dat"); for(list<Yuding>::iterator li_hot=list_hot.begin();li_hot!=list_hot.end();li_hot++) { outfile<<*li_hot; } outfile.close(); outfile.clear(); } /////////////////////////////构造函数/////////////////////////////////////////// //CLASSHOTEL///// Hotel::Hotel() //初始化对象属性 { No=0; name="NONE"; cty="NONE"; total_room=0; proom=0; proom_empty=0; proom_money=0.00; hroom=0; hroom_empty=0; hroom_money=0.00; } //////////////////////////////////析构函数///////////////////////////////////// Hotel::~Hotel(){} /////////////////////////////////输入酒店信息////////////////////////////////// void Hotel::input() { bool b=1; while(b) { cout<<"/n请输入酒店名称:"; cin >> name; cout<<"/n请输入所在城市:"; cin>> cty; cout<<"/n请输入总房间数:"; cin>>total_room; cout<<"/n请输入普通房间数:"; cin>>proom; cout<<"/n请输入普通空房数:"; cin>>proom_empty; cout<<"/n请输入普通标准房价格:"; cin>>proom_money; cout<<"/n请输入豪华房间数:"; cin>>hroom; cout<<"/n请输入空豪华房间数:"; cin>>hroom_empty; cout<<"请输入豪华房价格:"; cin>>hroom_money; if (proom>total_room ||hroom>total_room ||proom+hroom>total_room ||proom_empty>proom ||hroom_empty>hroom ||proom_money>hroom_money) { cout <<"您的输入有误,请重新输入!"<<endl; b=1; } else { b=0; } } } //////////////////////////////////返回房间数/////////////////////////////////// int Hotel::turn(bool a) { if (a) { return proom_empty; } else { return hroom_empty; } } ////////////////////////////来定单时,修改对象基本属性///////////////////////// void Hotel::Dingdan(int strct,int strnum) { cout <<"进入"<<strct<<strnum<<endl; if (strct) { proom_empty-=strnum; } else { hroom_empty-=strnum; } cout <<"修改成功!"<<endl; } ////////////////////////////////输出酒店信息/////////////////////////////////// void Hotel::output() { cout<<No<<"| "<<name<<"| "<<cty<<"| "<< total_room<<"| "<<proom <<"| "<<proom_empty<<"| "<<proom_money<<"| "<<hroom <<"| "<<hroom_empty<<"| "<<hroom_money<<endl; } //////////////////////////取消单时,修改对象基本属性/////////////////////////// void Hotel::unDingdan(int strct,int strnum) { if (strct) { proom_empty+=strnum; } else { hroom_empty+=strnum; } cout <<"修改成功!"<<endl; } //////////////////////////////构造函数///////////////////////////////////////// ////CLASSYUDING// Yuding::Yuding() { No=0; hotelNo=0; strct=0; name="NONE"; tel="NOnumber"; email="NOemail"; } /////////////////////////////////析构函数/////////////////////////////////////// Yuding::~Yuding(){} /////////////////////////////////定单输入/////////////////////////////////////// void Yuding::input(list<Hotel> &hot,int &num) { cout <<"本系统现在共有"<<num<<"家酒店信息"<<endl; bool b=1; while(b) { cout<<"/n清输入酒店编号:/n"; cin>> hotelNo; if (hotelNo>num) { cout <<"您输入的酒店编号不存在,请重新输入!"<<endl; b=1; break; } list<Hotel>::iterator map=hot.begin(); for(int i=1;i<hotelNo;i++) { map++; } int cls=map->turn(strct); string hotname=map->turnname(); cout<<"欢迎光临您预定"<<hotname <<"酒店客房!你如果需要高级房客请按Y,如果需要普通客房请按N.(y/n)/n"; string strct1 ; cin >> strct1; if (strct1=="y"||strct1=="Y") { strct=false; } else if(strct1=="n"||strct1=="N") { strct=true; } else { cout <<"你输入有误请重新输入:"<<endl; break; } cout<<"本店"<<(strct>0)?"空普通客房还有":"空豪华客房还有") <<cls<<"间请输入定房数目:/n"; cin>>strnum; if(strnum>cls) { cout <<"哦,你输入的房间数大于此酒店的空房数,请重新输入:/n"; b=1; break; } cout<<"请输入预订者姓名:/n"; cin >> name; cout<<"请输入预订者电话:/n"; cin>>tel; cout<<"请输入预订者email:/n"; cin>>email; map->Dingdan(strct,strnum); b=0; } } ////////////////////////////////定单输出/////////////////////////////////////// void Yuding::output() { cout <<endl<<" | "<<No<<" | "<<hotelNo <<" | "<<strct<<" | " << strnum <<" | "<<name<<" | "<<tel<<" | " <<email<<" | "<<endl; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int main() { int a; do { a=menu(); switch(a) { case 1: add_hotel(); break; case 2: add_list(); break; case 3: sum_list(); break; case 4: findcty(); break; case 5: a=0; break; } }while(a); return 0; }
<hot.no></hot.no><hot.name></hot.name><hot.cty></hot.cty><hot.total_room></hot.total_room><hot.proom></hot.proom><hot.proom_empty></hot.proom_empty><hot.proom_money></hot.proom_money><hot.hroom></hot.hroom><hot.hroom_empty></hot.hroom_empty><hot.hroom_money></hot.hroom_money>
相关推荐
webservice 第一个开发小项目,java
第一个项目Demo第一个项目Demo第一个项目Demo第一个项目Demo
spring boot入门的第一个项目spring boot入门的第一个项目spring boot入门的第一个项目spring boot入门的第一个项目
这个是我的第一个项目,大家一定要捧场啊,哈哈哈哈哈哈啊
小程序第一个项目——安心食疗
一期项目网站第一名一期项目网站第一名一期项目网站第一名一期项目网站第一名一期项目网站第一名一期项目网站第一名一期项目网站第一名一期项目网站第一名一期项目网站第一名一期项目网站第一名一期项目网站第一名一...
简洁的记录了自己写第一个springmvc项目的过程,里面有源码,还有详细的教程里连接地址,下面那个图是我自己创作的,是自己的理解,请注意不要误解
我们学了几天的HTML,这是我们的第一项目
初学PHP,使用的工具是PHPStorm + XAMPP。 这是我写的一个非常简单的有增删改查以及异步ajax功能的PHP程序。 希望同样是初学者的你有帮助。
手把手教你实现第一个SSH项目
第一个SpringBoot入门级项目,第一个SpringBoot入门级项目
搭建第一个Eureka应用熟悉理解对微服务注册与发现框架Eureka的理解。
初学者第一个小项目基于JDBC+oracle实现图书管理系统,在控制台实现数据!
Android Kotlin项目:第一个Kotlin项目
这是spring security第一个项目
C#6.0学习笔记从第一行C#代码到第一个项目设计。。。。。。。。。。。。。。。。。。
C#6.0学习笔记 从第一行C#代码到第一个项目设计 随书源码
这是我做的第一个项目.这是我学习后做的第一个项目
这是我的第一个java项目,虽然不是蛮好,但是觉得还是上传分享。这个项目的部分功能未能完善,正在升级中。