資源簡介
數據結構課程設計大作業,交通咨詢模擬。1.出于不同目的的旅客對交通工具有不同的要求。例如,因公出差的旅客希望在旅途中的時間盡可能短,出門旅游的旅客則期望旅費盡可能省,而老年旅客則要求中轉次數最少。編制一個全國城市間的交通咨詢程序,為旅客提供兩種或三種最優決策的交通咨詢。
2.基本要求
(1)提供對城市信息進行編輯(如:添加或刪除)的功能。
(2)城市之間有兩種交通工具:火車和飛機。提供對列車時刻表和飛機航班進行編輯(增設或刪除)的功能。
(3)提供兩種最優決策:最快到達或最省錢到達。全程只考慮一種交通工具。
(4)旅途中耗費的總時間應該包括中轉站的等候時間。
(5)咨詢以用戶和計算機的對話方式進行。由用戶輸入起始站、終點站、最優決策原則和交通工具,輸出信息:最快需要多長時間才能到達或者最少需要多少旅費才能到達,并詳細說明依次于何時乘坐哪一躺列車或哪一次班機到何地。

代碼片段和文件信息
#include
#include
using?namespace?std;
#define?Maxn?500
class?graph{
public:
????mapid;
????string?place[Maxn];
????int?tot=0;
????struct?point{
????????int?numdis;
????????int?nowtime;
????????bool?operator<(const?point?&b)const{
????????return?this->dis ????????bool?operator>(const?point?&b)const{
????????return?this->dis>b.dis;}
????};
????struct?line{
????????string?BeginEnd;
????????string?number;
????????int?sted;
????????int?begintimeendtime;
????????int?disprice;
????????int?change(string?s)
????????{
????????????int?res=((s[0]-‘0‘)*10+(s[1]-‘0‘))*60;
????????????res+=((s[3]-‘0‘)*10+(s[4]-‘0‘));
????????????return?res;
????????}
????????line()
????????{
????????????Begin=““;End=““;number=““;
????????????st=ed=begintime=endtime=price=0;
????????}
????????line(string?numstring?astring?bstring?cstring?dint?sint?tint?p)
????????{
????????????number=num;Begin=a;End=b;
????????????begintime=change(c);endtime=change(d);
????????????st=s;ed=t;
????????????price=p;
????????}
????????void?showtime(int?t)
????????{
????????????printf(“%02d:%02d“t/60t%60);
????????}
????????void?print()
????????{
????????????cout< ????????????showtime(begintime);cout<<“?“;showtime(endtime);cout<<“?“;
????????????cout< ????????}
????};//邊的各種信息,構造函數
????vectorair[Maxn];
????vectortrain[Maxn];
????graph()
????{
????????tot=0;
????????id.clear();
????????for(int?i=0;i ????????for(int?i=0;i ????}//初始化
????int?passtime(int?xint?ybool?f)
????{
????????if(f)return?0;
????????x=x%1440;
????????y=y%1440;
????????return?(y-x+1440)%1440;
????}
????int?length(line?kint?typepoint?intempint?stint?dis)
????{
????????if(type==1)//求時間最短
????????{
????????????return?passtime(k.begintimek.endtime0)+passtime(disk.begintimest==intemp.num);
????????}
????????if(type==2)//求花費最短
????????{
????????????return?k.price;
????????}
????????if(type==3)//求中轉最短
????????{
????????????return?1;
????????}
????}
????void?printpath(int?stint?vline?path[])
????{
????????if(v==st)return?;
????????printpath(stpath[v].stpath);
????????path[v].print();
????}//打印路徑
????void?showshow(int?Time)
????{
????????int?h=Time/60m=Time%60;
????????printf(“%d小時%d分“hm);
????}//修改時間格式
????void?shortpath(int?stint?edvector?edge[]int?type)
????{
????????bool?mark[Maxn];
????????int?dis[Maxn];
????????line?path[Maxn];
????????const?int?inf=2000000;
????????int?iv;
????????point?intemp{st00}newtemp;
????????for(i=1;i<=tot;i++)
????????{
????????????mark[i]=false;
????????????dis[i]=inf;
????????}
????????dis[st]=0;
????????priority_queuegreater?>Q;
????????Q.push(intemp);
????????mark[st]=true;
????????while(!Q.empty())
????????{
????????????intemp=Q.top();
????????????Q.pop();
??????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????11791??2016-12-30?01:29??main.cpp
?????文件???????13235??2016-12-22?19:35??shuju.txt
?????文件???????85618??2017-11-10?12:10??全國交通咨詢模擬.docx
- 上一篇:采集軟件 .net 采集插件
- 下一篇:計算機網絡課程設計實驗報告
評論
共有 條評論