(2014/2015学年第一学期第19周)
指导教师: 庄巧莉、杨东鹤
班级:
学号:
姓名:
面向对象程序课程设计任务书
【题目】酒店客房预订系统
【目的】
通过设计一个小型的快捷式酒店客房预订系统,训练综合运用所学知识处理实际问题的能力,强化面向对象的程序设计理念,使自己的程序设计与调试水平有一个明显的提高。
【要求】
1、每个学生必须完成;
2、课程设计时间为1周;
3、设计语言采用C++;
4、学生有事离校必须请假。课程设计期间,无故缺席按旷课处理;缺席时间达四分之一以上者,未按规定上交实验报告的学生,其成绩按不及格处理。
【内容简介】
有一个小型的快捷式商务酒店,该酒店共现有10个房间,每个房间有两张床位,酒店全天24小时接受来客的客房预订服务。该酒店现计划使用客房预订系统来为顾客提供更方便快捷的客房预订服务。现在请你编写一个酒店客房预订系统的程序,使得这个客房预订系统能够正确工作。
【考核标准】
1、能够正确接受顾客的预订客房和退房申请,并正确结算房费(注意预定客房之前应首先查询出空闲的客房),成绩≥60;
2、能够实现对客房信息的管理(增加、删除、修改),成绩≥70;
3、能够统计每一天客房的预订情况成绩≥80;
4、能够考虑不同类型(标准间、大床房、套房)的客房和价格,界面设计友好,成绩≥90。
请仔细考虑这个题目中出现的各个实体,考虑如何保存数据,使得即使在程序窗口关闭后,再次运行程序时之前的预定信息仍然有效。
【工作内容及工作计划】
| 时间 | 地点 | 工作内容 | 指导教师 | |
| 12月 28日 | 上午 | 10-306 | 任务布置,需求分析 | 庄巧莉、杨东鹤 |
| 下午 | 10-306 | 系统功能划分 | 庄巧莉、杨东鹤 | |
| 12月 29日 | 上午 | 10-306 | 类的整体设计 | 庄巧莉、杨东鹤 |
| 下午 | 10-306 | 类的详细设计 | 庄巧莉、杨东鹤 | |
| 12月 30日 | 上午 | 10-306 | 编写代码 | 庄巧莉、杨东鹤 |
| 下午 | 10-306 | 编写代码 | 庄巧莉、杨东鹤 | |
| 12月 31日 | 上午 | 10-306 | 程序测试 | 庄巧莉、杨东鹤 |
| 下午 | 10-306 | 程序测试 | 庄巧莉、杨东鹤 | |
| 1月 1日 | 上午 | 10-306 | 上机检查、答辩 | 庄巧莉、杨东鹤 |
| 下午 | 10-306 | 上机检查、答辩 | 庄巧莉、杨东鹤 | |
一、题目
二、需求分析
三、系统结构图
四、类的设计
五、程序代码与说明
六、运行结果与分析
七、心得与体会
1、题目
【题目】酒店客房预订系统
【目的】
通过设计一个小型的快捷式酒店客房预订系统,训练综合运用所学知识处理实际问题的能力,强化面向对象的程序设计理念,使自己的程序设计与调试水平有一个明显的提高。
【内容简介】
有一个小型的快捷式商务酒店,该酒店共现有10个房间,每个房间有两张床位,酒店全天24小时接受来客的客房预订服务。该酒店现计划使用客房预订系统来为顾客提供更方便快捷的客房预订服务。现在请你编写一个酒店客房预订系统的程序,使得这个客房预订系统能够正确工作。
2、需求分析
系统要求能满足订房和退房的需求,对房间的信息像房号、类型、价格能进行修改以及对房间的添加及删除的操作,并且能够统计预定情况。如图2-1前台用例图,2-2管理员用例图。
2-1前台用例图
2-2管理员用例图
3、系统结构图
酒店客房预定系统下为预定客房、退房和客房管理三大模块。其中客房管理包含添加、删除、修改和统计预定情况四个操作。见4-1系统结构图。
3-1系统结构图
4、类的设计
酒店预定系统类的设计,有酒店管理系统,房间(room.h),住客(customer.h)、日期(date.h)、信息输入(information.h)、管理(Manager.h)间图4-1酒店预定系统类的设计图。
4-1酒店预定系统类的设计图
5、程序代码及说明
//date.h 日期头文件
#include class date{ private: int year, month, day; public: date(); int get_year(){ return year; } int get_month(){ return month; } int get_day(){ return day; } void set_day(int d){ day = d; } void set_mon(int m){ month= m; } void set_year(int y){ year = y; } }; //date.cpp 日期源文件 #include"stdafx.h" #include"Date.h" date::date() //构造函数:日期默认为系统时间 { time_t now; time(&now); struct tm *t_now; t_now = localtime(&now); year= t_now->tm_year + 1900; month = t_now->tm_mon + 1; day = t_now->tm_mday; } //customer.h 住客头文件 #include #include"Date.h" using namespace std; class customer{ public: string name,ID; date book_time; void set_name(string n) { name = n; }; void set_ID(string id) { ID = id; } }; //ROOM.h #include"Person.h" class room{ public: int num, prize; string kind; customer *cus; int flag; public: room(){ prize = 0, num = 1, flag = 0; cus = new customer[10]; } }; // 酒店客房预定系统Dlg.h #pragma once #include"information.h" #include"DlgManager.h" #include "afxwin.h" #include #include #include "afxdtctl.h" using namespace std; class C酒店客房预订系统Dlg : public CDialogEx { // 构造 public: C酒店客房预订系统Dlg(CWnd* pParent = NULL); // 标准构造函数 // 对话框数据 enum { IDD = IDD_MY_DIALOG }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: HICON m_hIcon; // 生成的消息映射函数 virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP() public: afx_msg void OnBnClicked订房(); afx_msg void OnBnClicked退房(); afx_msg void OnBnClicked查询(); afx_msg void OnBnClicked管理员(); afx_msg void OnLbnSelchangeList1(); void update_room(); int cus_day(); CListBox m_listbox; private: int n,m; room r[1000]; }; // 酒店客房预订系统Dlg.cpp : 实现文件 #include "stdafx.h" #include "酒店客房预订系统.h" #include "酒店客房预订系统Dlg.h" #include "afxdialogex.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 class CAboutDlg : public CDialogEx { public: CAboutDlg(); // 对话框数据 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP() // C酒店客房预订系统Dlg 对话框 C酒店客房预订系统Dlg::C酒店客房预订系统Dlg(CWnd* pParent /*=NULL*/) : CDialogEx(C酒店客房预订系统Dlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); ifstream is("room.txt"); is >> m; for (int i = 0; i < m; i++) { char b; is >> r[i].num; is >> r[i].kind; is >> r[i].prize >> r[i].flag; for (int j = 0; j < r[i].flag; j++){ is >> r[i].cus[j].name >> r[i].cus[j].ID; int y, m, d; is >> y >> b >> m >> b >> d; r[i].cus[j].book_time.set_day(d); r[i].cus[j].book_time.set_mon(m); r[i].cus[j].book_time.set_year(y); is >> y >> b >> m >> b >> d; r[i].cus[j].end_time.set_day(d); r[i].cus[j].end_time.set_mon(m); r[i].cus[j].end_time.set_year(y); } } } void C酒店客房预订系统Dlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST1, m_listbox); DDX_Control(pDX, IDC_DATETIMEPICKER1, m_cdatectr); } BEGIN_MESSAGE_MAP(C酒店客房预订系统Dlg, CDialogEx) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, &C酒店客房预订系统Dlg::OnBnClicked订房) ON_BN_CLICKED(IDC_BUTTON2, &C酒店客房预订系统Dlg::OnBnClicked退房) ON_BN_CLICKED(IDC_BUTTON3, &C酒店客房预订系统Dlg::OnBnClicked查询) ON_BN_CLICKED(IDC_BUTTON4, &C酒店客房预订系统Dlg::OnBnClicked管理员) ON_LBN_SELCHANGE(IDC_LIST1, &C酒店客房预订系统Dlg::OnLbnSelchangeList1) END_MESSAGE_MAP() // C酒店客房预订系统Dlg 消息处理程序 BOOL C酒店客房预订系统Dlg::OnInitDialog() { CDialogEx::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } void C酒店客房预订系统Dlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialogEx::OnSysCommand(nID, lParam); } } // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序, // 这将由框架自动完成。 void C酒店客房预订系统Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast // 使图标在工作区矩形中居中 int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CDialogEx::OnPaint(); } } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR C酒店客房预订系统Dlg::OnQueryDragIcon() { return static_cast } void C酒店客房预订系统Dlg::update_room() { ofstream os("room.txt"); int i, j; os << m << "\\n"; for (i = 0; i < m; i++) { os << r[i].num << " "; os << r[i].kind << " "; os << r[i].prize << " " << r[i].flag << "\\n"; for (j = 0; j < r[i].flag;j++) { os << " " << r[i].cus[j].name << " " << r[i].cus[j].ID; os << " " << r[i].cus[j].book_time.get_year() << "-"; os << r[i].cus[j].book_time.get_month() << "-" << r[i].cus[j].book_time.get_day(); os << " " << r[i].cus[j].end_time.get_year() << "-"; os << r[i].cus[j].end_time.get_month() << "-" << r[i].cus[j].end_time.get_day(); os << "\\n"; } } os.close(); } int C酒店客房预订系统Dlg::cus_day(int j) { date t; int i,dis1=0,dis2=0; int mon[14] = { 0, 31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30 }; for (i = 1; i < r[n].cus[j].book_time.get_month(); i++) { if (i == 2) dis1++; dis1 += mon[i]; } dis1 += r[n].cus[j].book_time.get_day(); for (i = r[n].cus[j].book_time.get_year(); i < t.get_year(); i++) { if (i % 400 == 0 && (i % 4 == 0 && i % 100 != 0)) dis2 += 366; else dis2 += 365; } for (i = 1; i < t.get_month(); i++) { if (i == 2) dis1++; dis1 += mon[i]; } dis2 += t.get_day(); return dis2 - dis1 + 1; } void C酒店客房预订系统Dlg::OnBnClicked订房() { // TODO: 在此添加控件通知处理程序代码 information login; if (login.DoModal() == IDOK) { int j = r[n].flag; r[n].flag ++; ifstream is("new_customer_information.txt"); ofstream os("预定情况.txt",ios::app); date t; r[n].cus[j].book_time = t; os << t.get_year() << "-" << t.get_month()<< "-" << t.get_day() << " "; os << r[n].num << "\\n"; is >> r[n].cus[j].name >> r[n].cus[j].ID; int y, m, d,y1,m1,d1; is >> y >> m >> d>> y1 >> m1>> d1; r[n].cus[j].book_time.set_day(d); r[n].cus[j].book_time.set_mon(m); r[n].cus[j].book_time.set_year(y); r[n].cus[j].end_time.set_day(d1); r[n].cus[j].end_time.set_mon(m1); r[n].cus[j].end_time.set_year(y1); is.close(); os.close(); MessageBox(TEXT("订房成功!"), TEXT("信息"), MB_OK); C酒店客房预订系统Dlg::update_room(); C酒店客房预订系统Dlg::OnBnClicked查询(); } } void C酒店客房预订系统Dlg::OnBnClicked退房() { // TODO: 在此添加控件通知处理程序代码 CString str; m_cdatectr.GetTime(m_date); int year = m_date.GetYear(), month = m_date.GetMonth(), day = m_date.GetDay(); int j; if (r[n].flag == 0) MessageBox(TEXT("客房无人入住,不能退房"), TEXT("信息"), MB_OK); else{ for (j = 0; j < r[n].flag; j++) { if (r[n].cus[j].book_time.get_year() <= year&&r[n].cus[j].end_time.get_year() >= year) { if (r[n].cus[j].book_time.get_month() <= month&&r[n].cus[j].end_time.get_month() >= month) { if (r[n].cus[j].book_time.get_day() <= day&&r[n].cus[j].end_time.get_day() >= day) break; } } } if(j==r[n].flag) MessageBox(TEXT("客房无人入住,不能退房"), TEXT("信息"), MB_OK); str = "房间住客:"; str += r[n].cus[j].name.c_str(); str += "\\n"; str += "是否为其退房?"; if (MessageBox(str, TEXT("信息"), MB_OKCANCEL) == IDOK) { r[n].flag = 0; int fee = cus_day(j)*r[n].prize; if (fee < 0) fee = 0; str.Format(_T("退房成功\\n扣除费用%d"), fee); MessageBox(str, TEXT("信息"), MB_OK); C酒店客房预订系统Dlg::update_room(); C酒店客房预订系统Dlg::OnBnClicked查询(); } } } void C酒店客房预订系统Dlg::OnBnClicked查询() { // TODO: 在此添加控件通知处理程序代码 m_listbox.ResetContent(); m_cdatectr.GetTime(m_date); int year = m_date.GetYear(),month = m_date.GetMonth(),day = m_date.GetDay(); for (int i = 0; i < m; i++) { string strroominfor; string s; char ch[100]; int j = 0; sprintf(ch, "%d", r[i].num); s = ch; strroominfor = s; strroominfor += " "; strroominfor += r[i].kind; strroominfor += " "; sprintf(ch, "%d", r[i].prize); s = ch; strroominfor += s; strroominfor += " "; for (j = 0; j < r[i].flag; j++) { if (r[i].cus[j].book_time.get_year() <= year&&r[i].cus[j].end_time.get_year() >= year) { if (r[i].cus[j].book_time.get_month() <= month&&r[i].cus[j].end_time.get_month() >= month) { if (r[i].cus[j].book_time.get_day() <= day&&r[i].cus[j].end_time.get_day() >= day) break; } } } if (j==r[i].flag) strroominfor += " 空 "; else strroominfor += "已预定"; strroominfor += '\\0'; CString str; str = strroominfor.c_str(); LPCTSTR lp; lp = (LPCTSTR)str; m_listbox.AddString(lp); } } void C酒店客房预订系统Dlg::OnBnClicked管理员() { // TODO: 在此添加控件通知处理程序代码 DlgManager dmg; dmg.DoModal(); } void C酒店客房预订系统Dlg::OnLbnSelchangeList1() { // TODO: 在此添加控件通知处理程序代码 n = m_listbox.GetCurSel(); // 获取当前选中列表项 GetDlgItem(IDC_BUTTON1)->EnableWindow(1); } //信息输入头文件 #pragma once #include "afxwin.h" #include #include "afxdtctl.h" using namespace std; // information 对话框 class information : public CDialog { DECLARE_DYNAMIC(information) public: information(CWnd* pParent = NULL); // 标准构造函数 virtual ~information(); // 对话框数据 enum { IDD = IDD_LOGIN }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() public: afx_msg void OnBnClickedOk(); private: CEdit c_name; CEdit c_ID; CDateTimeCtrl m_cdt; public: CDateTimeCtrl m1_cdt; }; //输入信息源文件 #include "stdafx.h" #include "酒店客房预订系统.h" #include "information.h" #include "afxdialogex.h" // information 对话框 IMPLEMENT_DYNAMIC(information, CDialog) information::information(CWnd* pParent /*=NULL*/) : CDialog(information::IDD, pParent) { } information::~information() { } void information::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_EDIT1, c_name); DDX_Control(pDX, IDC_EDIT2, c_ID); DDX_Control(pDX, IDC_DATETIMEPICKER1, m_cdt); DDX_Control(pDX, IDC_DATETIMEPICKER2, m1_cdt); } BEGIN_MESSAGE_MAP(information, CDialog) ON_BN_CLICKED(IDOK, &information::OnBnClickedOk) END_MESSAGE_MAP() // information 消息处理程序 void information::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 CTime m_date; m_cdt.GetTime(m_date); int year = m_date.GetYear(),month = m_date.GetMonth(), day = m_date.GetDay(); CString str,str1; GetDlgItem(IDC_EDIT1)->GetWindowText(str); GetDlgItem(IDC_EDIT2)->GetWindowText(str1); if (c_name.LineLength() == 0 || c_ID.LineLength() == 0) MessageBox(TEXT("信息不能为空!"), TEXT("信息"), MB_OK); else if (c_ID.LineLength() != 18) MessageBox(TEXT("身份证号码错误!"), TEXT("信息"), MB_OK); else{ ofstream of("new_customer_information.txt"); CStringA stra(str),stra2(str1); of << stra << " " << stra2<<" "< year = m_date.GetYear(), month = m_date.GetMonth(), day = m_date.GetDay(); of << " " << year << " " << month << " " << day; of.close(); CDialog::OnOK(); } } // DlgManager.h #pragma once #include "afxwin.h" #include #include"ROOM.h" using namespace std; class DlgManager : public CDialog { DECLARE_DYNAMIC(DlgManager) public: DlgManager(CWnd* pParent = NULL); // 标准构造函数 virtual ~DlgManager(); // 对话框数据 enum { IDD = IDD_MANAGER }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() public: afx_msg void OnLbnSelchangeList1(); private: CListBox manager_listbox; room r[1000]; int n,m; public: afx_msg void OnBnClicked添加(); afx_msg void OnBnClicked删除(); afx_msg void OnBnClicked修改信息(); afx_msg void OnBnClicked显示(); afx_msg void OnBnClicked统计(); void update_room(); bool error(); private: CEdit manager_rnum; CEdit manage_rkind; CEdit manager_rprize; }; // DlgManager.cpp : 实现文件 #include "stdafx.h" #include "酒店客房预订系统.h" #include "DlgManager.h" #include "afxdialogex.h" // DlgManager 对话框 IMPLEMENT_DYNAMIC(DlgManager, CDialog) DlgManager::DlgManager(CWnd* pParent /*=NULL*/) : CDialog(DlgManager::IDD, pParent) { ifstream is("room.txt"); is >> m; for (int i = 0; i < m; i++) { char b; is >> r[i].num; is >> r[i].kind; is >> r[i].prize >> r[i].flag; for (int j = 0; j < r[i].flag; j++){ is >> r[i].cus[j].name >> r[i].cus[j].ID; int y, m, d; is >> y >> b >> m >> b >> d; r[i].cus[j].book_time.set_day(d); r[i].cus[j].book_time.set_mon(m); r[i].cus[j].book_time.set_year(y); is >> y >> b >> m >> b >> d; r[i].cus[j].end_time.set_day(d); r[i].cus[j].end_time.set_mon(m); r[i].cus[j].end_time.set_year(y); } } } DlgManager::~DlgManager() { } void DlgManager::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST1, manager_listbox); DDX_Control(pDX, IDC_EDIT1, manager_rnum); DDX_Control(pDX, IDC_EDIT2, manage_rkind); DDX_Control(pDX, IDC_EDIT3, manager_rprize); } BEGIN_MESSAGE_MAP(DlgManager, CDialog) ON_LBN_SELCHANGE(IDC_LIST1, &DlgManager::OnLbnSelchangeList1) ON_BN_CLICKED(IDC_BUTTON1, &DlgManager::OnBnClicked添加) ON_BN_CLICKED(IDC_BUTTON2, &DlgManager::OnBnClicked删除) ON_BN_CLICKED(IDC_BUTTON3, &DlgManager::OnBnClicked修改信息) ON_BN_CLICKED(IDC_BUTTON4, &DlgManager::OnBnClicked显示) ON_BN_CLICKED(IDC_BUTTON5, &DlgManager::OnBnClicked统计) END_MESSAGE_MAP() // DlgManager 消息处理程序 void DlgManager::update_room() { ofstream os("room.txt"); os << m << "\\n"; for (int i = 0; i < m; i++) { os << r[i].num << " "; os << r[i].kind << " "; os << r[i].prize << " " << r[i].flag << "\\n"; for (int j = 0; j < r[i].flag; j++) { os << " " << r[i].cus[j].name << " " << r[i].cus[j].ID; os << " " << r[i].cus[j].book_time.get_year() << "-"; os << r[i].cus[j].book_time.get_month() << "-" << r[i].cus[j].book_time.get_day(); os << " " << r[i].cus[j].end_time.get_year() << "-"; os << r[i].cus[j].end_time.get_month() << "-" << r[i].cus[j].end_time.get_day(); os << "\\n"; } } os.close(); } bool DlgManager::error() { if (manager_rnum.LineLength() == 0 || manage_rkind.LineLength() == 0 || manager_rprize.LineLength() == 0) { MessageBox(TEXT("信息不能为空!"), TEXT("信息"), MB_OK); return 0; } return 1; } void DlgManager::OnLbnSelchangeList1() { // TODO: 在此添加控件通知处理程序代码 n= manager_listbox.GetCurSel(); // 获取当前选中列表项 char buf[20]; sprintf(buf, "%d", r[n].num); string s = buf; CString str; str = s.c_str(); LPCTSTR lp; lp = (LPCTSTR)str; SetDlgItemText(IDC_EDIT1, lp); // 将选中列表项的字符串显示到编辑框中 str = r[n].kind.c_str(); lp = (LPCTSTR)str; SetDlgItemText(IDC_EDIT2, lp); sprintf(buf, "%d", r[n].prize); s = buf; str = s.c_str(); lp = (LPCTSTR)str; SetDlgItemText(IDC_EDIT3, lp); } void DlgManager::OnBnClicked添加() { // TODO: 在此添加控件通知处理程序代码 CString str, str1,str2; GetDlgItem(IDC_EDIT1)->GetWindowText(str); GetDlgItem(IDC_EDIT2)->GetWindowText(str1); GetDlgItem(IDC_EDIT3)->GetWindowText(str2); if (error()) { r[m].flag = 0; CStringA stra1(str1); r[m].num = _ttoi(str); r[m].kind = stra1; r[m].prize = _ttoi(str2); m++; DlgManager::update_room(); DlgManager::OnBnClicked显示(); } } void DlgManager::OnBnClicked删除() { // TODO: 在此添加控件通知处理程序代码 if (r[n].flag) MessageBox(TEXT("该房间已经预定出去无法删除"), TEXT("信息"), MB_OK); else { for (int i = n + 1; i < m; i++) { r[i - 1].num = r[i].num; r[i - 1].prize = r[i].prize; r[i - 1].flag = r[i].flag; r[i - 1].kind = r[i].kind; for (int j = 0; j < r[i].flag;j++) r[i - 1].cus[j] = r[i].cus[j]; } m--; DlgManager::update_room(); DlgManager::OnBnClicked显示(); } } void DlgManager::OnBnClicked修改信息() { // TODO: 在此添加控件通知处理程序代码 CString str, str1, str2; GetDlgItem(IDC_EDIT1)->GetWindowText(str); GetDlgItem(IDC_EDIT2)->GetWindowText(str1); GetDlgItem(IDC_EDIT3)->GetWindowText(str2); if (error()) { CStringA stra1(str1); r[n].num = _ttoi(str); r[n].kind = stra1; r[n].prize = _ttoi(str2); DlgManager::update_room(); DlgManager::OnBnClicked显示(); } } void DlgManager::OnBnClicked显示() { // TODO: 在此添加控件通知处理程序代码 manager_listbox.ResetContent(); for (int i = 0; i < m; i++) { string strroominfor,s; char ch[100]; sprintf(ch, "%d", r[i].num); s = ch; strroominfor = s; strroominfor += " "; strroominfor += r[i].kind; strroominfor += " "; sprintf(ch, "%d", r[i].prize); s = ch; strroominfor += s; strroominfor += '\\0'; CString str; str = strroominfor.c_str(); LPCTSTR lp; lp = (LPCTSTR)str; manager_listbox.AddString(lp); } } void DlgManager::OnBnClicked统计() { // TODO: 在此添加控件通知处理程序代码 manager_listbox.ResetContent(); ifstream is("预定情况.txt"); string s, s1,str; char buf[100]; int m = 0; is >>buf; s = buf; is >> buf; s1 = s; m++; while (!is.eof()){ if (s1 != s){ sprintf(buf, "%d", m-1); str = s1; str += " 被预定"; str += buf; str += "次"; CString cstr; cstr = str.c_str(); LPCTSTR lp; lp = (LPCTSTR)cstr; manager_listbox.AddString(lp); m = 1; s1 = s; } else { m++; s1 = s; } is >> buf; s = buf; is >> buf; } str = s1; sprintf(buf, "%d", m); str += " 被预定"; str += buf; str += "次"; CString cstr; cstr = str.c_str(); LPCTSTR lp; lp = (LPCTSTR)cstr; manager_listbox.AddString(lp); } 6、运行结果与分析 主界面: 订房信息输入界面: 退房成功: 房间信息管理界面: 统计预定情况: 分析:能基本实现订房及退房的功能,房间信息的管理能够基本实现。 7、心得与体会 1.在程序设计过程中,了解与实现了酒店客房预定系统,熟练应用文件操作及相关函数,学习了MFC图形界面的设计及编程,提高了自身的编程能力以及相关的图形界面设计能力。酒店系统的设计是小的软件项目,麻雀虽小,五脏俱全,在其过程中,对程序的编写规范和程序调试亦是一种能力的锻炼。 2.体会到程序调试能力的重要:在程序编写后往往不能一次性通过,而开发软件所报出的错误更是云里雾里,不知到错在哪里,学会调试能较为便捷的找到错误原因。能够调试是软件编写成功的一大助力。 3.学会查找资料:没有人会所有的知识,在遇到错误及不会的技术,像MFC老师上课没有讲解的内容更加需要自学,要学会通过互联网或图书馆书籍进行查找,这对程序员乃至各行各业都是一种必备的技能。 4.对面向对象课程设计的认识 程序的基础是语言,代码是它的集中体现,学习一种编程语言能学习和领悟到一种思想,因为每一种语言都包含了自身的语法结构例如简单的数组表达、数据结构等语法表达。因此面向对象课程是计算机专业的必修课程,学好这门课对接下来的操作系统、数据库管理与应用、软件工程等课程有好处。程序具有它的思想,能够通过编程语言让其体现出来,是一个合格程序员的必备技能。在面向对象课程中,我学到了许多,收获了很多,相信这对我以后有更好的帮助。 考核成绩评定表平时成绩 答辩成绩 总成绩