全国交通咨询模拟系统源代码.doc_第1页
全国交通咨询模拟系统源代码.doc_第2页
全国交通咨询模拟系统源代码.doc_第3页
全国交通咨询模拟系统源代码.doc_第4页
全国交通咨询模拟系统源代码.doc_第5页
已阅读5页,还剩50页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

.12050741班(郭晓湛,李佳豪,廖川,杨鹤)课题:全国交通系统咨询模拟源程序代码:#include #include #include #include #include#include #define INF 65535 /定义一个最大数定为无穷值#define MAX 23using namespace std;static int c_number=10;static int k=0;staticint 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 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) cinaddi.a; switch(h)/运用switch语句。 case(0):cout;break; case(1) : cout成都 ;break; case(2) : cout西安 ;break; case(3) : cout郑州 ;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) : cout徐州 ;break; default: coutaddi-10.a;return 1;/输出城市列表及相应代码void pri()int i;cout 城市及其代码endlendlendl; cout*endl; for (i=1;i=c_number;i+) couti.; pr(i,0);coutendl*endlendlendlendlendlendl;/构造带权(费用)图 返回首地址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;ic_number+1;i+)for(j=1;jcostij=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=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火车花费编辑endl; cout请输入开始城市的代码a; cout请输入结尾城市的代码b; cout请输入你的两地花费mv.c_cost; nv.c_cost=a; xv.c_cost=b; cout请选择:endl; cout*endl; cout1:继续更改城市费用endl; cout0:返回上一级菜单endl; cout*h; switch(h) case 1:h=1;break; case 0:h=0;break; default: cout选择出错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;ic_number+1;i+)for(j=1;jcostij=INF;/初始化使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;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请输入开始城市的代码a; cout请输入结尾城市的代码b; cout请输入你的两地时间mz.c_time; nz.c_time=a; xz.c_time=b; cout请选择:endl; cout*endl; cout1:继续更改城市时间endl; cout0:返回上一级菜单endl; cout*h; switch(h) case 1: system(cls);h=1;break; case 0: system(cls);h=0;break; default: cout选择出错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;ic_number+1;i+)for(j=1;jcostij=INF; /初始化使G-costij为无穷。G-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=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请输入开始城市的代码a; cout请输入结尾城市的代码b; cout请输入你的中转次数mr.c_transer; nr.c_transer=a; xr.c_transer=b; cout请选择endl; cout*endl; cout1:继续更改城市费用endl; cout0:返回上一级菜单endl; cout*h; switch(h) case 1:h=1;break; case 0:h=0;break; default: cout选择出错costnv.c_transerxv.c_transer=mv.c_transer; v=f;return(G);unDiGraph *CreateTimeF(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;ic_number+1;i+)for(j=1;jcostij=INF;/初始化使G-costij为无穷。G-numVerts=c_number;G-cost12=G-cost21=2;G-cost16=G-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-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请输入开始城市的代码a; cout请输入结尾城市的代码b; cout请输入你的两地时间mt.f_time; nt.f_time=a; xt.f_time=b; cout请选择:endl; cout*endl; cout1:继续更改城市时间endl; cout0:返回上一级菜单endl; cout*h; switch(h) case 1:h=1;break; case 0:h=0;break; default: cout选择出错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(!(G=(unDiGraph *)malloc(sizeof(unDiGraph) /为G分配存储空间。return(NULL);for(i=1;ic_number+1;i+)for(j=1;jcostij=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;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-cost103=340;G-cost1310=G-cost1013=650;G-cost135=G-cost513=1180;if (o) while(h=1) r=r+1; pri(); cout飞机花费编辑endl; cout请输入开始城市的代码a; cout请输入结尾城市的代码b; cout请输入你的两地花费mr.f_cost; nr.f_cost=a; xr.f_cost=b; cout请选择:endl; cout*endl; cout1:继续更改城市费用endl; cout0:返回上一级菜单endl; cout*h; switch(h) case 1:h=1;break; case 0:h=0;break; default: cout选择出错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;jcostij;/初始化矩阵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+AkjAij) 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 coutn最短路径为: 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- c_numberBcity; cinEcity;/输入起始城市和终点城市的代码。 if (!(0Bcity&Bcityc_number+1)&(0Ecity&Ecityc_number+1)&Bcity!=Ecity) coutn出错啦! 输入城市号码请在1-c_number之间,且两城市不能相等!5000|LBcityEcity10000) cout两地间还没有线路通过endl; else cout火车花的钱是LBcityEcity元endl; cout火车花的时间是BBcityEcity小时endl; printf(nn 1.继续最少花费查找n 2.返回主菜单n 请选择:); scanf(%d,&l); /输入1或2选择是否继续。 h=l; while(h=1); printf(n);void transer() int Bcity,Ecity;/起始成市号码和终点城市号码 int l,h=1; do pri();/输出城市列表及相应代码。 cout请输入起始城市和目的城市的代码,中间以空格隔开,范围(1- c_numberBcity; cinEcity;/输入起始城市和终点城市的代码。 if (!(0Bcity&Bcityc_number+1)&(0Ecity&Ecityc_number+1)&Bcity!=Ecity) coutn出错啦! 输入城市号码请在1-c_number之间,且两城市不能相等!5000|LBcityEcity10000) cout两地间还没有线路通过endl; else cout最少中转次数是LBcityEcity-1次endl; cout火车总票价是BBcityEcity元endl; printf(nn 1.继续最少花费查找n 2.返回主菜单n 请选择:); scanf(%d,&l); /输入1或2选择是否继续。 h=l; while(h=1); printf(n);void c_transer() int Bcity,Ecity;/起始成市号码和终点城市号码 int l,h=1; do pri();/输出城市列表及相应代码。 cout请输入起始城市和目的城市的代码,中间以空格隔开,范围(1- c_numberBcity; cinEcity;/输入起始城市和终点城市的代码。 if (!(0Bcity&Bcityc_number+1)&(0Ecity&Ecityc_number+1)&Bcity!=Ecity) coutn出错啦! 5000|LBcityEcity10000) cout两地间还没有线路通过endl; else cout火车花的钱是LBcityEcity元endl; cout最少中转次数是BBcityEcity次endl; printf(nn 1.继续最少中转查找n 2.返回主菜单n 请选择:); scanf(%d,&l); /输入1或2选择是否继续。 h=l; while(h=1); printf(n);void f_time()int Bcity,Ecity;/起始成市号码和终点城市号码 int l,h=1; do pri();/输出城市列表及相应代码。 cout请输入起始城市和目的城市的代码,中间以空格隔开,范围(1- c_numberBcity; cinEcity;/输入起始城市和终点城市的代码。 if (!(0Bcity&Bcityc_number+1)&(0Ecity&Ecityc_number+1)&Bcity!=Ecity) coutn出错啦! 5000|LBcityEcity10000) cout两地间还没有线路通过endl; else cout飞机花的钱是LBcityEcity元endl; cout飞机花的时间是BBcityEcity小时endl; printf(nn 1.继续最少花费查找n 2.返回主菜单n 请选择:); scanf(%d,&l); /输入1或2选择是否继续。 h=l; while(h=1); printf(n);/求最少花费路径。void money() int Bcity,Ecity;/起始成市号码和终点城市号码 char l,h=1;/*unDiGraph *G;*/ do pri();/输出城市列表及相应代码。 cout请输入起始城市和目的城市的代码,中间以空格隔开,范围(1- c_numberBcity;cinEcity;/输入起始城市和终点城市的代码。if (!(0Bcity&Bcityc_number+1)&(0Ecity&Ecityc_number+1)&Bcity!=Ecity) coutn出错啦! 5000|LBcityEcity10000) cout两地间还没有线路通过endl;else cout火车花的钱是BBcityEcity元endl; cout火车花的时间LBcityEcity小时endl; printf(nn 1.继续最少花费查找n 2.返回主菜单n 请选择:); scanf(%d,&l); /输入1或2选择是否继续。 h=l; while(h=1); printf(n);/求飞机的情况void f_money()cout1endl;int Bcity,Ecity;/起始成市号码和终点城市号码 char l,h=1;/*unDiGraph *G;*/ do cout2endl; pri();/输出城市列表及相应代码。 cout请输入起始城市和目的城市的代码,中间以空格隔开,范围(1- c_numberBcity;cinEcity;/输入起始城市和终点城市的代码。if (!(0Bcity&Bcityc_number+1)&(0Ecity&Ecityc_number+1)&Bcity!=Ecity) coutn出错啦! 5000|LBcityEcity10000) cout两地间还没有线路通过e

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论