c++课程设计

  一交通公司,班车系统的数据包括如下两部分:

①班车信息:班交及车号、最大载客数、起点、开车时间、终地点、到达终点站时间,单价;

② 乘客信息:车次及车号、身份证号码、姓名、性别、出生年月、座位号。

乘客订票的主要方式是:乘客提供起点、时间、终点、订票数等订票要求,根据事先保存的班数据决定乘客能否订票?只有全部满足了乘客的订票要求并且所订班次有足够的未订座位之后才能完成订票处理,并且修改该班次的未订座位数(每个班的未订座位数的初始值就是该班次的最大载客数);否则,订票失败,并且给出不能订票的原因。

功能要求 :

⑴ 增加班次记录。将新的次班记录增加到原有的次班数据中。在进行处理时必须检查所要增加的班次记录是否存在,如果已经存在,应给出提示信息后停止增加;

⑵ 班次取消。如果某班次的乘客数太少(已订票的少于本次班次最大载客数的10%),将取消该班次,但该班欠的记录仍然保存在原有的班数据中;

⑶ 班次查询。应该有以下几种基本的查询方式:按班次号、按起点和时间、按终地点,和时间;

⑷ 班次订票。按上述问题描述中的乘客订票方式完成班次订票处理。

⑸ 设计一个菜单,至少具有上述操作要求的基本功能。

以下为设计的程序

#include<iostream>  
#include<windows.h>  
#include <time.h>   
#include<fstream>  
#include<cstdlib>      
#include <string>  
#include<iomanip>  
using namespace std;  
void menu();              
void add();              
void search();           
void book();            
void cancel();            
int comeon();             
int gethour(char *s);  
int getmin(char *s);    
int i=0,flag=1,f=1;  
char key=0;  

 
struct car  
{  
    char numbers[10];         
    char carnumber[10];      
    char people[5];          
    char start[50];         
    char starttime[30];      
    char finish[50];        
    char finishtime[30];      
    char money[5];           
    char man[3];            
    struct *next;  
};  

  
 
struct passenger  
{     
    char numbers[10];             
    char id[20];                  
    char name[50];              
    char ticket[2];               
    char snum[2];                 
    struct *next;  
};  
  
  
  
 
int main()  
{  
    system("color f9");  
    time_t rawtime;                   
    struct tm * timeinfo;     
    time ( &rawtime );  
    timeinfo = localtime ( &rawtime );  
    cout<<timeinfo->tm_hour<<":"<<timeinfo->tm_min;  
      
    key=0;            
    flag=1;  
    menu();           
    return 0;  
}  
  


 
void menu()  
{     
      
   cout<<"\t\t___________________________________________\n"  
        <<"\t\t|\t\t欢迎进入班车信息管理系统            |\n"  
        <<"\t\t|------------------------------------------\n"  
        <<"\t\t|请根据你的需求输入对应数字\t\t          |\n"  
        <<"\t\t|1.增加班次(注意:本操作限于管理员)\t\t          |\n"  
        <<"\t\t|2、退订车票。    \t\t          |\n"  
        <<"\t\t|3、班次查询。    \t\t          |\n"  
        <<"\t\t|4、班次订票。    \t\t          |\n"   
        <<"\t\t|5、退出系统        \t\t          |\n"  
        <<"\t\t|_________________________________________|\n"  
        <<"\n\t\t*************************************\n\t\t";  
    for(;key>'5'||key<'1';)             
    {     
        fflush(stdin);  
        cin>>key;  
        switch(key)  
        {  
        case '1':  
            add();  
            break;  
        case '2':  
            cancel();  
            break;  
        case '3':  
            search();  
            break;  
        case '4':  
            book();  
            break;  
    
        case '5':  
            system("cls");  
            cout<<"\t\t\t\t*********感谢你的使用*******\n\n"  
                <<"\t\t\t\t*********祝你旅途愉快*******\n\n"  
                <<"\t\t\t\t*******designed by frank********\n\n\n";    
            exit(1);  
            break;  
              
        default:                              
            system("cls");  
            cout<<"对不起,您的输入有误 \n\n\n";  
            Sleep(1000);  
            system("cls");  
            main();  
            break;  
              
        }  
    }     
}  
  

void add()  
{     
    f=1;  
    system("cls");            
    fflush(stdin);            
    char k;  
    while(f)  
    {  
        if(flag == 0)  
        {     
            f=0;  
            system("cls");  
            main();  
        }  
        if(f==0)  
            break;  
        cout<<"\n\n*******************管理员权限**************************\n\n";  
        cout<<"\t\t\t 1、增加车辆班次\n\n"  
            <<"\t\t\t 2、返回主界面\n\n"  
            <<"\t\t\t ";  
        cin>>k;  
        switch(k)  
        {  
        case '1':  
            system("cls");  
            break;  
        case '2':  
            system("cls");  
            main();  
            f = 0;  
            flag = 0;  
            break;  
        default:  
            system("cls");  
            cout<<"你的输入有误\n\n\n";  
            Sleep(1000);  
            system("cls");  
            break;  
        }  
        if(k=='1')  
        {  
            ofstream myfile;  
            myfile.open("car.txt",ios::app);  
            car *head,*p1,*p2;  
            head = NULL;  
            p1 = new(car);  
            p2 = p1;  
              
            cout<<"下面请输入班次相关信息\n"  
                <<"      车次: ";  
            fflush(stdin);        
            cin>>p1 -> numbers;  
              
            cout<<"      车号: ";  
            cin>>p1 -> carnumber;  
              
            cout<<"最大载客数: ";  
            cin>>p1 -> people;  
              
            cout<<"      起点: ";  
            cin>>p1->start;  
              
            cout<<"  出发时间 ";  
            cin>>p1 ->starttime;  
              
            cout<<"      终点: ";  
            cin>>p1 ->finish;  
              
            cout<<"  到达时间 ";  
            cin>>p1->finishtime;  
              
            cout<<"      票价: ";  
            cin>>p1->money;  
              
            myfile<<p1 -> numbers<<" "<<p1 ->carnumber<<" "<<p1 ->people<<' '  
                <<p1 ->start<<" "<<p1 ->starttime<<" "<<p1->finish<<" "  
                <<p1->finishtime<<" "<<p1->money<<" "<<"0 \n";  
            myfile.close();  
            delete head,p1,p2;  
            comeon();  
        }  
    }  
}  


 
void cancel()  
{  
    time_t rawtime;  
    struct tm * timeinfo;     
    time ( &rawtime );  
    timeinfo = localtime ( &rawtime );  
    f=1;  
    char a,tmp[100];  
    while(f)  
    {  
        if(flag == 0)  
        {     
            f=0;  
            system("cls");  
            main();  
        }  
        system("cls");  
        cout<<"\n\n*******************    欢迎进入班次取消,请按照流程进行操作。************\n"   
            <<"\t\t  1、进入操作                *\n"  
            <<"\t\t  2、返回主菜单              *\n"   
            <<"\t\t   ";  
        cin>>a;  
        system("cls");  
        switch(a)  
        {  
        case '1':  
            fflush(stdin);  
            system("cls");    
            cout<<"请输入班次号: ";  
            cin.getline(tmp,50);         
            while(1)  
            {  
                int ff,flag1=0;  
                char *s;  
                string str,st1,st2,st3,st4,st5,st6,st7,st8;  
                str=" ";  
                s =&str[0];  
                ifstream myfile("car.txt");       
                while(!myfile.eof())  
                {     
                    getline(myfile,str,' ');  
                    getline(myfile,st1,' ');  
                    getline(myfile,st2,' ');  
                    getline(myfile,st3,' ');  
                    getline(myfile,st4,' ');  
                    getline(myfile,st5,' ');  
                    getline(myfile,st6,' ');  
                    getline(myfile,st7,' ');  
                    getline(myfile,st8,'\n');  
                    if(strcmp(tmp,s)==0)          
                    {     
                        cout<<"\n  车次 : "<<str<<"\t车号 : "<<st1<<"\t最大载客数 : "<<st2<<" 人"  
                            <<"\n  始发地 : "<<left<<setw(20)<<st3<<"\t出发时间   : "<<st4  
                            <<"\n  目的地 : "<<left<<setw(20)<<st5<<"\t到达时间   : "<<st6  
                            <<"\n  票  价 : "<<st7<<" 元\t\t\t"<<"已订票人数:  "<<st8<<" 人\n";  
                        flag1=1;                  
                    }  
                }  
                myfile.close();                   
                if(flag1)                         
                {  
                    ifstream myfile("car.txt");   
                    string t2,max,num,ttl,t1=" ";  
                    char *p1,*p3;  
                    p1 = &t1[0];  
                    while(!myfile.eof())          
                    {  
                        getline(myfile,t1,' ');       
                        if(strcmp(p1,tmp)==0)         
                        {     
                            flag=1;  
                            for(i=1;i<8;i++)       
                            {  
                                getline(myfile,t1,' ');       
                                if(i==2)              
                                    max=t1;  
                                if(i==4)  
                                    ttl=t1;           
                                p3 = &(ttl[0]);       
                            }  
                            getline(myfile,num,'\n');     
                            break;                        
                        }  
                        getline(myfile,num,'\n');    
                    }  
                    myfile.close();                  
                    if(atof(&num[0])/atof(&max[0])<=0.1)      
                        ff=1;                                    
                    else ff=0;                                  
                      
                    if(gethour(p3)<timeinfo->tm_hour)           
                    {                                             
                        if(ff)            
                        {  
                             
                            cout<<"抱歉,由于班次预定人数较少,将取消该班次,请预定其他班次,谢谢合作~\n";  
                            comeon();  
                            cancel();  
                        }  
                        else  
                        {     
                            cout<<"\n 对不起,你的订票信息已被接受,即将发车,无法退票\n";  
                            comeon();  
                            cancel();  
                        }  
                    }         
                    else if(gethour(p3)<=timeinfo->tm_hour)      
                    {  
                        if(getmin(p3)<=timeinfo->tm_min)  
                        {  
                            if(ff)  
                            {  
                                
                             cout<<"抱歉,由于班次预定人数较少,将取消该班次,请预定其他班次,谢谢合作~\n";
                                comeon();  
                                cancel();  
                            }  
                            else  
                            {  
                                cout<<"\n 对不起,你的订票信息已被接受,即将发车,无法退票\n";  
                                comeon();  
                                cancel();  
                                  
                            }  
                        }  
                    }  
                    else                      
                    {     
                        string name,name1,numbers,num;  
                        ifstream f1("car.txt");  
                        ifstream f2("passenger.txt");  
                        ofstream f3,f4;  
                        f3.open("bak.txt",ios::trunc);  
                        f4.open("bak1.txt",ios::trunc);  
                        cout<<"请输入您的姓名 :";          
                        cin>>name;                         
                        while(!f2.eof())                  
                        {  
                            string str,str1,str2,str3;  
                            str=str1=str2=str3=" ";  
                            int ff=0;                         
                            getline(f2,str,' ');      
                            getline(f2,name1,' ');   
                            getline(f2,str1,' ');     
                            getline(f2,numbers,' ');  
                            getline(f2,str2,'\n');    
                            if(strcmp(&str[0],&tmp[0])==0 && strcmp(&name[0],&name1[0])==0)  
                                num=numbers;      
                            else          
                                f4<<str<<' '<<name1<<' '<<str1<<' '       
                                <<numbers<<' '<<str2<<' '<<'\n';                            
                        }  
                        while(!f1.eof())        
                        {     
                            string s1,s2;  
                            getline(f1,s1,' ');     
                            if(strcmp(&s1[0],&tmp[0])==0)     
                            {     
                                f3<<s1<<' ';                 
                                for(int i=1;i<8;i++)  
                                {  
                                    getline(f1,s2,' ');       
                                    f3<<s2<<' ';  
                                }  
                                getline(f1,s2,'\n');      
                                f3<<atoi(&s2[0])-atoi(&num[0])<<'\n';  
                            }  
                            else             
                            {                         
                                f3<<s1<<' ';     
                                getline(f1,s1,'\n');  
                                f3<<s1<<'\n';  
                            }  
                        }  
                        f1.close();       
                        f2.close();   
                        f3.close();       
                        f4.close();  
                        ofstream ff1("car.txt",ios::trunc);   
                        ofstream ff2("passenger.txt",ios::trunc);  
                        ifstream ff3("bak.txt");  
                        ifstream ff4("bak1.txt");  
                        while(!ff3.eof())     
                        {  
                            string s;  
                            s=" ";  
                            getline(ff3,s,'\0');  
                            ff1<<s;  
                        }  
                        while(!ff4.eof())     
                        {  
                            string s;  
                            s=" ";  
                            getline(ff4,s,'\0');  
                            ff2<<s;  
                        }  
                        ff1.close();          
                        ff2.close();  
                        ff3.close();  
                        ff4.close();  
                        cout<<" 退订成功!!! ";                          
                        comeon();             
                        cancel();  
                    }  
                }  
                  
                else                     
                {  
                    cout<<"\n无该班次信息,请确认是否输入有误 \n\n";  
                    comeon();  
                    cancel();  
                    break;  
                }  
            }  
            break;  
            case '2':  
                {                        
                    system("cls");  
                    main();  
                    break;  
                      
                }  
            default:                         
                system("cls");  
                cout<<"出错了~~\n\n\n";  
                Sleep(1000);  
                system("cls");  
                break;  
        }  
          
          
    }  
}  
  

 
void search()  
{     
    system("cls");               
    f=1;  
    char a,tmp[100],tmp1[30];  
    time_t rawtime;                   
    struct tm * timeinfo;     
    time ( &rawtime );  
    timeinfo = localtime ( &rawtime );  
    while(f)  
    {  
        if(f==0)  
            break;  
        if(flag == 0)  
        {     
            f=0;  
            system("cls");  
            main();  
        }  
          
        cout<<"\n\n **********************欢迎使用班次查询************************ \n\n"   
            <<"\t\t请根据序号进入要查询的内容\n"    
            <<"\t\t1、班次号                  *\n"  
            <<"\t\t2、起点和出发时间          *\n"  
            <<"\t\t3、终点和到达时间          *\n"  
            <<"\t\t4、返回主菜单              *\n"  
            <<"\t\t ******************************************************************\n"  
            <<"\t\t   ";  
        cin>>a;  
        switch(a)  
        {  
        case '1':  
            fflush(stdin);  
            system("cls");    
            cout<<"请输入班次号: ";        
            cin.getline(tmp,50);  
            while(1)  
            {  
                int flag1=0;  
                char *s;  
                string str,st1,st2,st3,st4,st5,st6,st7,st8;  
                str=" ";  
                s =&str[0];  
                ifstream myfile("car.txt");   
                while(!myfile.eof())          
                {     
                    getline(myfile,str,' ');      
                    getline(myfile,st1,' ');      
                    getline(myfile,st2,' ');  
                    getline(myfile,st3,' ');  
                    getline(myfile,st4,' ');  
                    getline(myfile,st5,' ');  
                    getline(myfile,st6,' ');  
                    getline(myfile,st7,' ');  
                    getline(myfile,st8,'\n');  
                    if(strcmp(tmp,s)==0)  
                    {             
                        cout<<"\n  车次 : "<<str<<"\t车号 : "<<st1<<"\t最大载客数 : "<<st2<<" 人"  
                            <<"\n  始发地 : "<<left<<setw(20)<<st3<<"\t出发时间   : "<<st4  
                            <<"\n  目的地 : "<<left<<setw(20)<<st5<<"\t到达时间   : "<<st6  
                            <<"\n  票  价 : "<<st7<<" 元\t\t"<<"已订票人数:  "<<st8<<" 人\n";  
                        flag1=1;      
                    }  
                }  
                cout<<"  当前时间 : "  
                    <<timeinfo->tm_hour<<":"<<timeinfo->tm_min;  
                myfile.close();  
                if(!flag1)           
                    cout<<"\n不存在该班车\n\n";  
                comeon();           
                search();        
                break;  
            }  
        case '2':                     
            fflush(stdin);        
            system("cls");    
            cout<<"请输入起始点: ";    
            cin.getline(tmp,50);  
            cout<<"请输入出发时间 ";  
            cin.getline(tmp1,50);  
              
            while(1)  
            {  
                int flag1=0;  
                char *s,*p;  
                string str,str1,st1,st2,st3,st4,st5,st6,st7;  
                str=str1=" ";  
                s =&str[0];  
                p =&str1[0];  
                ifstream myfile("car.txt");   
                while(!myfile.eof())  
                {     
                    getline(myfile,st1,' ');      
                    getline(myfile,st2,' ');      
                    getline(myfile,st3,' ');  
                    getline(myfile,str,' ');  
                    getline(myfile,str1,' ');  
                    getline(myfile,st4,' ');  
                    getline(myfile,st5,' ');  
                    getline(myfile,st6,' ');  
                    getline(myfile,st7,'\n');  
                    if(strcmp(tmp,s)==0 && strcmp(tmp1,p)==0)  
                    {            
                        cout<<"\n  车次 : "<<st1<<"\t车号 : "<<st2<<"\t最大载客数 : "<<st3<<" 人"  
                            <<"\n  始发地 : "<<left<<setw(20)<<str<<"\t出发时间   : "<<str1  
                            <<"\n  目的地 : "<<left<<setw(20)<<st4<<"\t到达时间   : "<<st5  
                            <<"\n  票  价 : "<<st6<<" 元\t\t"<<"已订票人数:  "<<st7<<" 人\n";  
                        flag1=1;          
                    }  
                }  
                cout<<"  当前时间 : "  
                    <<timeinfo->tm_hour<<":"<<timeinfo->tm_min;  
                myfile.close();  
                if(!flag1)            
                    cout<<"\n 不存在该班车 \n";  
                comeon();                 
                search();  
                break;  
            }  
              
        case '3':  
            fflush(stdin);  
            system("cls");    
            cout<<"请输入目的地: ";  
            cin.getline(tmp,100);  
            cout<<"请输入到达时间(请英文状态下输入):: ";  
            cin.getline(tmp1,50);  
              
            while(1)  
            {  
                int flag1=0;  
                char *s,*p;  
                string str,str1,st1,st2,st3,st4,st5,st6,st7;  
                str=str1=" ";  
                s =&str[0];  
                p =&str1[0];  
                ifstream myfile("car.txt");   
                while(!myfile.eof())  
                {     
                    getline(myfile,st1,' ');      
                    getline(myfile,st2,' ');      
                    getline(myfile,st3,' ');  
                    getline(myfile,st4,' ');  
                    getline(myfile,st5,' ');  
                    getline(myfile,str,' ');  
                    getline(myfile,str1,' ');  
                    getline(myfile,st6,' ');  
                    getline(myfile,st7,'\n');  
                    if(strcmp(tmp,s)==0 && strcmp(tmp1,p)==0)  
                    {             
                        cout<<"\n  车次 : "<<st1<<"\t车号 : "<<st2<<"\t最大载客数 : "<<st3<<" 人"  
                            <<"\n  始发地 : "<<left<<setw(20)<<st4<<"\t出发时间   : "<<st5  
                            <<"\n  目的地 : "<<left<<setw(20)<<str<<"\t到达时间   : "<<str1  
                            <<"\n  票  价 : "<<st6<<" 元\t\t\t"<<"已订票人数:  "<<st7<<" 人\n";  
                        flag1=1;      
                    }  
                }  
                cout<<"  当前时间 : "  
                    <<timeinfo->tm_hour<<":"<<timeinfo->tm_min;  
                myfile.close();  
                if(!flag1)            
                    cout<<"\n不存在该班车 \n";  
                comeon();             
                search();  
                break;  
            }  
              
        case '4':                 
            system("cls");  
            main();  
            break;  
        default:  
            system("cls");        
            cout<<"输入有误\n\n\n";  
            Sleep(1000);  
            system("cls");  
            break;  
        }  
    }  
}  
    
  
void book()  
{  
    system("cls");  
    f=1;  
    char a,tmp[100],tmp1[30];  
    time_t rawtime;  
    struct tm * timeinfo;     
    time ( &rawtime );  
    timeinfo = localtime ( &rawtime );  
      
    while(f)  
    {  
        if(flag == 0)  
        {     
            f=0;  
            system("cls");  
            main();  
        }  
        cout<<"\n\n*************************     欢迎使用班次订票页面  *******************************   \n";  
        cout<<"\t\t1、订车票                  *\n"  
            <<"\t\t2、返回主菜单              *\n"  
            <<"\t\t*************************************************************************************\n";  
        cin>>a;  
        switch(a)  
        {  
        case '1':  
            fflush(stdin);  
            system("cls");    
            cout<<"请输入目的地: ";  
            cin.getline(tmp,100);  
            cout<<"请输入到达时间";  
            cin.getline(tmp1,50);  
            while(1)  
            {  
                int flag1=0;  
                char *s,*p,b;  
                string str,str1,st1,st2,st3,st4,st5,st6,st7;  
                str=str1=" ";  
                s =&str[0];  
                p =&str1[0];  
                ifstream myfile("car.txt");       
                while(!myfile.eof()&&flag==1)  
                {     
                    getline(myfile,st1,' ');      
                    getline(myfile,st2,' ');  
                    getline(myfile,st3,' ');  
                    getline(myfile,st4,' ');  
                    getline(myfile,st5,' ');  
                    getline(myfile,str,' ');  
                    getline(myfile,str1,' ');  
                    getline(myfile,st6,' ');  
                    getline(myfile,st7,'\n');  
                    if(strcmp(tmp,s)==0 && strcmp(tmp1,p)==0)     
                    {     
                        cout<<"\n  车次 : "<<st1<<"\t车号 : "<<st2<<"\t最大载客数 : "<<st3<<" 人"  
                            <<"\n  始发地 : "<<left<<setw(20)<<st4<<"\t出发时间   : "<<st5  
                            <<"\n  目的地 : "<<left<<setw(20)<<str<<"\t到达时间   : "<<str1  
                            <<"\n  票  价 : "<<st6<<" 元\t\t\t"<<"已订票人数:  "<<st7<<" 人\n";  
                        flag1=1;         
                    }     
                }  
                myfile.close();      
                if(flag1)             
                {  
                    tmp[0]=' ';  
                    cout<<"以上为班车信息!"  
                        <<"是否订票? Y/N\n";  
                    cin>>b;            
                }  
                if(b=='y'||b=='Y')  
                {  
                    ofstream file;        
                    ofstream tmpfile;  
                    ifstream myfile("car.txt");  
                    tmpfile.open("bak.txt",ios::trunc);  
                    file.open("passenger.txt",ios::app);  
                      
                    string tmp1,tmp,num,max,ttl;  
                    tmp=" ";  
                    int i=1,flag=0;  
                    char *pp,*p;  
                    passenger *head,*p1,*p2;  
                    head = NULL;  
                    p1 = new(passenger);  
                    p2 = p1;  
                    pp=&tmp[0];  
                    system("cls");  
                    cout<<"请输入对应的信息>>>>>>>>>>>>>\n"  
                        <<"    车  次  :";  
                    cin>>p1->numbers;        
                    while(!myfile.eof())  
                    {  
                        getline(myfile,tmp,' ');  
                        if(strcmp(pp,p1->numbers)==0)  
                        {         
                            flag=1;           
                            for(i=1;i<8;i++)  
                            {                 
                                getline(myfile,num,' ');  
                                if(i==2)  
                                    max=num;      
                                if(i==4)  
                                    ttl=num;      
                                p=&(ttl[0]);  
                            }  
                            getline(myfile,num,'\n');   
                            if(gethour(p)<timeinfo->tm_hour)  
                            {        
                                file.close();  
                                myfile.close();  
                                tmpfile.close();  
                                cout<<"\n  亲,该班次已发出!!!\n";  
                                comeon();  
                                book();  
                                break;  
                            }    
                            else if(gethour(p)<=timeinfo->tm_hour)  
                            {  
                                  
                                if(getmin(p)<=timeinfo->tm_min)  
                                    cout<<"\n该班次已发出!!!\n";  
                                file.close();  
                                myfile.close();  
                                tmpfile.close();  
                                comeon();  
                                book();  
                                break;  
                            }  
                            if(atoi(&num[0])>atoi(&max[0]))  
                            {     
                                file.close();  
                                myfile.close();  
                                tmpfile.close();  
                                cout<<"对不起,该班次已满座,请定另外一班\n";  
                                comeon();  
                                book();  
                                break;  
                            }  
                            break;    
                        }  
                        getline(myfile,tmp1,'\n');                          
                    }  
                    myfile.close();  
                    if(flag==0)  
                    {     
                        cout<<"该班次不存在\n";  
                        file.close();  
                        myfile.close();  
                        tmpfile.close();  
                        comeon();  
                        book();  
                    }    
                    cout<<"    姓  名  :";  
                    cin>>p1 ->name;  
                      
                    cout<<"  身份证号码:";  
                    cin>>p1->id;  
                      
                    cout<<"  订  票  数:";  
                    cin>>p1->ticket;  
                    if(atoi(&num[0])+atoi(&(p1->ticket[0]))>atoi(&max[0]))  
                    {  
                        file.close();  
                        myfile.close();  
                        tmpfile.close();  
                        cout<<"剩余的票数已不足\n"  
                            <<"你最多只能订购 "<<atoi(&max[0])-atoi(&num[0])<<" 张票\n";  
                        comeon();  
                        book();  
                    }     
                    file<<p1->numbers<<" "<<p1->name<<" "       
                        <<p1->id<<" "<<p1->ticket<<" ";  
                    cout<<"  座  位  号:"  
                        <<atoi(&(num[0]))+1<<" --- "  
                        <<atoi(&(num[0]))+atoi(&(p1->ticket[0]))<<'\n';  
                    file<<atoi(&(num[0]))+atoi(&(p1->ticket[0]))<<'\n';  
                    cout<<"  恭喜你订票成功!\n";  
                    file.close();  
                    ifstream ff("car.txt");       
                    while(!ff.eof())  
                    {  
                        string str,str1,str2;  
                        int tt,flag=0;                    
                        for(i=0;i<8;i++)  
                        {  
                            getline(ff,str,' ');  
                            if(strcmp(&str[0],p1->numbers)==0)  
                                flag=1;  
                            tmpfile<<str<<' ';  
                              
                        }  
                        getline(ff,str1,'\n');  
                        if(flag)  
                        {  
                            flag=0;  
                            tt=atoi(&str1[0])+atoi(&(p1->ticket[0]));  
                            tmpfile<<tt<<'\n';  
                            getline(ff,str,'\0');  
                            tmpfile.close();  
                        }  
                        else   
                            tmpfile<<str1<<'\n';      
                    }  
                    ff.close();  
                    tmpfile.close();  
                    ofstream f1("car.txt",ios::trunc);  
                    ifstream f2("bak.txt");  
                    while(!f2.eof())     
                    {  
                        string s;  
                        getline(f2,s,'\0');  
                        f1<<s;  
                    }  
                    f1.close();  
                    f2.close();  
                    comeon();  
                    book();  
            }             
            else if(b=='n'||b=='N')  
            {     
                comeon();  
                book();  
            }  
            else     
            {  
                system("cls");  
                cout<<"输入有误\n\n\n";  
                Sleep(1000);  
                system("cls");  
                book();  
            }        
            if(!flag1)  
            {  
                cout<<"\n   亲,找不到该班车信息 (>.<) \n";  
                comeon();  
                book();  
                break;  
            }  
            }     
              
        case '2':         
            system("cls");  
            main();  
            break;  
        default:         
            system("cls");  
            cout<<"输入有误\n\n\n";  
            Sleep(1000);  
            system("cls");  
            break;  
              
              
        }  
    }  
}  
  
   
int comeon()  
{  
    char answer,a=0;  
    do{  
        cout<<"\n是否继续操作?  Y/N ";  
        fflush(stdin);  
        cin>>answer;  
        if(answer=='y'||answer=='Y')  
        {  
            system("cls");  
            f = 1;  
            flag = 1;  
            return 1;  
        }  
        else if(answer=='n'||answer=='N')  
        {  
            flag =0;  
            system("cls");  
            break;  
        }  
        else  
        {  
            system("cls");  
            cout<<"出错了\n\n";  
            a=1;  
        }     
    }while(a);  
    return 0;  
}  
 
int gethour(char *s)  
{  
    char *p,*q;  
    p=(char*)malloc(10);  
    strcpy(p,s);  
    q = p;  
    while(*q!=':')  
        q++;  
    *q='\0';  
    return atoi(p);  
}  
  
int getmin(char *s)  
{  
    char *p;  
    p=(char*)malloc(10);  
    strcpy(p,s);  
    while(*p!=':')  
        p++;  
    p++;  
    return atoi(p);  
}  
一下为主页面

增加班次信息:


退出页面


订票情况



 做个课程设计花费了大量时间,有很多不懂得地方,遇到了很多问题,调试了很久,但最后还是出错,问题太多了。最后只能参考人家的作品,重新做了一遍。但还是有很多不够完善的地方。比如增加班次信息,应该另外弄一个密码进入程序,以防止人人都能修改班次,因为这个程序同时服务于官方和顾客。这也是这个题目矛盾的地方。再是,在订票时,必须得先查询班次信息,以便输入相应信息,才能订票。这个弄得有点繁琐,毕竟乘客不一定能记住该信息,会造成极大不便。还有,当进入错误的页面时还应该增加一个提前退出的设置。


  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值