首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

小弟我的第一个小项目,上次时一个朋友给的题,做虽然做出来了,可是不知道质量如何样,小弟我贴了源码,欢迎来批评

2012-02-29 
我的第一个小项目,上次求助时一个朋友给的题,做虽然做出来了,可是不知道质量怎么样,我贴了源码,欢迎来批评

我的第一个小项目,上次求助时一个朋友给的题,做虽然做出来了,可是不知道质量怎么样,我贴了源码,欢迎来批评
上次学习动力不足的时候一个朋友给的题。下面是原话,我现在想知道这类的题哪里还有,知道的告诉我一下,不要太难,最好逐步加深的


既然LZ这么欠练,那我给你个题目,你去做一下酒店预订系统
酒店信息放在,hotel.dat文件里
预订信息放在,booling.dat文件里

酒店的信息有:
酒店代号(自动编号)
名称
所在城市
标房数
空标房数
标房价格
豪华房
豪华房数
豪华房价格

预订信息有:
订单编号(自动编号)
酒店代号
预订房型
订者姓名
联系电话
email地址

菜单功能:
1.增加酒店
2.增加订单
3.取消订单
4.查看某城市所有酒店信息

C/C++ code
#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.


这里用的都是最简单的东西,第一次做这东西一点经验也没有,希望大家指出不足

[解决办法]
对C++语法有个大致了解了.对编译和链接也有概念了,可以考虑选择一个开发工具,比如VC6或者VS2005.把这个酒店管理系统做成WINFORM的应用程序.数据也存放在一个DBMS中(比如:MS ACCESS).实现增,删,改,查的功能.还可以考虑加上一个报表系统.整个过程走下来.能够学到不少东西的.
[解决办法]
赞。另外最好把文件打包上传,方便别人下载了阅读。
[解决办法]
C/C++ code

//BookingSystem.cpp#include "BookRecordContainer.h"#include "HotelContainer.h"#include <iostream>#include <conio.h>using namespace std;/////////////////////////////预订与取消/////////////////////////////int bookhotel(HotelContainer& h, BookRecordContainer& b,                 int hotelcode, const char* name, int telnumber, const char* email, char type) {    //成功返回1,失败返回0    int t = h.book(hotelcode, toupper(type));        if (t > 0) {        b.book(hotelcode, name, telnumber, email, toupper(type));        return 1;    }    else {        cout << "\n\tNo match Hotel or Hotel is running out of rooms" << endl;        return 0;    }}int cancelhotel(HotelContainer& h, BookRecordContainer& b, int bookcode) {    //成功返回1,失败返回0    char type = b.gettype(bookcode);    int hotelcode = b.cancel(bookcode);    if (hotelcode > 0) {        h.cancel(hotelcode, type);        return 1;    }    else {        cout << "No match booking record" << endl;        return 0;    }}///////////////////////////////////////////////////////////////////////////////////////////////////主菜单///////////////////////////////////char mainmenu() {    cout << "\t################################\n"          << "\t#     HOTEL BOOKING SYSTEM     #\n"         << "\t##########--********--##########\n\n"         << "\t1.Add new Hotel details\n"         << "\t2.Record Booking details\n"         << "\t3.Record Cancellation details\n"         << "\t4.View details of Hotels in a city\n"         << "\t5.Exit" << endl << endl;    cout << "\tEnter choice: ";    char choice;    do {        choice = getch();        choice = toupper(choice);    } while( choice != '1' && choice != '2' &&             choice != '3' && choice != '4' && choice != '5');    putch( choice );    putch( '\r' );    /* Carriage return */    putch( '\n' );    /* Line feed       */    return choice;}/////////////////////////增加酒店菜单////////////////////////////char addhotel(HotelContainer& h) {    char name[30];    char city[30];    char rr[10];    char pr[10];    char dr[10];    char pd[10];        cout << "\tADD NEW HOTEL DETAILS\n\n";    cout << "\tHotel code: " << h.getmaxcode() + 1 << endl << endl;    cout << "\tEnter Hotel name: ";    cin.getline(name, 30);    fflush(stdin);       cin.clear();    cout << "\n\tEnter City name: ";    cin.getline(city, 30);    fflush(stdin);       cin.clear();    cout << "\n\tEnter the number of Regular rooms: ";    cin.getline(rr, 10);    fflush(stdin);       cin.clear();    cout << "\n\tEnter the tarrif for Regular rooms: ";    cin.getline(pr, 10);    fflush(stdin);       cin.clear();    cout << "\n\tEnter the number of Deluxe rooms: ";    cin.getline(dr, 10);    fflush(stdin);       cin.clear();    cout << "\n\tEnter the tarrif for Deluxe rooms: ";    cin.getline(pd, 10);    fflush(stdin);       cin.clear();    h.add(name, city, atoi(rr), atof(pr), atoi(dr), atof(pd));        cout << "\n\t\tContinue(Y/N): ";    char choice;    do {        choice = getch();        choice = toupper(choice);    } while( choice != 'Y' && choice != 'N');    putch( choice );    putch( '\r' );    /* Carriage return */    putch( '\n' );    /* Line feed       */    return choice;}//////////////////////增加预订菜单//////////////////////////////char addbook(HotelContainer& h, BookRecordContainer& b) {    char hotelcode[10];    char name[30];    char email[30];    char type;    char telnumber[10];    cout << "\tADD NEW BOOKING DETAILS\n\n"         << "\tBooking number: " << b.getmaxcode() + 1 << endl << endl;    cout << "\tEnter Hotel code: ";    cin.getline(hotelcode, 10);    fflush(stdin);       cin.clear();    cout << "\n\tEnter required room type(\'R\' for regular, \'D\' for Deluxe): ";    do {        type = getch();        type = toupper(type);    } while( type != 'R' && type != 'D');    putch( type );    putch( '\r' );    /* Carriage return */    putch( '\n' );    /* Line feed       */    fflush(stdin);       cin.clear();    cout << "\n\tEnter name: ";    cin.getline(name, 30);    fflush(stdin);       cin.clear();    cout << "\n\tEnter contact number: ";    cin.getline(telnumber, 10);    fflush(stdin);       cin.clear();    cout << "\n\tEnter Email ID: ";    cin.getline(email, 30); 


[解决办法]
[code=C/C++]酒店的信息有:
酒店代号(自动编号)
名称
所在城市
标房数
空标房数
标房价格
豪华房
豪华房数
豪华房价格

预订信息有:
订单编号(自动编号)
酒店代号
预订房型
订者姓名
联系电话
email地址

菜单功能:
1.增加酒店
2.增加订单
3.取消订单
4.查看某城市所有酒店信息 [/code]

酒店的信息:
把联系电话电话去掉,加上个人网址

菜单功能:
查看某城市所有酒店信息-> 查看所有城市所有信息
增加房间/去除房间


LZ能不能很轻易的实现以上功能的修改或者扩充?

[解决办法]
>因为程序里没用到,,所以手懒了。。
没用到就明确的把它禁掉。两行代码的事。说不定哪天就不小心用错了。

热点排行