| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 527 人关注过本帖
标题:这个怎么运行不了,求专家解答
只看楼主 加入收藏
花儿与骚年
Rank: 1
来 自:包头
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-6-24
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
这个怎么运行不了,求专家解答
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include<string.h>
#include <fstream>
#include <ctime>
using namespace std;
const int N=10;
bool A=false,B=true;
long t = time(0);
tm * pt = localtime(&t);
void mainmenu();
struct Time
{
    int hour;
    int minute;                     
};

class user
{    friend void save ();
    friend void sure_message();
    friend void browse();
    friend void ticketmenu();
    friend void search_train();
    friend void search_station();
protected:
    char train[10];
    Time time;
    char start_station[20];
    char end_station[20];
    int ticket_price;
    int remaind_seats;
public:
   
    void display()
    {
        cout<<train<<"\t"<<" "<<setfill('0')<<setw(2)<<time.hour<<":"
            <<setw(2)<<time.minute<<"\t\t"<<" "<<start_station<<"\t"
            <<" "<<end_station<<"\t"<<" "<<ticket_price<<"\t"
            <<"  "<<remaind_seats<<"\t";
        
        t = ::time(NULL);
        tm * pt = localtime(&t);
        if(time.hour<pt->tm_hour)
            cout<<"  此班列车已发出";
        else if(time.hour==pt->tm_hour&&time.minute<=pt->tm_min)
            cout<<"  此班列车已发出";
        else cout<<"\t正常";
        cout<<endl;
    }
    void order()
    {
        if(time.hour<pt->tm_hour)
            cout<<"  此班列车已发出,不能订票,退出!";
        else if(time.hour==pt->tm_hour&&time.minute<=pt->tm_min)
            cout<<"  此班列车已发出,不能订票,退出!";
        else if (  remaind_seats == 0        )
            cout << "此班列车已没票,不能订票,退出!" << endl;
        else

        {
            remaind_seats = remaind_seats - 1;
            cout <<train<<"次列车  "<< "售票一次,现存票量为:" << remaind_seats << endl;
        }
    }
    void Delete()
    {
        if(time.hour<pt->tm_hour)
            cout<<"  此班列车已发出,不能退票,退出!";
        else if(time.hour==pt->tm_hour&&time.minute<=pt->tm_min)
            cout<<"  此班列车已发出,不能退票,退出!";
        else {
            remaind_seats = remaind_seats + 1;
            cout <<train<<"次列车  "<< "退票一次,现存票量为:" << remaind_seats << endl;
        }
    }
} ;
class service :public user
{
    friend void input();
   
public:
    void setinfo (char* c, int h, int m, char* q, char* z, int p, int s)
    {
        strcpy(train,c);
        time.hour=h;
        time.minute=m;
        strcpy(start_station,q);
        strcpy(end_station,z);
        ticket_price=p;
        remaind_seats=s;
    }
   
};
service ticket[N];
static int g_num=-1;

void save ()
{
    ofstream file("数据.txt",ios::out);

    for(int j=0;j<=g_num;j++)
    {
        file<<ticket[j].train<<" ";
        file<<ticket[j].time.hour <<" ";
        file<<ticket[j].time.minute<<" ";
        file<<ticket[j].start_station <<" ";
        file<<ticket[j].end_station <<" ";
        file<<ticket[j].ticket_price<<" ";
        file<<ticket[j].remaind_seats <<endl;
    }
    file.close();
    cout<<"信息已存入文件"<<endl;
}

void input()
{
    g_num++;
    char c[10];
    int h;
    int m;
    char q[20];
    char z[20];
    int p;
    int s;
   
   
    cout<<"车次:";cin>>c;

    cout<<"开车时间hour:";cin>>h;

    cout<<"开车时间minute:";cin>>m;
   
    cout<<"起始:";cin>>q;
   
    cout<<"终点:";cin>>z;
   
    cout<<"票价:";cin>>p;
   
    cout<<"剩余座位:";cin>>s;
   
    ticket[g_num].setinfo (c, h, m,  q,  z,  p,  s);
    save ();
   
}
void browse()
{
    int j;
    t = time(NULL);
    tm * pt = localtime(&t);
    cout<<"当前时间:"<<setfill('0')<<setw(2)<<pt->tm_hour<<':';
    cout<<setw(2)<<pt->tm_min<<':';cout<<setw(2)<<pt->tm_sec<<endl<<endl;
    cout<<"现存车次信息如下:"<<endl<<endl;
    cout<<"车次\t"<<"开车时间\t"<<"起始\t"<<"终点\t"<<"票价\t"<<"剩余座位\t"<<"状态\t"<<endl;
    for( j=0;j<=g_num;j++)
        ticket[j].display();
}
void search_train()
{
    char train[10];
    cout<<"输入你要查询的车次:";
    cin>>train;
    cout<<endl<<endl;
    for(int j=0;j<=g_num;j++)
        if(strcmp(train,ticket[j].train)==0)
        {
            cout<<"查询结果:"<<endl;
            cout<<"车次\t"<<"开车时间\t"<<"起始\t"<<"终点\t"<<"票价\t"
                <<"剩余座位\t"<<"状态\t"<<endl;
            ticket[j].display();break;
        }
        if(j>g_num)
            cout<<"对不起,没有这趟车次信息!";
        
}
void search_station()
{
    char station[20];
    cout<<"输入你要查询的站点:";
    cin>>station;
    cout<<endl<<endl;
    for(int j=0;j<=g_num;j++)
        if((strcmp(station,ticket[j].start_station)==0)||(strcmp(station,ticket[j].end_station)==0))
        {
            cout<<"查询结果:"<<endl;
            cout<<"车次\t"<<"开车时间\t"<<"起始\t"<<"终点\t"<<"票价\t"<<"剩余座位\t"<<"状态\t"<<endl;
            
            ticket[j].display();break;
        }
        if(j>g_num)
            cout<<"对不起,没有有关此站点的车次信息!";
}
void ticketmenu()
{
    long t = time(0);
    tm * pt = localtime(&t);
    int functionNumber;int j;
    cout<<"                      >>>>>> 票务菜单 <<<<<<                        \n";
    char train[10];char station[20];
    cout<<"可按站点或车次查询订票(1.按站点,2.按车次)"<<endl;
    cout<<"选择你需要的功能:";
    cin>>functionNumber;getchar();
    for(;functionNumber!=1&&functionNumber!=2;)
    {
        cout<<"指令错误!请重新输入!"<<endl;
        cin>>functionNumber;
    }
    cout<<endl<<endl;
    if (functionNumber==1)
    {
        cout<<"输入你要订票或退票的站点:";
        cin>>station;
        cout<<endl<<endl;
        for( j=0;j<=g_num;j++)
            if((strcmp(station,ticket[j].start_station)==0)||(strcmp(station,ticket[j].end_station)==0))
            {
                cout<<"本车次现存信息:"<<endl;
                cout<<"车次\t"<<"开车时间\t"<<"起始\t"<<"终点\t"<<"票价\t"<<"剩余座位\t"
                    <<"状态\t"<<endl;
                ticket[j].display();break;
            }
            if(j>g_num)
                cout<<"对不起,没有这趟车次信息!,无法订退票!";
    }
    if (functionNumber==2)
    {
        cout<<"输入你要订票或退票的车次:";
        cin>>train;
        cout<<endl<<endl;
        for( j=0;j<=g_num;j++)
            if(strcmp(train,ticket[j].train)==0)
            {
                cout<<"本车次现存信息:"<<endl;
                cout<<"车次\t"<<"开车时间\t"<<"起始\t"<<"终点\t"<<"票价\t"<<"剩余座位\t"
                    <<"状态\t"<<endl;
                ticket[j].display();break;
            }
            if(j>g_num)
                cout<<"对不起,没有有关此站点的车次信息!无法订退票!";
    }
    if(ticket[j].time.hour<pt->tm_hour)
        cout<<"此班列车已发出,不能订退票!";
    else if(ticket[j].time.hour==pt->tm_hour&&ticket[j].time.minute<=pt->tm_min)
            cout<<"此班列车已发出,不能订退票!";
    else
    {
        cout<<"\n";
        cout<<"                           1.订票                                   \n";
        cout<<"                           2.退票                                   \n";
        cout<<"                           3.返回主菜单                             \n";
        cout<<"\n";
        cout<<"选择你需要的功能:";
        cin>>functionNumber;
        for(;functionNumber!=1&&functionNumber!=2&&functionNumber!=3;)
        {
            cout<<"指令错误!请重新输入!"<<endl;
            cin>>functionNumber;
        }
        cout<<endl<<endl;
        switch(functionNumber)
        {
        case 1:ticket[j].order();save ();break;
            
        case 2:ticket[j].Delete();save ();break;
            
        case 3:mainmenu();break;
            
        }//switch ends
    }
}
void search_menu()
{
    int functionNumber;
    cout<<"                      >>>>>> 查询子菜单 <<<<<<                      \n";
    cout<<endl;
    cout<<"                           1.按班次查询                             \n";
    cout<<"                           2.按站点查询                             \n";
    cout<<"                           3.返回主菜单                             \n";
    cout<<endl;
    cout<<"请选择你所需要的功能:";
    cin>>functionNumber;
    cout<<endl<<endl;
    for(;functionNumber!=1&&functionNumber!=2&&functionNumber!=3;)
    {
        cout<<"指令错误!请重新输入!"<<endl;
        cin>>functionNumber;
        cout<<endl<<endl;
    }
    switch(functionNumber)
    {
    case 1:search_train();break;
    case 2:search_station();break;
    case 3:system("cls");
        mainmenu();
        
    }
}
void mainmenu()
{
    int functionNumber;
    cout<<"                   >>>>>> 欢迎使用车票管理系统 <<<<<<                 \n";
    cout<<endl;
    cout<<"                           1.录入班次信息                           \n";
    cout<<"                           2.浏览班次信息                           \n";
    cout<<"                           3.查询行车路线                           \n";
    cout<<"                           4.售票与退票系统                         \n";
    cout<<"                           5.退出系统                               \n";
    cout<<endl;
    cout<<"请选择你所需要的功能:";
    cin>>functionNumber;
    cout<<endl<<endl;
    switch(functionNumber)
    {
    case 1:
        { char  c;
        if (A)
        {
        do
        {
            input();
            cout<<"已录入"<<g_num+1<<"条航班信息(包括已从文件中读取的),想继续录入吗(y/n)"<<endl;
            cin>>c;
            for(;c!='y'&&c!='n';)
            {
                cout<<"指令错误!请重新输入!"<<endl;
                cin>>c;
            }
        } while (c=='y');
        }
        else  cout<<"对不起,您不是管理员不能进行这项操作!";
        cout<<endl<<"按任意键回主菜单......"<<endl;
        getchar();getchar();
        system("cls");
        }
        break;
    case 2:
        {
            browse();
            cout<<endl<<endl<<endl<<"按任意键回主菜单......"<<endl;
            getchar();getchar();
            system("cls");
        }
        break;
    case 3:
        {
            search_menu();
            cout<<endl<<"按任意键回主菜单......"<<endl;
            getchar();getchar();
            system("cls");
        }
        break;
    case 4:
        {
            ticketmenu();
            cout<<endl<<"按任意键回主菜单......"<<endl;
            getchar();getchar();
            system("cls");
        }
        break;
    case 5:
        {
        t = time(NULL);
        tm* pt = localtime(&t);
        system("cls");cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
        cout<<"                       >>>>>> 谢谢使用车票管理系统 <<<<<<         \n";
        B=false;
        }
        break;
   
   
    default:
        {
            cout<<"输入错误,请确保你的输入为1--5"<<endl;
            cout<<"按任意键回主菜单......"<<endl;
            getchar();
            system("cls");
        }
    }//switch ends
}
void sure_message()
{
    cout<<"                   >>>>>> 欢迎使用车票管理系统 <<<<<<                 \n"
        <<endl<<endl;
    ifstream file ( "数据.txt" ,ios::in) ;
    if  ( !file )   
    {
        if (A)
        {
            cout << "从没录入过信息,请您先录入信息" <<endl;
        input();
        cout<<endl<<"按任意键回主菜单......"<<endl;
        getchar();
        system("cls");
        mainmenu();
        }
        else  cout<<"对不起,系统还没录入过任何信息,请提示管理员录入信息!";
    }
    else{
        cout<<"本次运行尚未录入信息,默认读取已存信息\n";
        cout<<"按任意键读取......\n";
        getchar();getchar();
        while( !file.eof())
        {
            g_num++;
            file>>ticket[g_num].train;
            file>>ticket[g_num].time.hour ;
            file>>ticket[g_num].time.minute;
            file>>ticket[g_num].start_station;
            file>>ticket[g_num].end_station;
            file>>ticket[g_num].ticket_price;
            file>>ticket[g_num].remaind_seats;
        }
        g_num--;
        file .close();
        
        cout<<"读取完毕!"<<endl;
        
    }
}
void main()
{
    int  functionNumber,code;
    cout<<"请输入您的身份(1.管理员,2.乘客)"<<endl;
    cout<<"您的身份:";
    cin>>functionNumber;
    for(;functionNumber!=1&&functionNumber!=2;)
    {
        cout<<"指令错误!请重新输入!"<<endl;
        cin>>functionNumber;
    }
    if (functionNumber==1)
    {
        cout<<"请输入密码:";
        cin>>code;
        for(;code!=112233;)
        {
            cout<<"指令错误!请重新输入!"<<endl;
            cin>>code;
        }
         A=true;
    }
    sure_message();
    do mainmenu();
    while(B);
}
搜索更多相关主题的帖子: 专家解答 include friend minute false 
2014-06-24 11:34
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:20 
能弄出这么长的代码   自己不会调试吗

DO IT YOURSELF !
2014-06-24 15:03
快速回复:这个怎么运行不了,求专家解答
数据加载中...
 
   



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

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