1、 面向对象程序课程设计 (2014/2015学年第一学期第19周) 指导教师: 班级: 学号: 姓名: 面向对象程序课程设计任务书 【题目】酒店客房预订系统 【目的】 通过设计一个小型的快捷式酒店客房预订系统,训练综合运用所学知识处理实际问题的能力,强化面向对象的程序设计理念,使自己的程序设计与调试水平有一个明显的提高。 【要求】 1、每个学生必须独立完成; 2、课程设计时间为1周; 3、设计语言采用C++; 4、学生有事离校必须请假。课程设计期间,无故缺席按旷课处理;缺席时间达四分之一以上者,
2、未按规定上交实验报告的学生,其成绩按不及格处理。 【内容简介】 有一个小型的快捷式商务酒店,该酒店共现有10个房间,每个房间有两张床位,酒店全天24小时接受来客的客房预订服务。该酒店现计划使用客房预订系统来为顾客提供更方便快捷的客房预订服务。现在请你编写一个酒店客房预订系统的程序,使得这个客房预订系统能够正确工作。 【考核标准】 1、能够正确接受顾客的预订客房和退房申请,并正确结算房费(注意预定客房之前应首先查询出空闲的客房),成绩≥60; 2、能够实现对客房信息的管理(增加、删除、修改),成绩≥70; 3、能够统计每一天客房的预订情况成绩≥80; 4、能够考虑不同
3、类型(标准间、大床房、套房)的客房和价格,界面设计友好,成绩≥90。 请仔细考虑这个题目中出现的各个实体,考虑如何保存数据,使得即使在程序窗口关闭后,再次运行程序时之前的预定信息仍然有效。 【工作内容及工作计划】 时间 地点 工作内容 指导教师 12月 28日 上午 10-306 任务布置,需求分析 庄巧莉、杨东鹤 下午 10-306 系统功能划分 庄巧莉、杨东鹤 12月 29日 上午 10-306 类的整体设计 庄巧莉、杨东鹤 下午 10-306 类的详细设计 庄巧莉、杨东鹤 12月 30日 上午 10-306 编写代码
4、 庄巧莉、杨东鹤 下午 10-306 编写代码 庄巧莉、杨东鹤 12月 31日 上午 10-306 程序测试 庄巧莉、杨东鹤 下午 10-306 程序测试 庄巧莉、杨东鹤 1月 1日 上午 10-306 上机检查、答辩 庄巧莉、杨东鹤 下午 10-306 上机检查、答辩 庄巧莉、杨东鹤 面向对象程序课程设计 目 录 一、 题目 二、 需求分析 三、 系统结构图 四、 类的设计 五、 程序代码与说明 六、 运行结果与分析 七、 心得与体会 面向对象程序课程设计 一、 题目
5、 酒店客房预订系统 二、 需求分析 现今酒店的规模不断扩大, 客户预定以及房间信息管理等酒店管理操作急需更高效、更合理、且能动态保存的功能系统来实现,从而减少管理方面的工作量,为此,特完成此课程设计。 该课程设计采用c++语言实现对客户预订信息的基本管理,包括基本的客户预定、退订操作,以及客房信息的增加,删除和修改等操作,尽量考虑实用性与用户操作简便性。 三、 结构图 四、类的设计 此次课程设计一共设计了三个类。 1:首先是动态输出时间的类(借用了老师的程序)。 class CDate{ int d,m,y; const string df
6、s; const string df_l; public: CDate(int dd,int mm=1,int yy=1999); CDate(); void add_year(int n); void add_month(int n); void add_day(int n); string format(string df); int get_day() const; int get_month() const; int get_year() const; }; 2:这是顾客类,存放身份证号以及姓名 class Customer{
7、 protected: string name; //姓名 string ID; //身份证号 public: Customer(){}; void setname(string nam){name=nam;}//查询房客信息 void setID(string id){ID=id;}//查询房客信息 string get_name(){return name;} string get_ID(){return ID;} }; 3:这是房间类,用于得到每个房间的房间号和价格等信息,同时类中定义了is_use标志变量(用来标志预定过的房间),并将已
8、预订过的房间与顾客一一对应起来(类中定义Customer类的对象数组)。 class Room{ protected: int num;//房间号 Customer person; //一个人,住客 double price;//房价 int is_use; //是否被预定 public: Room(){} Customer& get_person(){ return person;}//为了得到房间里人的信息,这里有个返回人的函数 double get_price(){return price;} //得到价格 int get_num(){retu
9、rn num;} //得到房间号 int get_is_use(){return is_use;} //得到是否被预定的标志变量 void set_num(int number){num=number;}// 修改房间号,主要用于增加和删除房间 void set_price(double pric){price=pric;}//修改房价信息 void set_is_use(int i){is_use=i;} //修改标志变量 }; 4:管理类,实现客户预定、退订操作,管理员增减房间信息、修改房间价格、查询已被预定的房间的客户信息等操作,同时类中定义Room类的对象数组,
10、用于得到房间信息。 class Hotel_Manager{ protected: Room Standard[1000];//定义为数组,每一种房型,标准房 Room Superior[1000];//大床房 Room Deluxe[1000];//豪华房 int Stan_total ,Super_total , Del_total , Stan_residue , Super_residue , Del_residue; //记录每种房型的总量和剩余量 public: Hotel_Manager(); void book();//
11、预定房间
void retbook();//退房
void insert_room();//增加房间
void delete_room();//删除房间
void sets_price();//记录每天订房数
void search();//查找被预定房间的客户信息
void print(){
cout<<'\t'<<'\t'<<"房间类型"<<'\t'<<"房间价格"<<'\t'<<"房间总量"<<'\t'<<"房间余量"< 12、"/天"<<'\t'<<'\t'< 13、< 14、int yy=1999);
CDate();
void add_year(int n);
void add_month(int n);
void add_day(int n);
string format(string df);
int get_day() const;
int get_month() const;
int get_year() const;
};
class Customer{
protected:
string name;
string ID;
public:
Customer(){};
void setname 15、string nam){name=nam;}//查询房客信息
void setID(string id){ID=id;}//查询房客信息
string get_name(){return name;}
string get_ID(){return ID;}
};
class Room{
protected:
int num;//房间号
Customer person; //一个人,住客
double price;//房价
int is_use; //是否被预定
public:
Room(){}
Customer& get_person(){ 16、 return person;}//为了得到房间里人的信息,这里有个返回人的函数
double get_price(){return price;}
int get_num(){return num;}
int get_is_use(){return is_use;}
void set_num(int number){num=number;}
void set_price(double pric){price=pric;}//修改房价信息
void set_is_use(int i){is_use=i;}
};
class Hotel_Manager{
prote 17、cted:
Room Standard[1000];//定义为数组,每一种房型
Room Superior[1000];
Room Deluxe[1000];
int Stan_total ,Super_total , Del_total , Stan_residue , Super_residue , Del_residue;
//记录每种房型的总量和剩余量
public:
Hotel_Manager();
void book();//预定房间
void retbook();//退房
void insert_room();//增加房间 18、
void delete_room();//删除房间
void sets_price();//记录每天订房数
void search();//查找被预定房间的客户信息
void print(){
cout<<'\t'<<'\t'<<"房间类型"<<'\t'<<"房间价格"<<'\t'<<"房间总量"<<'\t'<<"房间余量"< 19、< 20、
};
hotel.cpp
#include"hotel.h"
CDate::CDate(int dd, int mm, int yy):df_s("ddd"),df_l("DDD") //初始化
{
if((mm>=1 && mm<=12) && (dd>=1 && dd<=31))
{
m = mm; d = dd; y = yy;
}else {
m = 0; d = 0; y = 0;
cout<<"the date created is wrong"< 21、e():df_s("ddd"),df_l("DDD") //初始化
{
time_t now;
time(&now);
struct tm *t_now;
t_now = localtime(&now);
y = t_now -> tm_year + 1900;
m = t_now -> tm_mon + 1;
d = t_now -> tm_mday;
}
void CDate::add_year(int n) //加n年
{
y += n;
}
void CDate::add_mont 22、h(int n) //加n月
{
m += n;
}
void CDate::add_day(int n) //加n天
{
d += n;
}
string CDate::format(string df)
{
char c_df[20];
if(df == df_s)
{
sprintf(c_df, "%d-%d-%d", y, m, d);
return string(c_df);
}
if(df == df_l)
{
sprintf(c_d 23、f, "%d年%d月%d日", y, m, d);
return string(c_df);
}
return string("");
}
int CDate::get_day() const
{
return d;
}
int CDate::get_month() const
{
return m;
}
int CDate::get_year() const
{
return y;
}
Hotel_Manager::Hotel_Manager()
{
fstream iofile;
iofile.open("D:\\Hot 24、el.txt",ios::in);
if(iofile.fail())
{
Stan_total=Stan_residue=5;
Super_total=Super_residue=3;
Del_total=Del_residue=2;
for(int i=101;i<=105;i++)
{Standard[i-101].set_num(i);
Standard[i-101].set_is_use(0);
Standard[i-101].set_price(200); }
for(int i=201;i<=203; 25、i++)
{Superior[i-201].set_num(i);
Superior[i-201].set_is_use(0);
Superior[i-201].set_price(400); }
for(int i=301;i<=302;i++)
{Deluxe[i-301].set_num(i);
Deluxe[i-301].set_is_use(0);
Deluxe[i-301].set_price(800); }
}
else
{
int num;
double price;
str 26、ing name,id;
int is_use;
iofile >> Stan_total >> Super_total >> Del_total >> Stan_residue >> Super_residue >> Del_residue;
for(int i=0;i 27、 if(is_use==1)
{
iofile>>name>>id;
Standard[i].get_person().setname(name);
Standard[i].get_person().setID(id);
}
}
for(int i=0;i 28、t_is_use(is_use);
if(is_use==1)
{
iofile>>name>>id;
Superior[i].get_person().setname(name);
Superior[i].get_person().setID(id);
}
}
for(int i=0;i< Del_total;i++)
{
iofile>>num>>price>>is_use;
Deluxe[i].set_num(num);
Deluxe[i].set_price(price);
29、
Deluxe[i].set_is_use(is_use);
if(is_use==1)
{
iofile>>name>>id;
Deluxe[i].get_person().setname(name);
Deluxe[i].get_person().setID(id);
}
}
}
iofile.close();
}
void Hotel_Manager::insert_room(){
cout<<"请选择要增加的房间类型:"< 30、 3:豪华房 0:撤销操作"< 31、rice;
Standard[Stan_total].set_num(num); //因为Stan_total为总量,所以下标为Stan_total-1的位置为最后一个元素,所以要把新的房间添加在Stan_total个位置
Standard[Stan_total].set_price(price);
Standard[Stan_total].set_is_use(0);//0表示未被预定
Standard[Stan_total].get_is_use();
Stan_total++; //标准房总量加一
Stan_ 32、residue++; //标准房余量加一
}
if(f==2){
cout<<"当前已有房间:"< 33、[Super_total].set_price(price);
Superior[Super_total].set_is_use(0);//0表示未被预定
Superior[Super_total].get_is_use();
Super_total++; //大床房总量加一
Super_residue++; //大床房余量加一
}
if(f==3){
cout<<"当前已有房间:"< 34、num()<<"\t";
}
cout< 35、l_residue++; //豪华房余量加一
}
}
void Hotel_Manager::delete_room(){
cout<<"请选择要删除的房间类型:"< 36、
cout< 37、
}
}
if(f==2){
cout<<"当前已有房间:"< 38、r_total-1;j++)
Superior[j]=Superior[j+1];
Super_total--;
Super_residue--;
cout<<"删除成功!"< 39、ut<<"请输入需要删除的房间号:";
cin>>num;
for(int i=0;i 40、
}
void Hotel_Manager::book(){
cout<<"请选择要预定的房间类型:"< 41、 if(Standard[i].get_is_use()==0){
cout< 42、<"请输入客户姓名以及证件号:"< 43、i 44、k;
}
}
cout<<"请输入客户姓名以及证件号:"< 45、e;
}
for(i=0;i 46、 break;
}
}
cout<<"请输入客户姓名以及证件号:"< 47、f3=0;
cout<<"标准房已被预订:"< 48、is_use()==1){
f2=1;
cout< 49、均未被预定!";
cout< 50、t i=0;i






