• C++与数据结构课程设计---定票咨询系统


    订票咨询管理系统

     设计编制一个订票管理系统,考虑旅客不同的要求。例如,选择不同的交通工具,希望在旅途中的时间尽可能地短,期望旅费尽可能省,或要求中转次数最少等。为旅客提供两种或三种最优决策。车票基本信息包括:车次、出发站、终点站、额定票数、已订票人数、金额、座位号、发车时间、到站时间等。

    基本功能与技术要求

    1、 数据文件管理功能:创建新文件、打开文件、保存文件。

    2、计算与统计功能:完成记录中相关数据的最优计算与分析;

    1)能够打开已存在的数据表文件,根据出发站和到达站计算需要多长时间才能到达及需要多少旅费及中转次数。

    2)分析提供旅客最佳选择方案。

    3、记录管理功能:记录的管理采用链表或者指针数组实现。

    1)输入/添加/插入记录,并保存到数据文件中。

    2)查询、显示记录,根据用户要求按所给发车时间、票数、金额等记录关键字排序,查询一个或多个相关联记录的各项信息。

    3)修改记录:能够打开已存在的数据表文件,并对确定的任意记录进行修改,在修改过程中,应显示记录信息,给出确认提示,并对更新的记录信息进行文件保存。

    4)删除记录:能够打开已存在的数据表文件,可以删除数据表中的任一记录,要求具备逻辑删除(具有恢复功能)和物理删除功能,并对新的数据表信息进行文件保存。

     

    一.需求分析

    考虑旅客的不同需求,比如乘坐不同的交通工具,有什么紧急的事情要求时间尽可能短,或则为零追去舒适度而去选择尽可能少的中转,或则考虑经济能力选择所需费用最少的等,根据旅客的不同需求为他们推荐最适合他们的出行路线。

    二.总体设计

    流程图为:

     

    三.详细设计

    1.模块总览

    void IO_read();//将文件中内容读出来

    void ex_pre();//建图

    void IO_write();//把建好的图写到line.txt文件里

    void Init();//初始化航班和车次

    void function1();//录入与删除信息

    void function2();//浏览所有信息

    void function3();//用户咨询(包括购买票的操作)

    void show_all();//显示当前所有航班及车次的信息

    void change_plane();//修改航班

    void change_train();//修改车次

    void add_plane();//增加航班

    void add_train();//增加车次

    void del_plane();//删除航班(包括物理删除和逻辑删除)

    void del_train();//删除车次(包括物理删除和逻辑删除)  

    int min_money(string s,string t);//起点到终点的最小费用及其路线  

    int min_trans(string s,string t);//起点到终点的最少中转次数用及其路线

    int min_time(string s,string t);//起点到终点的最小时间用及其路线

    void reset_del();//恢复被逻辑删除的航班或车次

    1. 模块说明

    void IO_write(); 这个函数主要调用C++输出流将指定文件里面的内容读出,然后赋值给相应的变量,从而实现后面的操作。

    void IO_read(); 这个函数也是使用C++输入流将内容写到指定文建中,然后保存,方便用户查询。

    void ex_pre();这个函数是用从文件中读出的航班以及车次信息建立一张有向网络图。

    (a). 其中对于城市的处理采用map<string,int>将每个城市映射为一个数字,然后再后面查询时,只要将起点在,终点线映射数字后,只要求对应网上的数字之间的信息即可。

    (b).对于城市数量,将他放在set<string>(具有自动去重的功能)容器里面,这样方便查询城市相关信息。

    void Init();这个函数是对交通网络的初始化,就是当你需从文件里面读入的时候,可以自己创建一张交通网路,里面可以添加航班,车次(包含 班次,起点,终点,起始时间,终止时间,价格,额定票数,已售票数,并将该信息创建为网络图存到相应文件里面。

    void function1();这是一个界面里面有 录入与删除信息的选项供用户选择。

    void function2();这是一个界面会有选项显示当前所有信息

    void function3();用户咨询界面里面有查询航班,车次选项,以及给出起点,终点,以及想要的出行方式,然后会转入到对应程序里面。

    void show_all();这个函数是用来显示当前所有航班及车次的信息。

    int min_money(string s,string t);计算起点到终点的最小费用及其路线,用Dijkstra(堆优化),来实现。  

    int min_trans(string s,string t);//起点到终点的最少中转次数用及其路线,用

    Dijkstra(堆优化),来实现。  

    int min_time(string s,string t);起点到终点的最小时间用及其路线,用深度优先搜索来搜索最短时间,并记录路径。

    void change_plane();修改航班,这里面会有增加和删除航班的操作,然后根据选择转到对应的程序里面。

    void change_train();修改车次,这里面会有增加和删除车次的操作,然后根据选择转到对应的程序里面。

    void add_plane();增加航班,当用户选择这个操作后,会会转入到这个程序。这个程序会让你将将要增加的航班的班次,起点,终点,起始时间,终止时间,费用。

    void add_train();增加车次,当用户选择这个操作后,会会转入到这个程序。这个程序会让你将将要增加的火车的班次,起点,终点,起始时间,终止时间,费用。

    void del_plane();//删除航班(包括物理删除和逻辑删除)。对于物理删除:我们将管理员输入的类型及其班次对应的一条线路从文件里面删除,逻辑删除:则是对相应的线路打标记,并不删除,只是当前不可以用。

    void del_train();//删除车次(包括物理删除和逻辑删除) 。对于物理删除:我们将管理员输入的类型及其班次对应的一条线路从文件里面删除,逻辑删除:则是对相应的线路打标记,并不删除,只是当前不可以用。

    void reset_del();恢复被逻辑删除的航班或车次,就是讲管理员输入类型班次的线路的标记取消,也就恢复了。

    参考代码:

      1 #include<iostream>
      2 #include<cstring>
      3 #include<string>
      4 #include<fstream>
      5 #include<algorithm>
      6 #include<queue>
      7 #include<list>
      8 #include<stack> 
      9 #include<set>
     10 #include<vector>
     11 #include<map>
     12 #include<ctime>
     13 using namespace std;
     14 string admin="123";
     15 const int size=1e3+5;
     16 const int inf=0x3f3f3f3f;
     17 typedef pair<int,int> pii;
     18 vector<string> roar;//记录路线 
     19 bool vis[size][size];
     20 
     21 struct transfor{
     22     string no;// 班次 
     23     string beg;// 起点 
     24     string ed;// 终点 
     25     int tk;// 票数 
     26     int num;// 已售票数 
     27     int money;// 价格 
     28     int beg_tim;//起始时间 
     29     int end_tim;//终止时间 
     30     string typp;//飞机或火车 
     31     bool flag;//标记是否逻辑删除 
     32 };
     33 vector<transfor> Edge[size];// 
     34 vector<pii> val[2][size];// 存费用 /中转次数 
     35 vector<transfor> total;//存储所有航线和车次 
     36 set<string> point;//存储城市(具有自动去重的能力) 
     37 map<string,int> pointno;//将城市映射为数字 
     38 
     39 struct Node{
     40     int id,w;
     41     Node(int id,int w):id(id),w(w){} 
     42     friend bool operator<(Node a,Node b)
     43     {
     44         return a.w<b.w;
     45     }
     46 };
     47 priority_queue<Node> q;//用堆优化dijkstra 
     48 int dis[size];
     49 pair<string,string> pre[size];
     50 typedef pair<string,string> pss;
     51 vector<string> T;
     52 int ans=inf;
     53 
     54 void ex_pre();//建图 
     55 void IO_read();//从文件中拿出来 
     56 void ex_pre();//建图 
     57 void IO_write();//把图写到txt里 
     58 
     59 void Init();//初始化航班和车次
     60 void function1();//录入与删除信息
     61 void function2();//浏览列车信息
     62 void function3();//用户咨询
     63 
     64 void show_all();//显示所有信息 
     65 void change_plane();//修改航班
     66 void change_train();//修改车次 
     67 void del_plane();//删除航班 
     68 void del_train();//删除车次 
     69 void add_plane();//增加航班 
     70 void add_train();//增加车次
     71 
     72 int min_money(string s,string t);//最小费用  
     73 int min_trans(string s,string t);//最少中转次数 
     74 int dfs(int s,int t,int bt);
     75 void reset_del();  
     76 
     77 int main()
     78 {
     79     total.clear();IO_read();ex_pre();//把文件中内容读取出来 
     80     cout<<"
    
    
    
    
    
    ";
     81     cout<<"                     ---------------------------------------------------"<<endl;
     82     cout<<"                    | 1:录入与删除信息(需管理员权限)     2:浏览所有信息 |"<<endl;
     83     cout<<"                    | 3:用户咨询                         0:退出         |"<<endl; 
     84     cout<<"                     ---------------------------------------------------"<<endl;
     85     cout<<"
    
    
    ";
     86     cout<<"         请输入选择操作号码:"; 
     87     int my_choice;
     88     cin>>my_choice;
     89     if(my_choice==0) return 0;
     90     while(true)
     91     {
     92         if(my_choice==1) function1();
     93         else if(my_choice==2) function2();
     94         else if(my_choice==3) function3(); 
     95         system("cls");
     96         cout<<"
    
    
    
    
    
    ";
     97         cout<<"                     ---------------------------------------------------"<<endl;
     98         cout<<"                    | 1:录入与删除信息(需管理员权限)     2:浏览所有信息 |"<<endl;
     99         cout<<"                    | 3:用户咨询                         0:退出         |"<<endl; 
    100         cout<<"                     ---------------------------------------------------"<<endl;
    101         cout<<"
    
    
    ";
    102         cout<<"         请输入选择操作号码:"; 
    103         cin>>my_choice;
    104         if(my_choice==0) break;
    105     }
    106     return 0;
    107 }
    108 
    109 void function1()//录入与删除信息
    110 {
    111     system("cls");
    112     cout<<"
    
                 **欢迎进入录入与删除信息系统**
    
    
    "<<endl;
    113     cout<<"请输入密码:";string admin_mima,ch;
    114     while(cin>>admin_mima)
    115     {
    116         if(admin_mima!=admin) 
    117         {
    118             cout<<"             密码错误!!!"<<endl;
    119             cout<<"             是否继续?yes/no:";
    120             cin>>ch;
    121             if(ch=="no") return ;    
    122         }
    123         if(admin_mima==admin) break;
    124     }
    125     system("cls");
    126     cout<<"             **欢迎进入录入与删除信息系统**
    
    
    "<<endl;
    127     cout<<"              0:初始化航班和车次"<<endl; 
    128     cout<<"              1:增加/删除航班 "<<endl;
    129     cout<<"              2:增加/删除车次 "<<endl;
    130     cout<<"              3:恢复删除的航班/车次"<<endl;
    131     cout<<"              4:返回上一界面"<<endl;
    132     cout<<"
    
    
          请输入你的选择: ";
    133     int Choice;
    134     cin>>Choice;
    135     if(Choice==4) return ;
    136     else if(Choice==0) Init(); 
    137     else if(Choice==1) change_plane();////
    138     else if(Choice==2) change_train();////
    139     else if(Choice==3) reset_del();
    140 }
    141 
    142 void function2()//浏览所有信息
    143 {
    144     system("cls");
    145     cout<<"
    
                 **所有航班及车次如下**
    
    "<<endl;
    146     show_all();
    147     cout<<"   请输入1返回.";
    148     int str;
    149     cin>>str;
    150 }
    151 
    152 void function3()//用户咨询
    153 {
    154     system("cls");
    155     cout<<"
    
                 请输入您需要乘坐的交通工具"<<endl;
    156     cout<<"     1: 飞机 "<<endl;
    157     cout<<"     2: 火车 "<<endl;
    158     cout<<"     3: 返回 "<<endl;
    159     int choice_type;
    160     cin>>choice_type;
    161     if(choice_type==3) return ;
    162     string Start,End;
    163     cout<<endl;
    164     cout<<"           请输入起点: ";
    165     cin>>Start;
    166     cout<<"           请输入终点: ";
    167     cin>>End;
    168     system("cls");
    169     cout<<"
    
    
    
    
    
    ";
    170     cout<<"                请选择您的意愿
    
    "<<endl;
    171     cout<<"                  1:费用最少"<<endl; 
    172     cout<<"                  2:中转最少"<<endl;
    173     cout<<" 请输入你的选择: ";
    174     int cho;
    175     cin>>cho;
    176     
    177     if(cho==1) 
    178     {
    179         int Minmoney;
    180         Minmoney=min_money(Start,End);//////
    181         if(Minmoney>=inf) 
    182         { 
    183             cout<<" 抱歉!没有您需要的类型"<<endl;
    184             cout<<"输入1返回: ";int sssv;
    185             cin>>sssv;
    186             return ;
    187         }
    188         cout<<"   最少费用为: "<<Minmoney<<endl;
    189         cout<<"   费用最少的推荐为:";
    190         vector<string>::iterator it;
    191         vector<transfor>::iterator itt;
    192         for(it=roar.begin();it!=roar.end();++it) cout<<(*it)<<" ";//依次输出路径 
    193         cout<<endl;
    194         cout<<"           是否购买?yes/no: ";
    195         string isbuy;
    196         cin>>isbuy;
    197         if(isbuy=="no") return ;
    198         else if(isbuy=="yes")
    199         {
    200             for(it=roar.begin();it!=roar.end();++it) 
    201             {
    202                 for(itt=total.begin();itt!=total.end();++itt) ///////////
    203                 {
    204                     if((*itt).tk<=(*itt).num) { cout<<"无票"<<endl;return ;}
    205                     if((*itt).no==(*it) && (*itt).tk>(*itt).num) (*itt).num++;
    206                 }
    207             }
    208             ex_pre();IO_write();////跟新 
    209             cout<<"  **购买成功!!!**"<<endl;
    210             cout<<"输入1返回: ";int sssv;
    211             cin>>sssv;
    212         }
    213     }
    214     else if(cho==2) 
    215     {
    216         int times=min_trans(Start,End);//////
    217         if(times>=inf) 
    218         { 
    219             cout<<" 抱歉!没有您需要的类型"<<endl;
    220             cout<<"输入1返回: ";int sssv;
    221             cin>>sssv;
    222             return ;
    223         }
    224         cout<<"   中转次数最少为: "<<times<<endl;
    225         cout<<"   中转次数最少的推荐为:";
    226         vector<string>::iterator it;
    227         vector<transfor>::iterator itt;
    228         for(it=roar.begin(); it!=roar.end() ;++it ) cout<<(*it)<<" ";
    229         cout<<endl;
    230         cout<<"           是否购买?yes/no: ";
    231         string isbuy;
    232         cin>>isbuy;
    233         if(isbuy=="no") return ;
    234         else if(isbuy=="yes")
    235         {
    236             for(it=roar.begin();it!=roar.end();++it) 
    237             {
    238                 for(itt=total.begin();itt!=total.end();++itt) if((*itt).no==(*it)) (*itt).num++;
    239             }
    240             ex_pre();IO_write();////////////
    241             cout<<"  **购买成功!!!**"<<endl;
    242             cout<<"输入1返回: ";int sssv;
    243             cin>>sssv;
    244         }
    245     }
    246 }
    247 /////////////function1()管理员的操作 
    248 void Init()//初始化航班和车次
    249 {
    250     system("cls");
    251     cout<<"
    
    
          欢迎来到初始化航班和车次界面
    
    "<<endl;
    252     total.clear();//初始化清空所有航线/班次 
    253     transfor tran;
    254     while(true)
    255     { 
    256         string choice;
    257         int t1,t2;
    258         cout<<"                   是否输入航班?yes/no: ";
    259         cin>>choice;
    260         if(choice=="no") break;
    261         tran.typp="plane";tran.flag=false;//这条航线标记为false(即为可以用) 
    262         cout<<"            请输入航班编号:";
    263         cin>>tran.no;
    264         cout<<"            请输入航班起始时间:";
    265         cin>>tran.beg_tim;
    266         cout<<"            请输入航班终止时间:";
    267         cin>>tran.end_tim;
    268         cout<<"            请输入航班起始地点:";
    269         cin>>tran.beg;
    270         cout<<"            请输入航班终止地点:";
    271         cin>>tran.ed;
    272         cout<<"            请输入航班费用:";
    273         cin>>tran.money;
    274         cout<<"            请输入航班额定票数:";
    275         cin>>tran.tk;
    276         cout<<"            请输入航班已售票数:"; 
    277         cin>>tran.num;
    278         point.insert(tran.beg);
    279         point.insert(tran.ed);
    280         total.push_back(tran);
    281     } 
    282     while(true)
    283     { 
    284         string choice;
    285         int t1,t2;
    286         cout<<"                   是否输入车次?yes/no: ";
    287         cin>>choice;
    288         if(choice=="no") break;
    289         tran.typp="train"; tran.flag=false;
    290         cout<<"            请输入车次编号:";
    291         cin>>tran.no;
    292         cout<<"            请输入车次起始时间:";
    293         cin>>tran.beg_tim;
    294         cout<<"            请输入车次终止时间:";
    295         cin>>tran.end_tim;
    296         cout<<"            请输入车次起始地点:";
    297         cin>>tran.beg;
    298         cout<<"            请输入车次终止地点:";
    299         cin>>tran.ed;
    300         cout<<"            请输入车次费用:";
    301         cin>>tran.money;
    302         cout<<"            请输入车次额定票数:";
    303         cin>>tran.tk;
    304         cout<<"            请输入车次已售票数:"; 
    305         cin>>tran.num;
    306         //tran.beg_tim.outbecome(t1);//////
    307         //tran.end_tim.outbecome(t2);//////
    308         point.insert(tran.beg);
    309         point.insert(tran.ed);
    310         total.push_back(tran);
    311     } 
    312     ex_pre();//建图
    313     IO_write();//把图写进文件里面 
    314 } 
    315 
    316 
    317 
    318 void change_plane()//修改航班 
    319 {
    320     system("cls");
    321     cout<<"
    
    
                 请选择操作:
    "<<endl;
    322     cout<<"      1:增加航班"<<endl;
    323     cout<<"      2:删除航班"<<endl;
    324     int choice;
    325     cin>>choice;
    326     switch(choice)
    327     {
    328         case 1:add_plane();break;
    329         case 2:del_plane();break; 
    330     } 
    331     
    332 }
    333 void change_train()//修改车次 
    334 {
    335     system("cls");
    336     cout<<"
    
    
    ";
    337     cout<<"      1:增加车次"<<endl;
    338     cout<<"      2:删除车次"<<endl;
    339     int choice;
    340     cin>>choice;
    341     switch(choice)
    342     {
    343         case 1:add_train();break;
    344         case 2:del_train();break; 
    345     } 
    346 }
    347 void del_plane()//删除航班 
    348 {
    349     system("cls"); 
    350     cout<<"
    
    
                 欢迎来到删除航班的界面
    
    "<<endl;
    351     //while(true)
    352     //{
    353         cout<<"        请选择要进行的操作
    "<<endl;
    354         cout<<"    1:逻辑删除  2:物理删除
    "<<endl;    
    355         int choice;
    356         cin>>choice;
    357         if(choice==1)//逻辑删除:只是打个标记,并没有真正从文件里面删除 
    358         {
    359             cout<<"    输入要删除的航班的编号:";
    360             string str;bool temp=false;
    361             cin>>str;//vrctor total
    362             for(auto i=total.begin();i!=total.end();++i)
    363             {
    364                 if((*i).no==str&&(*i).typp=="plane")
    365                 {
    366                     (*i).flag=true;
    367                     temp=true;
    368                     break;
    369                 }
    370                 i++;
    371             }
    372             if(!temp) cout<<" 没有此编号的航班!!!"<<endl;
    373         }
    374         else if(choice==2)//物理删除 
    375         {
    376             cout<<"    输入要删除的航班的编号:";
    377             string str;bool temp=false;
    378             cin>>str;//vrctor total
    379             vector<transfor>::iterator it=total.begin();
    380             //cout<<" al  "<<total.size()<<endl;
    381             while(it!=total.end())
    382             {
    383                 if((*it).no==str&&(*it).typp=="plane")
    384                 {
    385                     total.erase(it);//删除total里面的航班 
    386                     temp=true;
    387                     break;
    388                 }
    389                 it++;
    390             }
    391             //cout<<" al  "<<total.size()<<endl;
    392             if(!temp) {cout<<"没有此航班!!!"<<endl;} 
    393         }
    394         ex_pre();//从新构图 
    395         IO_write();//吧图从新存在line.txt里面
    396     //} 
    397 }
    398 void del_train()//删除车次
    399 {
    400 
    401     system("cls"); 
    402     cout<<"
    
    
                 欢迎来到删除车次的界面
    
    "<<endl;
    403     //while(true)
    404     //{
    405         cout<<"        请选择要进行的操作
    "<<endl;
    406         cout<<"    1:逻辑删除  2:物理删除
    "<<endl;    
    407         int choice;
    408         cin>>choice;
    409         if(choice==1)//逻辑删除:只是打个标记,并没有真正从文件里面删除 
    410         {
    411             cout<<"    输入要删除的车次的编号:";
    412             string str;bool temp=false;
    413             cin>>str;//vrctor total
    414             for(auto i=total.begin();i!=total.end();++i)
    415             {
    416                 if((*i).no==str&&(*i).typp=="train")
    417                 {
    418                     (*i).flag=true;
    419                     temp=true;
    420                     break;
    421                 }
    422                     i++;
    423             }
    424             if(!temp) cout<<" 没有此编号的车次!!!"<<endl;
    425         }
    426         else if(choice==2)//物理删除 
    427         {
    428             cout<<"    输入要删除的车次的编号:";
    429             string str;bool temp=false;
    430             cin>>str;//vrctor total
    431             vector<transfor>::iterator it=total.begin();
    432             while(it!=total.end())
    433             {
    434                 if((*it).no==str&&(*it).typp=="train")
    435                 {
    436                     total.erase(it);//删除total里面的车次 
    437                     temp=true;
    438                     break;
    439                 }
    440                 it++;
    441             }
    442             if(!temp) {cout<<"没有此车次!!!"<<endl;}
    443         }
    444         ex_pre();//从新构图 
    445         IO_write();//吧图从新存在line.txt里面 
    446     //}     
    447 }
    448 void add_train()//增加车次
    449 {
    450     system("cls");
    451     cout<<"
    
    
                 欢迎来到增加车次的界面
    
    "<<endl;
    452     transfor tran;
    453     while(true)
    454     { 
    455         string choice;
    456         int t1,t2;
    457         tran.typp="train"; tran.flag=false;
    458         cout<<"            请输入车次编号:";
    459         cin>>tran.no;
    460         cout<<"            请输入车次起始时间:";
    461         cin>>tran.beg_tim;
    462         cout<<"            请输入车次终止时间:";
    463         cin>>tran.end_tim;
    464         cout<<"            请输入车次起始地点:";
    465         cin>>tran.beg;
    466         cout<<"            请输入车次终止地点:";
    467         cin>>tran.ed;
    468         cout<<"            请输入车次费用:";
    469         cin>>tran.money;
    470         cout<<"            请输入车次额定票数:";
    471         cin>>tran.tk;
    472         cout<<"            请输入车次已售票数:"; 
    473         cin>>tran.num;
    474         //tran.beg_tim.outbecome(t1);//////
    475         //tran.end_tim.outbecome(t2);//////
    476         point.insert(tran.beg);
    477         point.insert(tran.ed);
    478         total.push_back(tran);
    479         cout<<"                   是否输入车次?yes/no";
    480         cin>>choice;
    481         if(choice=="no") break;
    482     }
    483     ex_pre();
    484     IO_write();
    485 }
    486 void add_plane()//增加航班 
    487 {
    488     system("cls");
    489     cout<<"
    
    
                 欢迎来到增加航班的界面
    
    "<<endl;
    490     transfor tran;
    491     while(true)
    492     { 
    493         string choice;
    494         int t1,t2;
    495         tran.typp="plane";tran.flag=false;//这条航线标记为false(即为可以用) 
    496         cout<<"            请输入航班编号:";
    497         cin>>tran.no;
    498         cout<<"            请输入航班起始时间:";
    499         cin>>tran.beg_tim;
    500         cout<<"            请输入航班终止时间:";
    501         cin>>tran.end_tim;
    502         cout<<"            请输入航班起始地点:";
    503         cin>>tran.beg;
    504         cout<<"            请输入航班终止地点:";
    505         cin>>tran.ed;
    506         cout<<"            请输入航班费用:";
    507         cin>>tran.money;
    508         cout<<"            请输入航班额定票数:";
    509         cin>>tran.tk;
    510         cout<<"            请输入航班已售票数:"; 
    511         cin>>tran.num;
    512         //tran.beg_tim.outbecome(t1);//////
    513         //tran.end_tim.outbecome(t2);//////
    514         point.insert(tran.beg);
    515         point.insert(tran.ed);
    516         total.push_back(tran);
    517         cout<<"                   是否输入航班?yes/no";
    518         cin>>choice;
    519         if(choice=="no") break;
    520     } 
    521     ex_pre();
    522     IO_write();
    523 }
    524 
    525 void reset_del()///恢复逻辑删除内容 
    526 {
    527     system("cls");
    528     string typ,number;bool tempp=false;
    529     cout<<"   请输入要恢复的类型(plane/train): ";
    530     cin>>typ;
    531     cout<<"   请输入要恢复的的编号: ";
    532     cin>>number;
    533     vector<transfor>::iterator it=total.begin();
    534     while(it!=total.end())
    535     {
    536         if((*it).no==number && (*it).flag)
    537         {
    538             tempp=true;(*it).flag=0;//取消标记 
    539             break;
    540         }
    541         it++;
    542     }
    543     if(!tempp) cout<<"  没有找到相应逻辑删除的班次!!!"<<endl;
    544     else cout<<"    **恢复成功!!!**"<<endl; 
    545     ex_pre();
    546     IO_write();
    547 }
    548 ////////////////////////////////////////////
    549 int min_money(string s,string t)//最小费用 
    550 {
    551     int beg=pointno[s],end=pointno[t];
    552     memset(dis,inf,sizeof(dis));
    553     while(!q.empty()) q.pop();
    554     dis[beg]=0;
    555     q.push(Node(beg,0));
    556     while(!q.empty())
    557     {
    558         Node S=q.top();
    559         q.pop();
    560         int id=S.id;
    561         if(dis[id]!=S.w) continue;
    562         for(int i=0;i<Edge[id].size();i++)
    563         {
    564             if(dis[pointno[Edge[id][i].ed]]>dis[id]+Edge[id][i].money&&!Edge[id][i].flag)
    565             {
    566                 dis[pointno[Edge[id][i].ed]]=dis[id]+Edge[id][i].money;
    567                 q.push(Node(pointno[Edge[id][i].ed],dis[pointno[Edge[id][i].ed]]));
    568                 pre[pointno[Edge[id][i].ed]]=pss(Edge[id][i].beg,Edge[id][i].no);
    569                 
    570             }
    571         }
    572     }
    573     roar.clear();
    574     for(int i=end;i!=beg;i=pointno[pre[i].first]) roar.push_back(pre[i].second);//路径存入全局vector roar中 
    575     
    576     return dis[end];//最少费用直接返回 
    577 }
    578 /*
    579 int dfs(int s,int t,int bt)
    580 {
    581     //cout<<s<<' '<<t<<endl;
    582     int temp_ans=inf;
    583     if(s==t)
    584     {
    585         if(bt<ans)
    586         T.clear();
    587         return bt;
    588     }
    589     for(int j=0;j<Edge[s].size();j++)
    590     {
    591         if(!vis[s][j]&&Edge[s][j].beg_tim>=bt)
    592         {
    593             vis[s][j]=1;
    594             int temp=dfs(pointno[Edge[s][j].beg],pointno[Edge[s][j].ed],Edge[s][j].end_tim);
    595             temp_ans=min(temp_ans,temp);
    596             if(temp<ans)
    597             {
    598                 T.push_back(Edge[s][j].no);
    599                 ans=temp;
    600             }
    601         }
    602         
    603     }
    604     //return temp_ans;
    605     return temp_ans;
    606 }
    607 int min_time(string s,string t)//最小时间 
    608 {
    609     int beg=pointno[s],end=pointno[t];
    610     ans=inf;
    611     int ans=inf;
    612     for(int i=0;i<Edge[beg].size();i++)
    613     {
    614         memset(vis,0,sizeof(vis));
    615         int temp=dfs(pointno[Edge[beg][i].ed],end,Edge[beg][i].end_tim)-Edge[beg][i].beg_tim;
    616 //        cout<<temp<<' '<<Edge[beg][i].beg_tim<<endl; 
    617         if(ans>temp)
    618         {
    619             ans=temp;
    620             roar.swap(T);//释放多余空间 
    621         }
    622     }
    623     return ans;
    624 }
    625 */
    626 int min_trans(string s,string t)//最少中转次数 
    627 {
    628     int beg=pointno[s],end=pointno[t];
    629     memset(dis,inf,sizeof(dis));
    630     while(!q.empty()) q.pop();
    631     dis[beg]=0;
    632     q.push(Node(beg,0));
    633     while(!q.empty())
    634     {
    635         Node S=q.top();
    636         q.pop();
    637         int id=S.id;
    638         if(dis[id]!=S.w) continue;
    639         for(int i=0;i<Edge[id].size();i++)
    640         {
    641             if(dis[pointno[Edge[id][i].ed]]>dis[id]+1&&!Edge[id][i].flag)
    642             {
    643                 dis[pointno[Edge[id][i].ed]]=dis[id]+1;
    644                 q.push(Node(pointno[Edge[id][i].ed],dis[pointno[Edge[id][i].ed]]));
    645                 pre[pointno[Edge[id][i].ed]]=pss(Edge[id][i].beg,Edge[id][i].no);//记录前面一条边的信息 
    646                 
    647             }
    648         }
    649     }
    650     roar.clear();//清空 
    651     for(int i=end;i!=beg;i=pointno[pre[i].first]) roar.push_back(pre[i].second);//路径存入全局vector roar中 
    652     
    653     return dis[end]-1;//最少中转直接返回 
    654 }
    655 
    656 
    657 void show_all()//显示所有的信息 
    658 {
    659     fstream file;
    660     file.open("line.txt",ios::in);
    661     transfor edge;
    662     int t1,t2;
    663     while(file>>edge.typp>>edge.no>>edge.beg>>edge.ed>>edge.beg_tim>>edge.end_tim>>edge.tk>>edge.num>>edge.money>>edge.flag)
    664     { 
    665         ////////////////////////////////////////////////////////////////////
    666         if(!edge.flag)
    667         {
    668             cout<<edge.typp<<" "<<edge.no<<" "<<edge.beg<<""<<edge.ed<<" 额定票数:"<<edge.tk<<" ";
    669             cout<<"已售票数:"<<edge.num<<" 价格:"<<edge.money<<""<<endl;
    670         }
    671         /////////////////////////////////////////////////////////////////////
    672     }
    673     file.close();
    674 }
    675 
    676 void ex_pre()//建图 
    677 {
    678     int no=1;
    679     for(auto i=point.begin();i!=point.end();i++,no++)//point里面是点 
    680     {
    681         pointno[(*i)]=no;
    682         Edge[no].clear();
    683         val[0][no].clear();
    684         val[1][no].clear(); 
    685     }
    686     for(int i=0;i<total.size();i++)
    687     {
    688         Edge[pointno[total[i].beg]].push_back(total[i]);//点映射 
    689         val[0][pointno[total[i].beg]].push_back(pii(total[i].money,pointno[total[i].ed]));
    690         val[1][pointno[total[i].beg]].push_back(pii(1,pointno[total[i].ed]));
    691     }
    692 }
    693 void IO_write()//把图写到txt里 
    694 {
    695     fstream file;
    696     file.open("line.txt",ios::out);
    697     string temp;
    698     for(int i=1;i<size;i++)//离散化后从1开始 
    699     {
    700         for(int j=0;j<Edge[i].size();j++)
    701         {
    702             file<<Edge[i][j].typp<<' '<<Edge[i][j].no<<' '<<Edge[i][j].beg<<' '<<Edge[i][j].ed<<' '<<Edge[i][j].beg_tim<<' '<<Edge[i][j].end_tim<<' '<<Edge[i][j].tk<<' '<<Edge[i][j].num<<' '<<Edge[i][j].money<<' '<<Edge[i][j].flag<<endl;
    703         }
    704     }
    705     file.close();
    706 }
    707 
    708 void IO_read()//从文件中拿出来 
    709 {
    710     fstream file;
    711     file.open("line.txt",ios::in);
    712     transfor edge;
    713     while(file>>edge.typp>>edge.no>>edge.beg>>edge.ed>>edge.beg_tim>>edge.end_tim>>edge.tk>>edge.num>>edge.money>>edge.flag)
    714     { 
    715         point.insert(edge.beg);
    716         point.insert(edge.ed);
    717         total.push_back(edge);
    718     }
    719     file.close();
    720 }
    View Code
  • 相关阅读:
    Convert string to hex « Python recipes « ActiveState Code
    分享:301定向技术全面解决
    UTF8 ANSI Unicode/UCS2 UCS4 所占存储比较_高山流水_百度空间
    分享:Arcadia 0.12.1 发布,Ruby 集成开发环境
    分享:探索 Python、机器学习和 NLTK 库
    Windows Codepage: 936 (Simplified Chinese GBK)
    分享:QT 5.0 正式版发布,支持 C++11
    分享:探索 Python、机器学习和 NLTK 库
    分享:Gearmand 1.0.2 和 1.1.4 发布,作业调度系统
    Convert string to hex « Python recipes « ActiveState Code
  • 原文地址:https://www.cnblogs.com/csushl/p/10281121.html
Copyright © 2020-2023  润新知