




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、12050741班(郭晓湛,李佳豪,廖川,杨鹤)课题:全国交通系统咨询模拟源程序代码:#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:继续更改城市费用"<<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:继续更改城市时间"<<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:继续更改城市费用"<&
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:继续更改城市时间"<<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:继续更改城市费用"<<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.继续最少花费查找n 2.返回主菜单n 请选择:"); scanf("%d",&l); /输入1或2选择是否继续。 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.继续最少花费查找n 2.返回主菜单n 请选择:"); scanf("%d",&l); /输入1或2
39、选择是否继续。 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.继续最少中转查找n 2.返回主菜单n 请选择:");
42、 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_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、继续最少花费查找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_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.继续最少花费查找n 2.返回主菜单n 请选择:"); scanf("%d",&l); /输入1或2选择是否继续。 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. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 航天器空间机器人与自动化技术考核试卷
- 自行车租赁市场政策支持研究考核试卷
- 出版业的协同创新考核试卷
- 花画艺术在健身房墙面装饰的动力考核试卷
- 通信设备更新考核试卷
- 渔业资源遥感监测与评估技术研发与应用考核试卷
- 体育产品质量控制考核试卷
- 运输设备材料性能与应用考核试卷
- 航空运动飞行器载荷与应力分析考核试卷
- 远程医疗服务感染管理培训计划
- 2025年人教版小学一年级下学期奥林匹克数学竞赛试题(附答案解析)
- 2024年广东省普宁市事业单位公开招聘警务岗笔试题带答案
- 《社会保险知识普及教学课件》
- 2025委托维修服务合同模板
- 延安通和电业有限责任公司招聘笔试真题2024
- 上海市松江区2024-2025学年七年级下学期期中数学试卷
- (2025)保密观题库及答案
- 统编版2024-2025第二学期小学六年级期末语文测试卷(有答案)
- 中华人民共和国民营经济促进法
- 2025年田径三级裁判试题及答案
- 保安证考试新手必看试题及2025年答案
评论
0/150
提交评论