全國交通咨詢模擬系統(tǒng)源代碼_第1頁
全國交通咨詢模擬系統(tǒng)源代碼_第2頁
全國交通咨詢模擬系統(tǒng)源代碼_第3頁
全國交通咨詢模擬系統(tǒng)源代碼_第4頁
全國交通咨詢模擬系統(tǒng)源代碼_第5頁
已閱讀5頁,還剩50頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、12050741班(郭曉湛,李佳豪,廖川,楊鶴)課題:全國交通系統(tǒng)咨詢模擬源程序代碼:#include <windows.h>#include <stdio.h>#include <string.h>#include <vector>#include<iostream>#include <malloc.h>#define INF 65535 /定義一個最大數定為無窮值#define MAX 23using namespace std;static int c_number=10;static int k=0;statici

2、nt v=0,z=0,r=0,t=0;typedef struct searchint c_transer;int c_cost;int c_time;int f_cost;int f_time;search;search m20,x20,n20;typedef int costAdjMAX+1MAX+1;/圖鄰接矩陣從1開始記數int PathMAX+1MAX+1;/圖鄰接矩陣從1開始記數typedef struct unDiGraphint numVerts; /結點costAdj cost; /鄰接矩陣unDiGraph,*UNG; /圖的定義typedef struct c_edit

3、char a10;c_edit;c_edit add10;costAdj B,L;/定位函數,輸出城市列表,增添城市。int pr(int i,int j)int h=0; if (j=0) h=i; else if (j=1) cin>>addi.a; switch(h)/運用switch語句。 case(0):cout<<""break; case(1) : cout<<"成都 "break; case(2) : cout<<"西安 "break; case(3) : cout<

4、;<"鄭州 "break; case(4) : cout<<"武漢 "break; case(5) : cout<<"株洲 "break; case(6) : cout<<"貴陽 "break; case(7) : cout<<"柳州 "break; case(8) : cout<<"廣州 "break; case(9) : cout<<"南寧 "break; case(10)

5、: cout<<"徐州 "break; default: cout<<addi-10.a;return 1;/輸出城市列表及相應代碼void pri()int i;cout<<" 城市及其代碼"<<endl<<endl<<endl; cout<<"*"<<endl; for (i=1;i<=c_number;i+) cout<<i<<"." pr(i,0);cout<<endl&

6、lt;<"*"<<endl<<endl<<endl<<endl<<endl<<endl;/構造帶權(費用)圖 返回首地址G:unDiGraph *CreateCostG(int o)/火車的花費的存貯和編輯功能unDiGraph *G;int i,j;int a=0,b=0,f,h=1;if(!(G=(unDiGraph *)malloc(sizeof(unDiGraph) /為G分配存儲空間。return(NULL);for(i=1;i<c_number+1;i+)for(j=1;j<

7、;c_number+1;j+)G->costij=INF; /初始化使G->costij為無窮。G->numVerts=c_number;G->cost12=G->cost21=112;G->cost16=G->cost61=190;G->cost23=G->cost32=136;G->cost25=G->cost52=325;G->cost34=G->cost43=142;G->cost35=G->cost53=230;G->cost36=G->cost63=213;G->cost47

8、=G->cost74=247;G->cost48=G->cost84=250;G->cost57=G->cost75=161;G->cost59=G->cost95=208;G->cost510=G->cost105=261;G->cost68=G->cost86=317;G->cost78=G->cost87=208;G->cost810=G->cost108=367;G->cost910=G->cost109=444;if (o) while(h=1) v=v+1; pri(); cout

9、<<"火車花費編輯"<<endl; cout<<"請輸入開始城市的代碼"<<endl; cin>>a; cout<<"請輸入結尾城市的代碼"<<endl; cin>>b; cout<<"請輸入你的兩地花費"<<endl; cin>>mv.c_cost; nv.c_cost=a; xv.c_cost=b; cout<<"請選擇:"<<endl;

10、 cout<<"*"<<endl; cout<<"1:繼續(xù)更改城市費用"<<endl; cout<<"0:返回上一級菜單"<<endl; cout<<"*"<<endl; cin>>h; switch(h) case 1:h=1;break; case 0:h=0;break; default: cout<<"選擇出錯"<<endl; f=v+1; while (v

11、-) G->costnv.c_costxv.c_cost=mv.c_cost; v=f;return(G);/構造帶權(時間)圖 返回首地址G:unDiGraph *CreateTimeG(int o)/火車的時間的存貯和編輯功能unDiGraph *G;int i,j; int a=0,b=0,f,h=1;if(!(G=(unDiGraph *)malloc(sizeof(unDiGraph) /為G分配存儲空間。return(NULL);for(i=1;i<c_number+1;i+)for(j=1;j<c_number+1;j+)G->costij=INF;/初始

12、化使G->costij為無窮。G->numVerts=c_number;G->cost12=G->cost21=15;G->cost16=G->cost61=16;G->cost23=G->cost32=6;G->cost25=G->cost52=20;G->cost34=G->cost43=6;G->cost35=G->cost53=9;G->cost36=G->cost63=24;G->cost47=G->cost74=13;G->cost48=G->cost84=14;

13、G->cost57=G->cost75=8;G->cost59=G->cost95=12;G->cost510=G->cost105=17;G->cost68=G->cost86=23;G->cost78=G->cost87=13;G->cost810=G->cost108=20;G->cost910=G->cost109=33; if (o) while(h=1) z=z+1; pri(); cout<<"火車時間編輯"<<endl; cout<<&qu

14、ot;請輸入開始城市的代碼"<<endl; cin>>a; cout<<"請輸入結尾城市的代碼"<<endl; cin>>b; cout<<"請輸入你的兩地時間"<<endl; cin>>mz.c_time; nz.c_time=a; xz.c_time=b; cout<<"請選擇:"<<endl; cout<<"*"<<endl; cout<<&qu

15、ot;1:繼續(xù)更改城市時間"<<endl; cout<<"0:返回上一級菜單"<<endl; cout<<"*"<<endl; cin>>h; switch(h) case 1: system("cls");h=1;break; case 0: system("cls");h=0;break; default: cout<<"選擇出錯"<<endl; f=z+1; while (z-) G-

16、>costnz.c_timexz.c_time=mz.c_time; z=f;return(G);unDiGraph *CreatetranserG(int o)/火車中轉次數的存貯和編輯功能unDiGraph *G;int i,j;int a=0,b=0,f,h=1;if(!(G=(unDiGraph *)malloc(sizeof(unDiGraph) /為G分配存儲空間。return(NULL);for(i=1;i<c_number+1;i+)for(j=1;j<c_number+1;j+)G->costij=INF; /初始化使G->costij為無窮。G

17、->numVerts=c_number;G->cost12=G->cost21=1;G->cost16=G->cost61=1;G->cost23=G->cost32=1;G->cost25=G->cost52=1;G->cost34=G->cost43=1;G->cost35=G->cost53=1;G->cost36=G->cost63=1;G->cost47=G->cost74=1;G->cost48=G->cost84=1;G->cost57=G->cost75

18、=1;G->cost59=G->cost95=1;G->cost510=G->cost105=1;G->cost68=G->cost86=1;G->cost78=G->cost87=1;G->cost810=G->cost108=1;G->cost910=G->cost109=1;if (o) while(h=1) r=r+1; pri(); cout<<"中轉次數編輯"<<endl; cout<<"請輸入開始城市的代碼"<<endl;

19、 cin>>a; cout<<"請輸入結尾城市的代碼"<<endl; cin>>b; cout<<"請輸入你的中轉次數"<<endl; cin>>mr.c_transer; nr.c_transer=a; xr.c_transer=b; cout<<"請選擇"<<endl; cout<<"*"<<endl; cout<<"1:繼續(xù)更改城市費用"<&

20、lt;endl; cout<<"0:返回上一級菜單"<<endl; cout<<"*"<<endl; cin>>h; switch(h) case 1:h=1;break; case 0:h=0;break; default: cout<<"選擇出錯"<<endl; f=v+1; while (v-) G->costnv.c_transerxv.c_transer=mv.c_transer; v=f;return(G);unDiGraph *Cr

21、eateTimeF(int o)/飛機的時間的存貯和編輯功能unDiGraph *G;int i,j; int a=0,b=0,f,h=1;if(!(G=(unDiGraph *)malloc(sizeof(unDiGraph) /為G分配存儲空間。return(NULL);for(i=1;i<c_number+1;i+)for(j=1;j<c_number+1;j+)G->costij=INF;/初始化使G->costij為無窮。G->numVerts=c_number;G->cost12=G->cost21=2;G->cost16=G->

22、;cost61=1;G->cost23=G->cost32=1;G->cost34=G->cost43=2;G->cost45=G->cost54=4;G->cost56=G->cost65=3;G->cost57=G->cost75=6;G->cost58=G->cost85=6;G->cost67=G->cost76=6;G->cost79=G->cost97=2;G->cost311=G->cost113=6;G->cost1112=G->cost1211=1;G-&g

23、t;cost1210=G->cost1012=2;G->cost310=G->cost103=3;G->cost1310=G->cost1013=6;G->cost135=G->cost513=1; if (o) while(h=1) t=t+1; pri(); cout<<"飛機時間編輯"<<endl; cout<<"請輸入開始城市的代碼"<<endl; cin>>a; cout<<"請輸入結尾城市的代碼"<<

24、;endl; cin>>b; cout<<"請輸入你的兩地時間"<<endl; cin>>mt.f_time; nt.f_time=a; xt.f_time=b; cout<<"請選擇:"<<endl; cout<<"*"<<endl; cout<<"1:繼續(xù)更改城市時間"<<endl; cout<<"0:返回上一級菜單"<<endl; cout<

25、<"*"<<endl; cin>>h; switch(h) case 1:h=1;break; case 0:h=0;break; default: cout<<"選擇出錯"<<endl; f=t+1; while (t-) G->costnt.f_timext.f_time=mt.f_time; t=f;return(G);unDiGraph *CreateCostF(int o)/飛機花費的存貯和編輯功能unDiGraph *G;int i,j;int a=0,b=0,f,h=1;if(!(

26、G=(unDiGraph *)malloc(sizeof(unDiGraph) /為G分配存儲空間。return(NULL);for(i=1;i<c_number+1;i+)for(j=1;j<c_number+1;j+)G->costij=INF; /初始化使G->costij為無窮。G->numVerts=c_number;G->cost26=G->cost62=960;G->cost12=G->cost21=840;G->cost23=G->cost32=501;G->cost34=G->cost43=530;

27、G->cost45=G->cost54=400;G->cost56=G->cost65=900;G->cost58=G->cost85=670;G->cost57=G->cost75=670;G->cost67=G->cost76=600;G->cost79=G->cost97=200;G->cost311=G->cost113=690;G->cost1112=G->cost1211=310;G->cost1210=G->cost1012=670;G->cost310=G->

28、cost103=340;G->cost1310=G->cost1013=650;G->cost135=G->cost513=1180;if (o) while(h=1) r=r+1; pri(); cout<<"飛機花費編輯"<<endl; cout<<"請輸入開始城市的代碼"<<endl; cin>>a; cout<<"請輸入結尾城市的代碼"<<endl; cin>>b; cout<<"請輸入

29、你的兩地花費"<<endl; cin>>mr.f_cost; nr.f_cost=a; xr.f_cost=b; cout<<"請選擇:"<<endl; cout<<"*"<<endl; cout<<"1:繼續(xù)更改城市費用"<<endl; cout<<"0:返回上一級菜單"<<endl; cout<<"*"<<endl; cin>>

30、h; switch(h) case 1:h=1;break; case 0:h=0;break; default: cout<<"選擇出錯"<<endl; f=r+1; while (r-) G->costnr.f_costxr.f_cost=mr.f_cost; r=f;return(G); /Floyed函數 求任意兩點的最短路徑:void Floyed(unDiGraph *D,unDiGraph *M)int i,j,k,n;costAdj A,C;n=c_number; for(i=1;i<=n;i+) for(j=1;j<

31、;=n;j+) Aij=D->costij;/初始化矩陣A。Cij=M->costij; Pathij=-1; /初始化矩陣p, 置-1. for(k=1;k<=n;k+) /k為逐步加入的中間結點 for(i=1;i<=n;i+) /i為A中行號 for(j=1;j<=n;j+) if(Aik+Akj<Aij) Aij=Aik+Akj;Cij=Cik+Ckj; Pathij=k;/若i經過k到j比i到j小,則令Aij=Aik+Akj。 Bij=Aij; Lij=Cij; else Bij=Aij;Lij=Cij; /end-for cout<<

32、"n最短路徑為: "<<endl;/end-Floyed/為了求從i到j的最短路徑,只需要調用如下的過程:void prn_pass(int i,int j)if(Pathij!=-1) prn_pass(i,Pathij);/輸出最短路徑經過的所有點 pr(Pathij,0);/求最少時間路徑。void time()int Bcity,Ecity;/起始成市號碼和終點城市號碼 int l,h=1; do pri();/輸出城市列表及相應代碼。 cout<<"請輸入起始城市和目的城市的代碼,中間以空格隔開,范圍(1- "<&

33、lt;c_number<<")" cin>>Bcity; cin>>Ecity;/輸入起始城市和終點城市的代碼。 if (!(0<Bcity&&Bcity<c_number+1)&&(0<Ecity&&Ecity<c_number+1)&&Bcity!=Ecity) cout<<"n出錯啦! 輸入城市號碼請在1-"<<c_number<<"之間,且兩城市不能相等!"<&l

34、t;endl; Floyed(CreateTimeG(0),CreateCostG(0);/調用Floyed函數。 pr(Bcity,0);/ 顯示起始城市。 prn_pass(Bcity,Ecity);/調用prn_pass函數,顯示最短路徑經過的城市。 pr(Ecity,0);/顯示終點城市。 if (BBcityEcity>5000|LBcityEcity>10000) cout<<"兩地間還沒有線路通過"<<endl; else cout<<"火車花的錢是"<<LBcityEcity&l

35、t;<"元"<<endl; cout<<"火車花的時間是"<<BBcityEcity<<"小時"<<endl; printf("nn 1.繼續(xù)最少花費查找n 2.返回主菜單n 請選擇:"); scanf("%d",&l); /輸入1或2選擇是否繼續(xù)。 h=l; while(h=1); printf("n");void transer() int Bcity,Ecity;/起始成市號碼和終點城市號碼 in

36、t l,h=1; do pri();/輸出城市列表及相應代碼。 cout<<"請輸入起始城市和目的城市的代碼,中間以空格隔開,范圍(1- "<<c_number<<")" cin>>Bcity; cin>>Ecity;/輸入起始城市和終點城市的代碼。 if (!(0<Bcity&&Bcity<c_number+1)&&(0<Ecity&&Ecity<c_number+1)&&Bcity!=Ecity) cou

37、t<<"n出錯啦! 輸入城市號碼請在1-"<<c_number<<"之間,且兩城市不能相等!"<<endl; Floyed(CreateCostG(0),CreatetranserG(0);/調用Floyed函數。 pr(Bcity,0);/ 顯示起始城市。 prn_pass(Bcity,Ecity);/調用prn_pass函數,顯示最短路徑經過的城市。 pr(Ecity,0);/顯示終點城市。 if (BBcityEcity>5000|LBcityEcity>10000) cout<&l

38、t;"兩地間還沒有線路通過"<<endl; else cout<<"最少中轉次數是"<<LBcityEcity-1<<"次"<<endl; cout<<"火車總票價是"<<BBcityEcity<<"元"<<endl; printf("nn 1.繼續(xù)最少花費查找n 2.返回主菜單n 請選擇:"); scanf("%d",&l); /輸入1或2

39、選擇是否繼續(xù)。 h=l; while(h=1); printf("n");void c_transer() int Bcity,Ecity;/起始成市號碼和終點城市號碼 int l,h=1; do pri();/輸出城市列表及相應代碼。 cout<<"請輸入起始城市和目的城市的代碼,中間以空格隔開,范圍(1- "<<c_number<<")" cin>>Bcity; cin>>Ecity;/輸入起始城市和終點城市的代碼。 if (!(0<Bcity&&B

40、city<c_number+1)&&(0<Ecity&&Ecity<c_number+1)&&Bcity!=Ecity) cout<<"n出錯啦! "<<endl; Floyed(CreateTimeF(0),CreatetranserG(0);/調用Floyed函數。 pr(Bcity,0);/ 顯示起始城市。 prn_pass(Bcity,Ecity);/調用prn_pass函數,顯示最短路徑經過的城市。 pr(Ecity,0);/顯示終點城市。 if (BBcityEcity&g

41、t;5000|LBcityEcity>10000) cout<<"兩地間還沒有線路通過"<<endl; else cout<<"火車花的錢是"<<LBcityEcity<<"元"<<endl; cout<<"最少中轉次數是"<<BBcityEcity<<"次"<<endl; printf("nn 1.繼續(xù)最少中轉查找n 2.返回主菜單n 請選擇:");

42、 scanf("%d",&l); /輸入1或2選擇是否繼續(xù)。 h=l; while(h=1); printf("n");void f_time()int Bcity,Ecity;/起始成市號碼和終點城市號碼 int l,h=1; do pri();/輸出城市列表及相應代碼。 cout<<"請輸入起始城市和目的城市的代碼,中間以空格隔開,范圍(1- "<<c_number<<")" cin>>Bcity; cin>>Ecity;/輸入起始城市和終點城

43、市的代碼。 if (!(0<Bcity&&Bcity<c_number+1)&&(0<Ecity&&Ecity<c_number+1)&&Bcity!=Ecity) cout<<"n出錯啦! "<<endl; Floyed(CreateTimeF(0),CreateCostF(0);/調用Floyed函數。 pr(Bcity,0);/ 顯示起始城市。 prn_pass(Bcity,Ecity);/調用prn_pass函數,顯示最短路徑經過的城市。 pr(Ecity

44、,0);/顯示終點城市。 if (BBcityEcity>5000|LBcityEcity>10000) cout<<"兩地間還沒有線路通過"<<endl; else cout<<"飛機花的錢是"<<LBcityEcity<<"元"<<endl; cout<<"飛機花的時間是"<<BBcityEcity<<"小時"<<endl; printf("nn 1.

45、繼續(xù)最少花費查找n 2.返回主菜單n 請選擇:"); scanf("%d",&l); /輸入1或2選擇是否繼續(xù)。 h=l; while(h=1); printf("n");/求最少花費路徑。void money() int Bcity,Ecity;/起始成市號碼和終點城市號碼 char l,h=1;/*unDiGraph *G;*/ do pri();/輸出城市列表及相應代碼。 cout<<"請輸入起始城市和目的城市的代碼,中間以空格隔開,范圍(1- "<<c_number<<&q

46、uot;)" cin>>Bcity;cin>>Ecity;/輸入起始城市和終點城市的代碼。if (!(0<Bcity&&Bcity<c_number+1)&&(0<Ecity&&Ecity<c_number+1)&&Bcity!=Ecity) cout<<"n出錯啦! "<<endl; /輸入出錯 Floyed(CreateCostG(0),CreateTimeG(0);/調用Floyed函數。pr(Bcity,0);/顯示起始城

47、市。prn_pass(Bcity,Ecity);/調用prn_pass函數,顯示最短路徑經過的城市。pr(Ecity,0);/顯示終點城市。if (BBcityEcity>5000|LBcityEcity>10000) cout<<"兩地間還沒有線路通過"<<endl;else cout<<"火車花的錢是"<<BBcityEcity<<"元"<<endl; cout<<"火車花的時間"<<LBcityEcit

48、y<<"小時"<<endl; printf("nn 1.繼續(xù)最少花費查找n 2.返回主菜單n 請選擇:"); scanf("%d",&l); /輸入1或2選擇是否繼續(xù)。 h=l; while(h=1); printf("n");/求飛機的情況void f_money()cout<<"1"<<endl;int Bcity,Ecity;/起始成市號碼和終點城市號碼 char l,h=1;/*unDiGraph *G;*/ do cout<

49、<"2"<<endl; pri();/輸出城市列表及相應代碼。 cout<<"請輸入起始城市和目的城市的代碼,中間以空格隔開,范圍(1- "<<c_number<<")" cin>>Bcity;cin>>Ecity;/輸入起始城市和終點城市的代碼。if (!(0<Bcity&&Bcity<c_number+1)&&(0<Ecity&&Ecity<c_number+1)&&Bcity!=Ecity) cout<<"n出錯啦! "<<endl; /輸入出錯Floyed(CreateCostF(0),CreateTimeF(0);/調用Floyed函數。pr(Bcity,0);/顯示起始城市。prn_pass(Bcity,Ecity);/調用prn_pass函數,顯示最短路徑經過的城市。pr(Ecity,0);/顯示終點城市。if (BBcityEcity>5000|LBcityEcity>10000) cout<<&

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論