| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 273 人关注过本帖
标题:求C++课程设计解读
只看楼主 加入收藏
忆惜
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-12-27
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
求C++课程设计解读
C++答辩求下面这个程序的解读!!!
#include <string.h>
#include <iostream.h>
#include"fstream.h"
#define M 5//每种飞机票的总数目
#define N 3//飞机票的总数目
class Plane
{private:
    char name[40];//终点站名
    int number;//航班号
    int Number;//飞机号
    int week;//星期几飞行
    int day;//日期
    int left;//余票额
    int n;//与数组flag一起确定客户订票状态
public:   
    int flag[20];//订票状态数组,-1为预订票,1为已定票,0为初始化状态
    Plane()//构造函数
    {
        name[0]='\0';
        number=0;
        Number=0;
        week=0;
        day=0;
        left=M;
        n=0;//数组从0开始计数        
        for(int i=0;i<20;i++)
            flag[i]=0;
    }
void init()//初始化每种飞机票
    {
        cout<<"请输入终点站名:";
        cin>>name;
        cout<<"请输入航班号:";
        cin>>number;
        cout<<"请输入飞机号:";
        cin>>Number;
        cout<<"请输入星期几飞行:";
        cin>>week;
        cout<<"请输入航班的日期:";
        cin>>day;
    }

    ~Plane(){};//析构函数
    char *getname(){return name;}//获得终点站名
    int getnumber(){return number;}//获得航班号
    int getNumber(){return Number;}//获得飞机号
    int getweek(){return week;}//获得星期几飞行
    int getday(){return day;}//获得日期   
    int getleft(){return left;}//获得余票额
    int getn(){return n;}//获得旅客数目
    void inleft(int n){left=left+n;}//余票额增加函数
    void deleft(int n){left=left-n;}//余票额减少函数
    void inn(){n++;}//旅客数目增加函数
};
Plane pl[N];
void init();
int showmenu();//菜单函数
void start();//初始化函数
void query();//查询函数
void make();//订票函数
void back();//退票函数
void writetofile();
int main()
{
    cout<<"这是民航售票处的计算机系统程序"<<endl;
    while(1)
    {
        int choice;
        choice=showmenu();
        switch(choice)
        {
        case 1:start();break;
        case 2:query();break;
        case 3:make();break;
        case 4:back();break;
        case 5:writetofile();break;
        case 0:return 0;
        default:cout<<"你敲错了!\n";
        }
    }
    return 0;
}
int showmenu()
{
    int ch;
    cout<<endl;
    cout<<"请选择你要执行的功能"<<endl;
    cout<<"1:录入数据"<<endl;
    cout<<"2:查询航线"<<endl;
    cout<<"3:承办订票业务"<<endl;
    cout<<"4:承办退票业务"<<endl;
    cout<<"5:将数据写入文件"<<endl;
    cout<<"0:退出程序的运行"<<endl;
    cin>>ch;
    return ch;
}
   
void start()
{
    for(int i=0;i<N;i++)
    {
        pl[i].init();
        cout<<endl;
    }
}
void query()
{
    int i,num=0;
    char name[40];
    cout<<endl;
    cout<<"请输入终点站名:";
    cin>>name;
    for(i=0;i<=N;i++)
        if(strcmp(name,pl[i].getname())==0)
        {
            num++;
            cout<<"航班号:"<<pl[i].getnumber()<<endl;
            cout<<"飞机号:"<<pl[i].getNumber()<<endl;
            cout<<"星期:"<<pl[i].getweek()<<"飞行"<<endl;
            cout<<"航班日期:"<<pl[i].getday()<<endl;
            cout<<"余票额:"<<pl[i].getleft()<<endl;
            break;
        }
        if(num==0)
            cout<<"没有此航班"<<endl;
}
void make()
{
    int number,n,sitnumber,nu,ch,num=0;
    cout<<"请输入航班号:";
    cin>>number;
    cout<<"请输入订票数额:";
    cin>>n;
    for(int i=0;i<N;i++)
        if(number==pl[i].getnumber())
        {
            num++;
            if(n<=pl[i].getleft())
            {
                cout<<"此航班有票"<<endl;
                pl[i].deleft(n);
                pl[i].inn();
                pl[i].flag[pl[i].getn()]=1;
                for(i=0;i<n;i++)
                {
                    cout<<"座位号";
                    cin>>sitnumber;
                }
            }
            else
            {
                cout<<"余票额少于订票额,请重新输入订票数额,"<<"订票数额应该少于或等于"<<pl[i].getleft();
                cin>>nu;
                if(nu<=pl[i].getleft())
                {
                    cout<<"此航班有票"<<endl;
                    pl[i].deleft(nu);
                    pl[i].inn();
                    pl[i].flag[pl[i].getn()]=1;
                    for(i=0;i<N;i++)
                    {
                        cout<<"座位号";
                        cin>>sitnumber;
                    }
                }
                else
                {
                    cout<<"是否需要预约"<<endl;
                    cout<<"是(1)   否(2)"<<endl;
                    cin>>ch;
                    switch(ch)
                    {
                    case 1:pl[i].inn();pl[i].flag[pl[i].getn()]=-1;break;
                    case 2:break;
                    default:cout<<"你敲错了!"<<endl;
                    }
                }
            }
        }
        if(num==0)
            cout<<"没有此航班"<<endl;
}
void back()
{
    int number,day,n,nu,sitnumber,num=0;//航班号,日期,退票数目,订票数目,座位号,标志量
    cout<<"请输入日期:";
    cin>>day;
    cout<<"请输入航班:";
    cin>>number;
    for(int i=0;i<N;i++)
        if((day==pl[i].getday())&&(number==pl[i].getnumber()))//日期与航班是否满足
        {
            num++;//日期与航班满足
            cout<<"输入退票数目";
            cin>>n;
            cout<<"退票成功"<<endl;
            pl[i].inleft(n);//该种飞机票增加,即已退票
            for(int j=0;j<=pl[i].getn();j++)//顺序查询客户订票状态
            {
                if(pl[i].flag[j]==-1)//客户是否为预定状态
                {
                    cout<<"有预约订票,请输入订票数额:";
                    cin>>nu;
                    if(nu<=pl[i].getleft())//余票额是否满足要求
                    {
                        cout<<"此航班有票"<<endl;
                        pl[i].flag[j]=1;
                        cout<<"订票成功"<<endl;
                        pl[i].deleft(nu);
                        for(int k=0;k<nu;k++)
                        {                           
                            cout<<"座位号"<<" ";
                            cin>>sitnumber;
                        }
                        cout<<"余票额为"<<pl[i].getleft()<<endl;
                    }
                }
                else
                    cout<<"没有预约订票!"<<"余票额为"<<pl[i].getleft()<<endl;
            }
        }
        if(num==0)
            cout<<"没有此票"<<endl;
}
void writetofile()
{
    ofstream ofs("123.dat");
    int i;
    for(i=0;i<N;i++)
    {
        ofs<<pl[i].getname()<<endl;
        ofs<<pl[i].getnumber()<<endl;
        ofs<<pl[i].getNumber()<<endl;
        ofs<<pl[i].getweek()<<endl;
        ofs<<pl[i].getday()<<endl;
    }
    ofs.close();
    cout<<"数据已经写入文件123.dat中"<<endl;
}

   
搜索更多相关主题的帖子: private include public 
2013-01-06 21:00
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:10 
解读是神马意思?没明白。写的不错!

同学习......同进步....你帮我......我帮你.....上善若水.....
2013-01-07 08:54
qunxingw
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:24
帖 子:1676
专家分:7295
注 册:2011-6-30
收藏
得分:10 
好长啊,用了一个类,看到了一个对象

www.qunxingw.wang
2013-01-07 11:10
快速回复:求C++课程设计解读
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.043929 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved