全国交通咨询模拟 数据结构 源代码
交通图咨询查询系统数据结构(C语言)

信息科学与工程学院《结构数据》课程设计报告课程设计名称:交通咨询系统专业班级 : 计算机xxx学生姓名 : xxx学号: 2015xxxx指导教师 : xx课程设计时间:2016。
07.04—2016.07.08计算机应用技术专业课程设计任务书说明:本表由指导教师填写,由教研室主任审核后下达给选题学生,装订在设计(论文)首页填表说明1.“课题性质”一栏:A.工程设计;B.工程技术研究;C.软件工程(如CAI课题等);D.文献型综述;E.其它。
2.“课题来源"一栏:A.自然科学基金与部、省、市级以上科研课题;B.企、事业单位委托课题;C.校、院(系、部)级基金课题;D.自拟课题。
目录1 需求分析 01。
1 添加交通图信息 01。
2 查询单源最短路径 01。
3 查询多源最短路径 01。
4 更新交通图信息 01.6 读取、保存信息 (1)2 概要设计 (2)2.1 数据类型的定义 (2)2.2 功能模块结构图 (3)3 运行环境 (6)4 开发工具和编程语言 (6)5 详细设计 (7)5。
1 图结构的基本操作 (7)5。
1。
1添加城市结点和路径结点 (8)5。
1.2修改城市结点和路径结点 (8)5.1。
3删除城市结点和路径结点 (8)5。
1。
4退出保存 (8)5。
2 迪杰斯特拉算法的实现 (8)5.2。
1 迪杰斯特拉算法函数 (8)5.2.2 提取迪杰斯特拉函数信息 (8)5.2。
3 求多源最短路径 (8)6 程序编码 (9)7 运行结果 (39)8 心得体会 (45)9参考文献 (46)1需求分析本系统中的数据来源于标准输入设备(如键盘)和文件,可以实现对交通图城市、城市到其余城市的距离的操作,根据需要可查询某两个城市之间的最短距离、城市到各城市的最短距离,各个城市到各个城市的最短距离,以及路径。
本系统要实现的功能有:添加城市和城市间距离,删除城市及城市间距离,修改城市间距离,查询城市间的最短路径,查询某个城市到某个城市的最短路径。
全国交通咨询模拟分解

数据结构课程设计报告实验题目:5组+全国交通咨询模拟班级:191132-04姓名:薛福兴学号:20131000447指导老师:郭艳完成日期:2015年07月5组+ 全国交通模拟咨询系统 (3)1、需求分析 (3)1.1、解决问题: (3)1.2、程序的功能: (3)1.3、输入和输出的形式: (3)2.设计 (4)2.1 设计思想 (4)2.2 设计表示 (5)2.3 详细设计 (5)3.调试分析 (10)4.用户手册 (10)5.测试数据及测试结果 (10)6.参考文献 (14)7.总结 (14)8.检查过后对程序的修改(07.25) (15)5组+ 全国交通模拟咨询系统1、需求分析1.1、解决问题:城市之间有两种交通工具:火车和飞机。
出于不同目的的旅客对交通工具有不同的要求。
例如,因公出差的旅客希望在旅途中的时间尽可能短,出门旅游的游客则期望旅费尽可能省。
编制一个全国城市间的交通咨询程序,为旅客提供两种最优决策的交通咨询。
1.2、程序的功能:①读取城市信息文件并在程序运行时动态加载到内存;提供对城市信息进行编辑(如添加或删除)的功能。
②读取列车时刻表和飞机航班表并在程序运行时动态加载到内存;提供对列车时刻表和飞机航班表进行编辑(增设或删除)的功能。
③用户输入城市起点和终点,以及决策选项(最快到达或最省钱到达)后,系统针对用户所选的决策策略提供城市起点到城市终点间的所有不重复的可行方案(按照最优到最差的顺序排序输出)。
全程只考虑一种交通工具。
数据结构设计应尽可能快地实现查询和排序。
④旅途中耗费的总时间应该包括中转站的等候时间。
⑤咨询以用户和计算机的对话方式进行。
1.3、输入和输出的形式:①功能:模拟全国交通咨询系统对费用或运行时间的最佳方案进行排序。
②数据流入:将站台、铁路线的信息通过读取文件的方式进行对图的建立。
③数据流出:在退出程序时对修改过的文件进行保存。
④程序流程图:资源管理器流程图如图2.设计2.1 设计思想一、数据与操作的特性① 数据特性分析 在本项目共包含2大类。
交通规划——多路径分配计算机程序代码

FORM1Private Sub Command1_Click()Form1.HideForm2.ShowEnd SubFORM2Private Sub Command1_Click()a = 4.2b = 3.93c = 1.96Text1(0).Text = aText1(1).Text = aText1(2).Text = cText1(3).Text = cText1(4).Text = aText1(5).Text = aText2(0).Text = aText2(1).Text = aText2(2).Text = aText2(3).Text = aText2(4).Text = bText2(5).Text = bEnd SubPrivate Sub Command2_Click()d = 50Text3.Text = dEnd SubPrivate Sub Command3_Click()Text4(0).Text = Text1(0) / Text3 * 60 Text4(1).Text = Text1(1) / Text3 * 60 Text4(2).Text = Text1(2) / Text3 * 60 Text4(3).Text = Text1(3) / Text3 * 60 Text4(4).Text = Text1(4) / Text3 * 60 Text4(5).Text = Text1(5) / Text3 * 60 Text5(0).Text = Text2(0) / Text3 * 60 Text5(1).Text = Text2(1) / Text3 * 60 Text5(2).Text = Text2(4) / Text3 * 60 Text5(3).Text = Text2(5) / Text3 * 60 Text5(4).Text = Text2(2) / Text3 * 60Text5(5).Text = Text2(3) / Text3 * 60 End SubPrivate Sub Command4_Click()e = 600Text6 = eEnd SubPrivate Sub Command5_Click()Text7(1).Text = 200Text7(2).Text = 200Text7(3).Text = 500Text7(4).Text = 200Text7(6).Text = 500Text7(7).Text = 100Text7(8).Text = 200Text7(9).Text = 500Text7(11).Text = 250Text7(12).Text = 500Text7(13).Text = 100Text7(14).Text = 250End SubPrivate Sub Command6_Click()Form2.HideForm3.ShowEnd SubPrivate Sub Form_Load()End SubFORM3Public i, jPrivate Sub Command3_Click()Form3.HideForm2.ShowEnd SubPrivate Sub Command4_Click()Form3.HideForm4.ShowEnd SubPrivate Sub Form_Load()i = 0j = 0End SubPrivate Sub Command2_Click()i = i + 1If i = 1 ThenCommand2.Caption = "分配A—B后的交通量" Command1.Caption = "求分配A—B后的阻抗"Text3(0).Text = 155Text3(1).Text = 0Text3(2).Text = 168Text3(3).Text = 0Text3(4).Text = 0Text3(5).Text = 45Text3(6).Text = 13Text3(7).Text = 0Text3(8).Text = 32Text3(9).Text = 0Text3(10).Text = 45Text3(11).Text = 0Text3(12).Text = 32Text3(13).Text = 0Text3(14).Text = 0Text3(15).Text = 0Text3(16).Text = 0Text3(17).Text = 0Text3(18).Text = 0Text3(19).Text = 0Text3(20).Text = 0Text3(21).Text = 0Text3(22).Text = 0Text3(23).Text = 0ElseIf i = 2 ThenCommand2.Caption = "分配B—A后的交通量" Command1.Caption = "求分配B—A后的阻抗"Text3(0).Text = 155Text3(2).Text = 168Text3(3).Text = 155Text3(4).Text = 32Text3(5).Text = 45Text3(6).Text = 26Text3(7).Text = 0Text3(8).Text = 32Text3(9).Text = 45Text3(10).Text = 45Text3(11).Text = 32Text3(12).Text = 32Text3(13).Text = 45Text3(14).Text = 0Text3(15).Text = 0Text3(16).Text = 0Text3(17).Text = 0Text3(18).Text = 0Text3(19).Text = 0Text3(20).Text = 0Text3(21).Text = 0Text3(22).Text = 0Text3(23).Text = 0ElseIf i = 3 ThenCommand2.Caption = "分配A—C后的交通量" Command1.Caption = "求分配A—C后的阻抗"Text3(0).Text = 155Text3(1).Text = 168Text3(2).Text = 168Text3(3).Text = 155Text3(4).Text = 32Text3(5).Text = 245Text3(6).Text = 26Text3(7).Text = 0Text3(8).Text = 32Text3(9).Text = 45Text3(10).Text = 45Text3(11).Text = 32Text3(12).Text = 32Text3(13).Text = 45Text3(14).Text = 0Text3(15).Text = 200Text3(17).Text = 0Text3(18).Text = 0Text3(19).Text = 0Text3(20).Text = 0Text3(21).Text = 0Text3(22).Text = 0Text3(23).Text = 0ElseIf i = 4 ThenCommand2.Caption = "分配C—A后的交通量" Command1.Caption = "求分配C—A后的阻抗"Text3(0).Text = 155Text3(1).Text = 168Text3(2).Text = 168Text3(3).Text = 155Text3(4).Text = 232Text3(5).Text = 245Text3(6).Text = 26Text3(7).Text = 0Text3(8).Text = 32Text3(9).Text = 45Text3(10).Text = 45Text3(11).Text = 32Text3(12).Text = 32Text3(13).Text = 45Text3(14).Text = 200Text3(15).Text = 200Text3(16).Text = 0Text3(17).Text = 0Text3(18).Text = 0Text3(19).Text = 0Text3(20).Text = 0Text3(21).Text = 0Text3(22).Text = 0Text3(23).Text = 0ElseIf i = 5 ThenCommand2.Caption = "分配A—D后的交通量" Command1.Caption = "求分配A—D后的阻抗"Text3(0).Text = 345Text3(1).Text = 168Text3(3).Text = 155Text3(4).Text = 232Text3(5).Text = 555Text3(6).Text = 26Text3(7).Text = 128Text3(8).Text = 32Text3(9).Text = 107Text3(10).Text = 355Text3(11).Text = 32Text3(12).Text = 344Text3(13).Text = 45Text3(14).Text = 200Text3(15).Text = 200Text3(16).Text = 0Text3(17).Text = 126Text3(18).Text = 0Text3(19).Text = 374Text3(20).Text = 0Text3(21).Text = 0Text3(22).Text = 126Text3(23).Text = 0ElseIf i = 6 ThenCommand2.Caption = "分配D—A后的交通量" Command1.Caption = "求分配D—A后的阻抗"Text3(0).Text = 345Text3(1).Text = 294Text3(2).Text = 230Text3(3).Text = 155Text3(4).Text = 232Text3(5).Text = 555Text3(6).Text = 152Text3(7).Text = 128Text3(8).Text = 32Text3(9).Text = 107Text3(10).Text = 355Text3(11).Text = 344Text3(12).Text = 344Text3(13).Text = 354Text3(14).Text = 262Text3(15).Text = 200Text3(17).Text = 126Text3(18).Text = 309Text3(19).Text = 374Text3(20).Text = 0Text3(21).Text = 62Text3(22).Text = 126Text3(23).Text = 191ElseIf i = 7 ThenCommand2.Caption = "分配C—B后的交通量" Command1.Caption = "求分配C—B后的阻抗"Text3(0).Text = 345Text3(1).Text = 294Text3(2).Text = 357Text3(3).Text = 155Text3(4).Text = 232Text3(5).Text = 555Text3(6).Text = 279Text3(7).Text = 128Text3(8).Text = 405Text3(9).Text = 107Text3(10).Text = 663Text3(11).Text = 344Text3(12).Text = 655Text3(13).Text = 354Text3(14).Text = 570Text3(15).Text = 200Text3(16).Text = 259Text3(17).Text = 126Text3(18).Text = 371Text3(19).Text = 374Text3(20).Text = 192Text3(21).Text = 62Text3(22).Text = 188Text3(23).Text = 191ElseIf i = 8 ThenCommand2.Caption = "分配B—C后的交通量" Command1.Caption = "求分配B—C后的阻抗"Text3(0).Text = 345Text3(1).Text = 351Text3(3).Text = 346Text3(4).Text = 608Text3(5).Text = 612Text3(6).Text = 279Text3(7).Text = 262Text3(8).Text = 405Text3(9).Text = 416Text3(10).Text = 663Text3(11).Text = 658Text3(12).Text = 655Text3(13).Text = 663Text3(14).Text = 570Text3(15).Text = 571Text3(16).Text = 259Text3(17).Text = 255Text3(18).Text = 371Text3(19).Text = 374Text3(20).Text = 192Text3(21).Text = 191Text3(22).Text = 188Text3(23).Text = 191ElseIf i = 9 ThenCommand2.Caption = "分配B—D后的交通量" Command1.Caption = "求分配B—D后的阻抗"Text3(0).Text = 345Text3(1).Text = 351Text3(2).Text = 357Text3(3).Text = 346Text3(4).Text = 608Text3(5).Text = 612Text3(6).Text = 279Text3(7).Text = 262Text3(8).Text = 405Text3(9).Text = 516Text3(10).Text = 663Text3(11).Text = 658Text3(12).Text = 655Text3(13).Text = 663Text3(14).Text = 570Text3(15).Text = 571Text3(16).Text = 259Text3(18).Text = 371Text3(19).Text = 474Text3(20).Text = 192Text3(21).Text = 191Text3(22).Text = 188Text3(23).Text = 191ElseIf i = 10 ThenCommand2.Caption = "分配D—B后的交通量" Command1.Caption = "求分配D—B后的阻抗"Text3(0).Text = 345Text3(1).Text = 351Text3(2).Text = 357Text3(3).Text = 346Text3(4).Text = 608Text3(5).Text = 612Text3(6).Text = 279Text3(7).Text = 262Text3(8).Text = 505Text3(9).Text = 516Text3(10).Text = 663Text3(11).Text = 658Text3(12).Text = 655Text3(13).Text = 663Text3(14).Text = 570Text3(15).Text = 571Text3(16).Text = 259Text3(17).Text = 255Text3(18).Text = 471Text3(19).Text = 474Text3(20).Text = 192Text3(21).Text = 191Text3(22).Text = 188Text3(23).Text = 191ElseIf i = 11 ThenCommand2.Caption = "分配D—C后的交通量" Command1.Caption = "求分配D—C后的阻抗"Text3(0).Text = 345Text3(1).Text = 351Text3(2).Text = 357Text3(4).Text = 608Text3(5).Text = 612Text3(6).Text = 279Text3(7).Text = 262Text3(8).Text = 505Text3(9).Text = 516Text3(10).Text = 663Text3(11).Text = 658Text3(12).Text = 655Text3(13).Text = 663Text3(14).Text = 570Text3(15).Text = 571Text3(16).Text = 259Text3(17).Text = 255Text3(18).Text = 471Text3(19).Text = 474Text3(20).Text = 192Text3(21).Text = 441Text3(22).Text = 188Text3(23).Text = 441ElseIf i = 12 ThenCommand2.Caption = "分配C—D后的交通量" Command1.Caption = "分配C—D后的阻抗"Text3(0).Text = 345Text3(1).Text = 351Text3(2).Text = 357Text3(3).Text = 346Text3(4).Text = 608Text3(5).Text = 612Text3(6).Text = 279Text3(7).Text = 262Text3(8).Text = 505Text3(9).Text = 516Text3(10).Text = 663Text3(11).Text = 658Text3(12).Text = 655Text3(13).Text = 663Text3(14).Text = 570Text3(15).Text = 571Text3(16).Text = 259Text3(17).Text = 255Text3(18).Text = 471Text3(19).Text = 474Text3(20).Text = 442Text3(21).Text = 441Text3(22).Text = 438Text3(23).Text = 441Form3.ShowForm2.HideEnd IfEnd SubPrivate Sub Command1_Click()Dim a(3) As StringText1(0).Text = Form2.Text4(0)Text1(1).Text = Form2.Text4(1)Text1(2).Text = Form2.Text4(2)Text1(3).Text = Form2.Text4(3)Text1(4).Text = Form2.Text4(4)Text1(5).Text = Form2.Text4(5)Text2(0).Text = Form2.Text5(0)Text2(1).Text = Form2.Text5(1)Text2(2).Text = Form2.Text5(2)Text2(3).Text = Form2.Text5(3)Text2(4).Text = Form2.Text5(4)Text2(5).Text = Form2.Text5(5)j = j + 1If j = 1 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据初始阻抗求分配A—B后的交通量"ElseIf j = 2 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配A—B后的阻抗求分配A—C后交通量" Command1.Caption = "分配A—B后的阻抗"ElseIf j = 3 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配A—C后的阻抗求分配A—D后交通量" Command1.Caption = "分配A—C后的阻抗"ElseIf j = 4 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配A—D后的阻抗求分配B—A后交通量" Command1.Caption = "分配A—D后的阻抗"ElseIf j = 5 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配B—A后的阻抗分配B—C后交通量" Command1.Caption = "分配B—A后的阻抗"ElseIf j = 6 Then((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配B—C后的阻抗求分配B—D后交通量" Command1.Caption = "分配B—C后的阻抗"ElseIf j = 7 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 *Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配B—D后的阻抗求分配C—A后交通量" Command1.Caption = "分配B—D后的阻抗"ElseIf j = 8 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配C—A后的阻抗求分配C—B后交通量" Command1.Caption = "分配C—A后的阻抗"ElseIf j = 9 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 *Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配C—B后的阻抗求分配C—D后交通量" Command1.Caption = "分配C—B后的阻抗"ElseIf j = 10 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配C—D后的阻抗求分配D—A后交通量" Command1.Caption = "分配C—D后的阻抗"ElseIf j = 11 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配D—A后的阻抗求分配D—B后交通量" Command1.Caption = "分配D—A后的阻抗"ElseIf j = 12 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 * ((Val(Text3(6).Text) + Val(Text3(7).Text)) / 600) ^ 4), 3)Text2(3).Text = Round(Val(Text2(3).Text) * (1 + 0.15 * ((Val(Text3(16).Text) + Val(Text3(17).Text)) / 600) ^ 4), 3)Text2(4).Text = Round(Val(Text2(4).Text) * (1 + 0.15 * ((Val(Text3(8).Text) + Val(Text3(9).Text)) / 600) ^ 4), 3)Text2(5).Text = Round(Val(Text2(5).Text) * (1 + 0.15 * ((Val(Text3(18).Text) + Val(Text3(19).Text)) / 600) ^ 4), 3) Command2.Caption = "根据分配D—B后的阻抗求分配D—C后交通量" Command1.Caption = "分配D—B后的阻抗"ElseIf j = 13 ThenText1(0).Text = Round(Val(Text1(0).Text) * (1 + 0.15 * ((Val(Text3(0).Text) + Val(Text3(1).Text)) / 600) ^ 4), 3)Text1(1).Text = Round(Val(Text1(1).Text) * (1 + 0.15 * ((Val(Text3(2).Text) + Val(Text3(3).Text)) / 600) ^ 4), 3)Text1(2).Text = Round(Val(Text1(2).Text) * (1 + 0.15 * ((Val(Text3(10).Text) + Val(Text3(11).Text)) / 600) ^ 4), 3)Text1(3).Text = Round(Val(Text1(3).Text) * (1 + 0.15 * ((Val(Text3(12).Text) + Val(Text3(13).Text)) / 600) ^ 4), 3)Text1(4).Text = Round(Val(Text1(4).Text) * (1 + 0.15 * ((Val(Text3(20).Text) + Val(Text3(21).Text)) / 600) ^ 4), 3)Text1(5).Text = Round(Val(Text1(5).Text) * (1 + 0.15 * ((Val(Text3(22).Text) + Val(Text3(23).Text)) / 600) ^ 4), 3)Text2(0).Text = Round(Val(Text2(0).Text) * (1 + 0.15 * ((Val(Text3(4).Text) + Val(Text3(5).Text)) / 600) ^ 4), 3)Text2(1).Text = Round(Val(Text2(1).Text) * (1 + 0.15 * ((Val(Text3(14).Text) + Val(Text3(15).Text)) / 600) ^ 4), 3)Text2(2).Text = Round(Val(Text2(2).Text) * (1 + 0.15 *。
数据结构课程设计报告--交通咨询系统

数据结构设计报告姓名:专业:指导教师:目录摘要 (3)第1章概述 (4)1.1系统实现的目标 (4)1.2系统实现方案 (4)1.3系统实现环境 (4)1.4具体的开发方法 (4)第2章系统设计 (5)2.1系统功能设计 (5)2.2数据设计 (5)2.3界面的设计 (5)第3章系统实现 (9)参考文献 (15)摘要设计、实现一个全国大城市间的交通咨询程序,为旅客提供三种最优决策方案:一是建立交通网络图的存储结构,二实现两个城市间的最短路经问题。
程序所具有的功能特色本程序主要目的是为了给用户提供路径咨询。
实现了帮助用户了解全国各大城市间往来的最短路径问题,第二,可以提供用户查询各大城市的相关信息。
本程序最大的特点是支持用户自己添加城市信息及城市,或添加城市的路径,既就有可扩展性该程序所做的工作的是模拟全国交通咨询,为旅客提供三种最优决策的交通咨询。
此程序规定:(1)在程序中输入城市名称时,需输入10个字母以内的字母串;输入列车或飞机编号时需输入一个整型数据;输入列车或飞机的费用时需输入一个实型数据;输入列车或飞机开始时间和到达时间时均需输入两个整型数据(以hh:mm的形式);在选择功能时,应输入与所选功能对应的一个整型数据。
(2)程序的输出信息主要是:最快需要多少时间才能到达,或最少需要多少旅费才能到达,或最少需要多少次中转到达,并详细说明依次于何时乘坐哪一趟列车或哪一次班机到何地。
(3)程序的功能包括:提供对城市信息的编辑,提供列车时刻表和飞机航班表的编辑,提供三种最优决策:最快到达、最省钱到达、最少中转次数到达。
第1章概述1.1 系统实现的目标通过进行课程设计,了解并初步掌握设计、实现较大系统的完整过程,包括:系统分析、编码设计、系统集成、以及调试分析,熟练掌握数据结构的选择、设计、实现以及操作方法,为进一步的应用开发打好基础。
应用所学数据结构知识,独立完成问题分析,结合数据结构理论知识,编写程序求解指定问题。
数据结构公交线路提示代码实现含源代码

typedef struct ArcCell {
VRType adj; //顶点关系类型 }ArcCell,AdjMatrix[MAX_STATION][MAX_STATION];
公交线路提示 (图) [问题描述] 上网下载南京公交线路图,建立南京主要公交线路图的存储结构。 [基本要求] (1)输入任意两站点,给出转车次数最少的乘车路线。 (2)输入任意两站点,给出经过站点最少的乘车路线。 8.2 数据结构 typedef int VRType; typedef int Status; typedef struct Station {
2 / 22
找两点是否存在相同车辆线路,如有,则输出直达车辆,并通过对链 表的查找计算出经过的站数;之后用迪杰斯特拉算法求两点之间的最 短路径, 在对路径上的点,从头开始,两两之间比较经过的站点,如果有相同 的车辆,则继续,遇到没有相同的时候,进行转车操作,循环往复直 到到达终点。 迪杰斯特拉算法: (1)将由 v 出发到图上各点可能到达的最短路径长度设初值为 arcs 的值。 (2)选择 vj 使得 D[j]=Min{D[i]|vi 属于 V-S}
typedef struct
1 / 22
{ Station vex[MAX_STATION];//顶点向量 AdjMatrix arcs; //邻结矩阵 int vexnum; // 图当前的顶点数
}MGraph;
typedef struct LNode3 { // 车站站点
char station[20]; struct LNode3 *next; }LNode3,*LinkList3;
交通运输-数据结构实训全国交通咨询模拟 精品

学生实训报告实训名称:数据结构实训指导教师:姓名:学号:班级:日期:一、实训项目项目名称:全国交通咨询模拟二、实训的目的1.熟悉图数据结构;2.掌握图的顺序存储结构—邻接表;3.掌握最短路径算法4.上机调试程序,掌握查错、排错使程序能正确运行。
三.实训要求1.每个人独立完成实训项目,相互之间可以交流,不能抄袭2.实训的成果包括程序代码和报告3.程序代码要有注释和说明三、实验的环境:1.硬件环境: PC机2.软件环环境:Windows2000 +Visual C++6四、算法描述:建立图的数据结构,采用邻接矩阵作为其存储结构。
存储以上的全国主要城市的交通信息。
通过软件模拟的方法实现:给定出发点和终点,求出它们之间的最短路径,并给出最短路径的线路。
五、源程序清单:#include <stdio.h>#include<string.h>#define VEX_NUM 26#define MAXINT 1000000typedef struct graph{char city[VEX_NUM][10];int arcs[VEX_NUM][VEX_NUM];}Mgraph;void CreatGraph(Mgraph *G,int e);void Dijkstra(Mgraph *Gn, int v0,int path[],int dist[]);void PutPath(Mgraph *g,int v0,int v1,int p[],int d[]);int index(char s[],Mgraph *g);void main(){Mgraph *g;int i;int e;int v0,v1;char sr[10],dt[10];int dist[VEX_NUM];int path[VEX_NUM];g=new Mgraph;CreatGraph(g,30);printf("输入出发城市和终点城市\n");getchar();gets(sr);v0=index(sr,g);gets(dt);v1=index(dt,g);Dijkstra(g,v0,path,dist);PutPath(g,v0,v1,path,dist);}void CreatGraph(Mgraph *G,int e){int i,j,k,cost;printf("输入城市名称\n");for(i=0;i<VEX_NUM;++i)scanf("%s",G->city[i]);for(i=0;i<VEX_NUM;i++)for(j=0;j<VEX_NUM;j++)G->arcs[i][j]=MAXINT;printf("输入城市之间的距离\n");for(k=0;k<e;k++){scanf("%d,%d,%d",&i,&j,&cost);G->arcs[i][j]=cost;G->arcs[j][i]=cost;}}void Dijkstra(Mgraph *Gn, int v0,int path[],int dist[]) {int s[VEX_NUM];int v;int w;int i,j,k;int min;for(v=0; v<VEX_NUM; v++){s[v]=0;dist[v]=Gn->arcs[v0][v];if(dist[v]<MAXINT)path[v]=v0;else path[v]=-1;}dist[v0]=0;s[v0]=1;for(i=1;i<VEX_NUM -1;i++){min=MAXINT;for(w=0;w<VEX_NUM;w++)if(!s[w] && dist[w]<min){v=w;min=dist[w];}s[v]=1;for(j=0;j<VEX_NUM;j++)if(!s[j] && (min+Gn->arcs[v][j]<dist[j])){dist[j]=min+Gn->arcs[v][j];path[j]=v;}}}void PutPath(Mgraph *g,int v0,int v1,int p[],int d[]) {int k;int next;int top=0;int st[20];if(d[v1]<MAXINT && v1!=v0){st[top++]=v1;next=p[v1];while(next!=v0){st[top++]=next;next=p[next];}}elseif(v1!=v0){printf("%s->%s:没有路径\n",g->city[v0],g->city[v1]);return;}st[top++]=v0;while(top){next=st[--top];if(top!=0)printf("%s->",g->city[next]);elseprintf("%s\n",g->city[next]);}printf("两个城市之间的最短距离为:%d\n",d[v1]);}int index(char s[],Mgraph *g){int i;for(i=0;i<VEX_NUM;i++)if(strcmp(s,g->city[i])==0)return i;}六、运行结果:七、实验运行情况分析(包括算法、运行结果、运行环境等问题的讨论)。
交通咨询系统 C语言
CHINA交通咨询系统目录一、需求分析 (2)1、程序的功能及设计要求 (2)2、输入输出的要求 (2)二、环境说明 (2)三、详细设计 (3)1、模块设计 (3)2、画出各函数的调用关系图、主要函数的流程图。
(3)2、详细代码 (4)四、调试分析 (4)1、测试数据: (4)2、借鉴的资料 (5)五、课程总结 (6)六、附录 (6)一、需求分析1、程序的功能及设计要求在交通网络非常发达、交通工具和交通方式不断更新的今天,人们在出差、旅游或做其他出行时,不仅关心节省交通费用,而且对里程和所需时间等问题也感兴趣。
对于这样一个人们关心的问题,通过建立交通网络图的存储结构图,提供用户查询的功能,功能一:通过输入城市名及任意两个城市的距离,查询任意两个城市之间的最短距离,从而达到最省目的;功能二:通过输入城市名以及任意两个程序的距离,查询中转路线最少。
程序所具有的功能特色本程序主要目的是为了给用户提供路径咨询,可以通过输入设置,延续程序的拓展性。
设计要求及分析设计一个交通咨询系统,能让旅客咨询从任一个城市顶点到另一城市顶点之间的中转次数最少问题或最低花费或最少时间(最短路径)问题。
该设计共分三个部分:一是建立交通网络图的存储结构;二是解决单源最短路径问题;最后再实现任意两个城市顶点之间的最短路径问题。
1. 建立交通网络图的存储结构要实现设计要求,首先要定义交通图的存储结构:邻接链表和邻接矩阵;2. 解决任意两个城市顶点之间的中转次数最少的问题;3. 解决任意两个城市顶点之间的最短路径(最低花费或最少时间)问题。
2、输入输出的要求定义变量类型应该保持类型一致,通过键盘输入,确保输入输出一致,使最短路径途径以及最短路径能够简单明了的输出,同时保持程序简洁美观,效果明显。
输入要求为输入界面直观、亲切;有利于快速输入;有利于准确输入;有利于输入、修改;方便操作。
输出要求:输出要求应简单、直观,一目了然,尽量符合用户的习惯,便于用户阅读、理解与使用。
数据结构课设-订票系统源代码
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>#define maxrailway 100#define maxorder 1000typedef struct Time{int month; //月int day; //日int hour; //小时int minute; //分钟}Time, *Ptime;typedef struct Railway{char Num[15]; //列车号char corp[15]; //铁路公司名称char rail[15]; //列车车型char from[15]; //始发站点char to[15]; //终点站Ptime takeoff; //发车时间Ptime arrive; //到站时间int price; //票价float discount; //折扣,小于100大于0的浮点数int vaculmn; //乘客容量int rest; //剩余座位数struct Railway *next;}Railway, *Pst_Rail;typedef struct Order{char Num[15]; //列车号char cusname[20]; //乘客姓名char IDcardnum[20];//乘客身份证号int ticketnum; //订票总数int num; //订单编号struct Order *next;}Order, *Pst_Order;FILE *data, *order; //分别保存列车线路记录和订单记录Pst_Rail head_rail; //列车链表表头Pst_Order head_order; //订单链表表头int flag; //退出操作的标记int numofrail; //记录列车线路数目int numoforder; //记录订单数目int lastorder; //记录最后一个订单的序号void pause(){int t, now_time;now_time = clock(); //取出当前时间for(;(t = (clock() - now_time)) < 2 * (CLOCKS_PER_SEC););system("cls"); //在pause()函数中放一个清屏函数}//时钟程序,用来控制用户界面的输出,每两个界面中间暂停2秒钟void Inuput(){int i;Pst_Rail p, q;p = head_rail;for(i = 0;i < numofrail;i++)p = p->next;q = (Pst_Rail)malloc(sizeof(Railway));q->takeoff = (Ptime)malloc(sizeof(Time));q->arrive = (Ptime)malloc(sizeof(Time));p->next = q;// 为记录开辟空间printf("Please input Railway information:\n");printf("Number:\tCorparation:\tType of railway:\n");scanf("%s%s%s",q->Num,q->corp,q->rail);//输入列车线路的车号、铁路公司名称、列车车型printf("\nPassenger vaculmn:\tTake off position:\tArrive position:\n");scanf("%d%s%s",&q->vaculmn,q->from,q->to);//输入列车的乘客容量、始发、终点q->rest = q->vaculmn;//剩余的座位初始时为乘客容量printf("\nTake off time:\tArrive time:\tPrice:\tDiscount:\nTime e.g.:6/25 12:30\n");scanf("%d/%d %d:%d",&q->takeoff->month,&q->takeoff->day,&q->takeoff->hour,&q->takeof f->minute);scanf("%d/%d %d:%d",&q->arrive->month,&q->arrive->day,&q->arrive->hour,&q->arrive->m inute);//输入列车发车的时间和到站时间scanf("%d%f",&q->price,&q->discount);//输入车票价格和折扣numofrail += 1;}void File_Scanf_Data(){Pst_Rail p, q;p = head_rail;while(!feof(data)){q = (Pst_Rail)malloc(sizeof(Railway));q->takeoff = (Ptime)malloc(sizeof(Time));q->arrive = (Ptime)malloc(sizeof(Time)); // 为记录开辟空间fscanf(data,"%s%s%s",q->Num,q->corp,q->rail);fscanf(data,"%d%s%s",&q->vaculmn,q->from,q->to);fscanf(data,"%d/%d %d:%d",&q->takeoff->month,&q->takeoff->day,&q->takeoff->hour,&q->take off->minute);fscanf(data,"%d/%d %d:%d",&q->arrive->month,&q->arrive->day,&q->arrive->hour,&q->arrive-> minute);fscanf(data,"%d%f%\n",&q->price,&q->discount);q->next = NULL;numofrail += 1;p->next = q;p = p->next;} //从文件中读取列车线路记录}void File_Scanf_Order(){Pst_Order p, q;p = head_order;while(!feof(order)){q = (Pst_Order)malloc(sizeof(Order)); // 为记录开辟空间fscanf(order,"NO.%d: %s\t%s\t%d tickets for railway :%s\n",&q->num,q->cusname,q->IDcardnum,&q->ticketnum,q->Num);q->next = NULL;numofrail += 1;p->next = q;p = p->next;} //从文件中读取订单记录}void File_write(){Pst_Rail p;Pst_Order q;p = head_rail;q = head_order;while(p->next != NULL){p = p->next;fprintf(data,"%s %s %s\n",p->Num,p->corp,p->rail);fprintf(data,"%d %s %s\n",p->vaculmn,p->from,p->to);fprintf(data,"%d/%d %d:%d - ",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);fprintf(data,"%d/%d %d:%d",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->mi nute);fprintf(data,"%d %.2f%%\n",p->price,p->discount);}while(q->next!=NULL){q = q->next;fprintf(order,"NO.%d: %s\t%s\t%d tickets for railway :%s\n",q->num,q->cusname,q->IDcardnum,q->ticketnum,q->Num);}} //向文件中写入数据void Change_item(int n){int i, choose;Pst_Rail p;p = head_rail;for(i = 0;i < n;i++)p = p->next;printf("Which item do you want to change?\n");printf("0: Number\n1: Corparation\n2: Type of railway\n3: Passenger vaculmn\n\4: Take off position\n5: Arrive position\n6: Take off time\n7: Arrive time\n\8: Price\n9: Discount\n\n");scanf("%d",&choose);system("cls");switch(choose){case 0:{printf("The old Number is %s\nPlease input the new one:\n",p->Num);scanf("%s",p->Num);break;}//显示列车号并输入新的列车号case 1:{printf("The old Corparation is %s\nPlease input the new one:\n",p->corp);scanf("%s",p->corp);break;}//显示原铁路公司并输入新的公司名称case 2:{printf("The old Type of railway is %s\nPlease input the new one:\n",p->rail);scanf("%s",p->rail);break;}//显示原列车车型并输入新的车型case 3:{printf("The old Passenger vaculmn is %d\nPlease input the new one:\n",p->vaculmn);scanf("%d",&p->vaculmn);break;}//显示原乘客容量并输入新的容量case 4:{printf("The old Take off position is %s\nPlease input the new one:\n",p->from);scanf("%s",p->from);break;}//显示原列车始发站并输入新的站名case 5:{printf("The old Arrive position is %s\nPlease input the new one:\n",p->to);scanf("%s",p->to);break;}//显示原列车终点站并输入新的终点站case 6:{printf("The old Take off time is %d/%d %d:%d\nPlease input the new one:\n",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);scanf("%d/%d %d:%d",&p->takeoff->month,&p->takeoff->day,&p->takeoff->hour,&p->takeoff->m inute);break;}//显示原列车发车时间并输入新的时间case 7:{printf("The old Arrive time is %d/%d %d:%d\nPlease input the new one:\n",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minute);scanf("%d/%d %d:%d",&p->arrive->month,&p->arrive->day,&p->arrive->hour,&p->arrive->minute );break;}//显示原列车到站时间并输入新的时间case 8:{printf("The old Price is %d\nPlease input the new one:\n",p->price);scanf("%d",&p->price);break;}//显示原列车价格并输入新的价格case 9:{printf("The old Discount is %.2f%%\nPlease input the new one:\n",p->discount);scanf("%f",&p->discount);break;}//显示原车票折扣并输入新的折扣}} //由Change_main()函数调用,用来选择性地改变记录中的某一项void Change_main(){char change[15], e;Pst_Rail p, q;p = head_rail;q = head_rail;int i, flag_find;do{for(i = 0;i < numofrail;i++){p = p->next;if(p != NULL)break;}if(i == numofrail){printf("There is no railway information!\n");break;} //如果pa[]数组所有元素都为空指针则退出do...while()循环,并显示没有列车信息flag_find = 0;printf("Plese input the number of the railway you want to change:\n");scanf("%s",change);for(i = 0;i < numofrail;i++){q = q->next;if(strcmp(change,q->Num) == 0){flag_find = 1;break;}} //逐一匹配输入与数组指针指向的结构体的Num项,若相等则标记找到if(flag_find == 0){printf("No such railway exist!\n");printf("Do you want to try again?(Y/N)\n");do{scanf("%c",&e);}while(e == '\n');if(e == 'N') flag_find = 1;}system("cls");}while(flag_find == 0);do{system("cls");Change_item(i); //修改飞机线记录中的一项printf("Do you want to continue?(Y/N)\n");do{scanf("%c",&e);}while(e == '\n'); //排除%c输入时,回车号的干扰}while(e == 'Y');}//用来查找需要修改的记录,并调用Change_item()函数void Quiry_number(){char quiry[15], e;Pst_Rail p;p = head_rail;int i, flag_quiry_number;do{system("cls");printf("Please input the number of the railway:\n");flag_quiry_number = 0;scanf("\n%s",quiry); //输入需要查询的列车号for(i = 0;i < numofrail;i++){p = p->next;if(strcmp(quiry,p->Num) == 0){system("cls");printf("Number: %s\t",p->Num);printf("From: %s\tTo: %s\n",p->from,p->to);printf("Time: %d/%d %d:%d - ",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);printf("%d/%d %d:%d\n",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minut e);printf("Price: %d\tDiscount: %.2f\t",p->price,p->discount);if(p->rest != 0)printf("There are %d seats avaliable!\n", p->rest);else printf("NO seat avaliable!\n");flag_quiry_number = 1;break;} //匹配输入与记录的列车号,若相同则输出列车始发站、时间以及票价、折扣和是否满座的信息}if(!flag_quiry_number){printf("There is no such railway exist!\n");printf("Do you want to try again?(Y/N)\n");do{scanf("%c",&e);}while(e == '\n');if(e == 'N') flag_quiry_number = 1;}}while(!flag_quiry_number);system("pause");} // 按照列车号查询void Quiry_position(){char quiry[2][15];Pst_Rail p;p = head_rail;int i, j, flag_quiry_position;do{printf("Please input the takeoff and arrive position of the airline:\n");flag_quiry_position = 0;scanf("%s%s",quiry[0],quiry[1]); //输入需要查询的始发、终点站名for(i = 0;i < numofrail;i++){p = p->next;if((strcmp(quiry[0],p->from) == 0) && (strcmp(quiry[1],p->to) == 0)){pause();printf("Number: %s\t",p->Num);printf("From: %s\tTo: %s\n",p->from,p->to);printf("Time: %d/%d %d:%d - ",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);printf("%d/%d %d:%d\n",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minut e);printf("Price: %d\tDiscount: %.2f\n",p->price,p->discount);flag_quiry_position = 1;break;}//匹配输入与记录的地点,若相同则输出始发、终点站、时间以及票价、折扣和是否满座的信息}if(!flag_quiry_position) printf("\nThere is no such airline exist!Please input again!\n");}while(!flag_quiry_position);pause();} //按照始发、终点站地点查询void Quiry_main(){char choose; //选择按照列车号还是始发、终点站查询printf("Please choose the type of quiry:\n1: Number\t2: Take off and arrive position\n");do{do{scanf("%c",&choose);}while(choose == '\n'); //排除回车的干扰system("cls");if(choose == '1'){Quiry_number(); //选择1则调用Quiry_number()函数break;}else if(choose == '2'){Quiry_position(); //选择2则调用Quiry_position()函数break;}else printf("Wrong input number!Please input again!\n");}while(1);}//用来选择查询的方式,并调用Quiry_number();或Quiry_position();void Order_main(){char ord[15];char e1;Pst_Order q, tail;Pst_Rail p;p = head_rail;tail = head_order;int i, j, flag_order; //用来标记是否存在需要预订的列车号q = (Pst_Order)malloc(sizeof(Order));//开辟空间do{flag_order = 0;e1 = 'N';printf("Please input the number of the railway:\n");scanf("%s",ord); //输入需要查询的列车号for(i = 0;i < numofrail;i++){p = p->next;if(strcmp(ord,p->Num) == 0){if(p->rest!=0){flag_order = 1; //若存在该列车且还有座位则标记为1break;}else{printf("The railway has no seat avaliable!\n");for(j = 0;j < numofrail;j++){if((strcmp(p->from,p->from)==0)&&(strcmp(p->to,p->to)==0)){if((p->rest!=0)&&(i!=j)){printf("%s: from %s to %s\n",p->Num,p->from,p->to);flag_order = -1; //标记有其他相同始末地点的列车线路}else continue;}}if(flag_order == 0){printf("There is no other railway from %s to %s",p->from,p->to);flag_order = -1;break;}else break;}}}if(flag_order == 1){system("cls");printf("%s from %s to %s, %d yuan per ticket, %d tickets avaliable.\n",p->Num,p->from,p->to,p->price,p->rest);printf("\nPlease input you name,ID number,and the amount ticket you want!\ne.g.:罗璐璐0909090825 2\n");scanf("%s%s%d",q->cusname,q->IDcardnum,&q->ticketnum);q->num = lastorder;strcpy(q->Num,ord);for(i = 0;i < numoforder;i++)tail = tail->next;tail->next = q;p->rest -= q->ticketnum;//TODO: 如果此时正好不够要定的票数numoforder += 1;lastorder += 1;printf("\nYour order number is:%d,please remember it!\n",lastorder-1);pause();}//由于在后面删除订单后不能改变其他订单的号码故此处用最后一个订单的号码+1作为新订单的号码else if(flag_order == -1){printf("Do you want to choose again?(Y/N)");do{scanf("%c",&e1);}while(e1 == '\n');}//当列车号对应列车满员时,查找相同起降点的列车线路,不管存在与否均重新输入订单号elseprintf("There is no such railway exist!Please input again!\n");//若列车号不存在则提示没有该列车号}while((flag_order == 0) || (e1 == 'Y'));}//预订车票void Cancel_order(){char e;int i, j, order, flag_cancel_order;Pst_Order q, change;q = head_order;change = q;flag_cancel_order = 0;printf("Please input the number of your order:\n");scanf("%d",&order); //吃掉回车for(i = 0;i < numoforder;i++){q = q->next;if(order == q->num){flag_cancel_order = 1;break;}}if(flag_cancel_order){printf("Are you sure?(Y/N)\n");do{scanf("%c",&e);}while(e == '\n'); //防止误删if(e == 'Y'){for(i = 0;i < numoforder-1;i++){change = change->next;}change->next = q->next;free(q);numoforder -= 1;pause();printf("Order cacelled!\n");}}else{printf("The is no such order number!\n");printf("Do you want to try again?(Y/N)\n");do{scanf("%c",&e);}while(e == '\n');if(e == 'Y'){system("cls");Cancel_order();}}}void Print_welcome(){printf("+-----------------------------------------------------------------------+\n\+ +\n\ + +\n\ + +\n\ + 欢迎使用简易订票系统!+\n\ + +\n\ + +\n\ + +\n\ + +\n\ + Copyright @ 2011 ****** *** +\n\ + +\n\ + +\n\ +-----------------------------------------------------------------------+\n");pause();}//欢迎界面,说明程序用途及作者char Print_operate(){char e;system("cls");printf("+-----------------------------------------------------------------------+\n\+ +\n\ + 一、录入列车信息请按'1' +\n\ + +\n\ + +\n\ + 二、更改列车信息请按'2' +\n\ + +\n\ + +\n\ + 三、查询列车信息请按'3' +\n\ + +\n\ + +\n\ + 四、订票请按'4' +\n\ + +\n\ + +\n\ + 五、退票请按'5' +\n\ + +\n\ + +\n\ + 六、退出请按'6' +\n\ + +\n\ + +\n\ +-----------------------------------------------------------------------+\n");do{scanf("%c",&e);}while(e == '\n'); //不管有多少回车,全部吃掉!while((int)e < '0' || (int)e > '6'){printf("\n选择错误!请重新选择!\n");Print_operate();}return(e);}//简单操作的选择void operate(){char choice;choice = Print_operate();system("cls");switch(choice){case '1':{Inuput(); //选择1输入列车信息break;}case '2':{Change_main(); //选择2更改列车信息break;}case '3':{Quiry_main(); //选择3查询列车信息break;}case '4':{Order_main(); //选择4订票break;}case '5':{Cancel_order(); //选择5退票break;}case '6':{flag = 1; //选择6退出break;}}}int main(){head_rail = (Pst_Rail)malloc(sizeof(Railway));head_rail->takeoff = (Ptime)malloc(sizeof(Time));head_rail->arrive = (Ptime)malloc(sizeof(Time));head_rail->next = NULL;head_order = (Pst_Order)malloc(sizeof(Order));head_order->next = NULL;numofrail = 0;numoforder = 0;lastorder = numoforder + 1;Print_welcome(); //打印欢迎界面if((data = fopen("c://data.txt","r+")) == NULL){data = fopen("c://data.txt","w+");}else{printf("数据初始化,请稍后!\n");pause();File_Scanf_Data();}if((order = fopen("c://order.txt","r+")) == NULL) {order = fopen("c://order.txt","w+");}else{printf("数据初始化,请稍后!\n");pause();File_Scanf_Order();}while(1){flag = 0; //将标记置0operate(); //调用操作函数if(flag) break; //标记为1时退出}File_write();fclose(data);fclose(order);return 0;}。
全国交通咨询模拟数据结构课程设计
数据结构课程设计报告题目:全国交通咨询模拟一.需求分析1.程序设计任务:从中国地图平面图中选取部分城市,抽象为程序所需要图(de)结点,并以城市间(de)列车路线和飞机路线,作为图结点中(de)弧信息,设计一个全国交通咨询模拟系统.利用该系统实现两种最优决策:最快到达或最省钱到达.2. 明确规定:(1)输入形式和输入值(de)范围:每条飞机弧或者火车弧涉及(de)信息量很多,包括:起始城市、目(de)城市、出发时间、到达时间、班次以及费用.作为管理员要输入(de)信息包括以上信息,而作为用户或者客户,要输入(de)信息有起始城市和目(de)城市,并选择何种最优决策.(2)输出形式:按用户提供(de)最优决策(de)不同而输出不同(de)信息,其中输出(de)所搭飞机或火车(de)班次及其起始地点和终点、起始时间和出发时间还有相关(de)最优信息,比如最快经多少时间到达、最省钱多少钱到达和最少经多少中转站到达.(3)程序所能达到(de)功能a.该系统有供用户选择(de)菜单和交互性.可以对城市、列车车次和飞机航班进行编辑,添加或删除.b.建立一个全国交通咨询系统,该系统具备自动查找任意两城市间铁路、飞机交通(de)最短路径和最少花费及中转次数最少等功能.c.初始化交通系统有两种方式,键盘和文档.二.设计概要1.算法设计(1)、总体设计(1) 数据存储:城市信息(城市名、代码)、交通信息(城市间(de)里程、各航班和列车时刻)存储于磁盘文件.建议把城市信息存于文件前面,交通信息存于文件(de)后面,用fread和fwrite函数操作.(2) 数据(de)逻辑结构:根据设计任务(de)描述,其城市之间(de)旅游交通问题是典型(de)图结构,可看作为有向图,图(de)顶点是城市,边是城市之间所耗费(de)时间(要包括中转站(de)等候时间)或旅费.(3) 数据(de)存储结构:采用邻接表和邻接矩阵都可作为数据(de)存储结构,但当邻接边不多时,宜采用邻接表,以提高空间(de)存储效率.这里采用邻接表作为数据(de)存储结构.(4) 用不同(de)功能模块对城市信息和交通信息进行编辑.添加、修改、删除功能可用菜单方式或命令提示方式.只要能方便(de)对城市信息和交通信息进行管理即可,但要注意人机界面.(5) 最优决策功能模块(fast or province).①读入城市信息和交通信息,用邻接表生成含权网络,表头数组中(de)元素存放城市名及对方城市到达该元素所代表城市(de)所有信息;表头数组中(de)元素所对应(de)单链表存放与该元素所代表(de)城市有交通联系(de)城市(代码、里程、航班、列车车次).②根据具体最优决策(de)要求,用Dijkstra算法求出出发城市到其它各城市(de)最优值(最短时间或最小(de)费用),搜索过程中所经过城市(de)局部最优信息都保存在邻接表(de)表头数组中.其目(de)城市所代表(de)元素中就保存了所需(de)最优决策结果.这过程中,要用队列或栈保存局部最优决策值(局部最短(de)时间或最省(de)费用)变小(de)城市,其相应(de)初始值可为∞,并在表头数组对应(de)城市元素中保存响应(de)信息.开始时,栈(队列)中只有出发地城市,随着对栈(队列)顶(首)城市有交通联系(de)城市求得决策值(最短时间或最小(de)费用),若该值是局部最优值且该城市不在栈(队列)中,则进栈(队列),直至栈(队列)为空,本题采用队列实现.③输出结果:从目(de)城市出发,搜索到出发城市,所经过(de)城市均入栈(队列),再逐一出栈栈(队列)中(de)城市,输出保存在表头数组中对应城市(de)信息(对方城市(de)出发信息,里程、时间、费用等)及最终结果.即输出依次于何时何地乘坐几点(de)飞机或火车于何时到达何地;最终所需(de)最快需要多长时间才能到达及旅费,或者最少需要多少旅费才能到达及时间.(6) 主程序可以有系统界面、菜单;也可用命令提示方式;选择功能模块执行,要求在程序运行过程中可以反复操作.(2).详细设计思想:本题所要求(de)交通系统是一个有向带权图结构,考虑到要求该系统有动态增加飞机和列车航班(de)功能,因而采用邻接表(de)形式存储:对每个顶点建立一个单链表,单链表中(de)子结点表示以该顶点连接(de)弧,单链表中子结点(de)顺序可以按权值递增(de)顺序排列,表头结点按顺序存储.题目中提到要提供三种策略,最快到达,最省钱到达和最少中转次数策略,前两种策略采用迪杰斯特拉算法思想,其中最快到达(de)权值为到达两城市所需(de)最短时间,最省钱到达(de)权值为到达两城市所需(de)费用,后一种采用广度优先算法(de)思想,只需求(de)两城市所在(de)层数,就可以求(de)到达两城市所需(de)最少中转次数.迪杰斯特拉(Dijkstra)算法(de)基本思想是:设置两个顶点(de)集合S和T=V-S,集合S中存放已找到最短路径(de)顶点,集合T存放当前还未找到最短路径(de)顶点.初始状态时,集合S中只包含源点v0,然后不断从集合T中选取到顶点v0路径长度最短(de)顶点u加入到集合S中,集合S 每加入一个新(de)顶点u,都要修改顶点v0到集合T中剩余顶点(de)最短路径长度值,集合T中各顶点新(de)最短路径长度值为原来(de)最短路径长度值与顶点u(de)最短路径长度值加上u到该顶点(de)路径长度值中(de)较小值.此过程不断重复,直到集合T(de)顶点全部加入到S中为止.下面讨论基于邻接表(de)存储结构求两点间最短路径(de)方法:根据迪杰斯特拉(Dijkstra)算法所依据(de)原理:若按长度递增(de)次序生成从源点V0到其它顶点(de)最短路径,则当前正在生成(de)最短路径上除终点以外,其余顶点(de)最短路径均已生成(将源点(de)最短路径看作是已生成(de)源点到其自身(de)长度为0(de)路径).按照这一思想,构造以下算法:设S=S’=U={},建立数组PATH[n],用来存储V0到各终点(de)最短路径,初值均置为空集.建立数组BOOL F[n],F[i]表示序号为i(de)表头结点(de)单链表中所有子结点已或未全部找到,初值置为FALSE.建立数组float dist[n],dist[i]表示序号为i(de)表头结点到V0(de)最短权值(这里是时间或费用),显然dist[V0]=0,其他顶点(de)dist初值置为∞.建立数组BOOL IS[n],IS[i]表示序号为i(de)顶点是否在S 中,初值均置为FALSE.(1)VX=V0;最短(de)最短路径为PATH[0]=[V0] (2)S=S+VX ;(集合(de)并计算) IS[VX]=TRUE ; S ’=S ’+VX ;(3)对S ’中(de)所有顶点: {do{ 由邻接表中该表头结点开始依次找单链表(de)下一子结点(沿链域指针依次访问);While (“命令” = “退出”){接受命令(用户输入要实现功能); 进入各个处理命令函数;} }2. 函数和过程(de)调用关系图四.调试分析:⑴调试过程中遇到(de)问题是如何解决(de)以及对设计与实现(de)回顾讨论和分析:在调试(de)过程中碰到了一下问题:a. 引用形参应用不当;b. 文件操作中遇到读入错误或找不到文件;解决方案:a. 对引用形参了解(de)不是很透彻,导致错误,通过查阅相关书籍如C++ Primer 和请教编程能力较高(de)人,最终解决问题.b. 通过参考谭浩强编着(de)C程序设计中(de)文件操作,文件格式和相关文件路径(de)设置,最终解决问题.⑵算法(de)时空分析(包括基本操作和其他算法(de)时间复杂度和空间复杂度(de)分析)和改进设想:⑶经验和体会:通过本次课程设计,我学到了一种程序设计方法,就是结构化程序设计方法,在程序设计过程中,我尝试按如下方法进行结构化程序设计:(1)自顶向下;(2)逐步细化;(3)模块化设计(4)结构化编码.这种设计方法(de)过程是将问题求解由抽象逐步具体化(de)过程,而且,用这种方法便于验证算法(de)正确性.本次课程设计所使用(de)是较为复杂(de)抽象数据类型——图,而且在弧(de)基础上增加了许多信息,如添加了时间,费用等等,这无疑给编程加大了难度,同时也是相当(de)具有挑战性.在编程(de)过程中,我用到了全局数组,我将数组放在工程(de)头文件里面,编译(de)时候报错,说是多重定义.最终放弃了创建工程,而选择了单个文件进行编译和运行,结果顺利通过.同时,在文件操作方面我也曾遇到问题,就是在程序对文件进行读取(de)时候报错,无法读取文件,最后查询有关C(de)工具书,原来是文件路径问题,借助工具书最终解决了文件操作方面(de)问题.总之,这次课程设计是对这一个学期以来对数据结构学习成果(de)一个验证,同时也是理论与实践很好(de)结合,既对学过(de)数据结构进行了巩固,也对我(de)编程能力奠定了坚实(de)基础.五.用户使用说明:1)打开并运行程序,按任意键进入操作主界面,按提示进行相关操作;2)按“1”进入管理员界面,按“2”进入用户咨询界面,按“3”显示交通系统,按“4”则退出.3)进入管理员界面可键入“1”初始化交通系统,并选择文档初始化方式(如果是第一次使用该系统建议使用文档初始化交通系统,免得自己进行繁冗(de)初始化操作).其余可按提示进行相关操作,不难掌握.4)进入用户咨询界面,可根据用户需要进行相关(de)选择,或是选择“1”(最少旅行费用);或是选择“2”(最少旅行时间),又或者是选择“3”(最少旅行中转次数)等.5)进入显示交通系统界面,根据用户选择则可显示城市、飞机航班、列车车次等信息.或者返回上一级菜单.六.附录——源程序define MAX_VERTEX_NUM 18define NULL 0define MAX_ARC_SIZE 100define MAX_ROUTE_NUM 5include<>include<>include<>include<>define False 0define True 1define INFINITY 10000typedef struct{int number;float expenditure;int begintime[2];int arrivetime[2];}Vehide;typedef struct{Vehide stata[MAX_ROUTE_NUM];int last;}infolist;typedef struct ArcNode{int adjvex;struct ArcNode nextarc;infolist info;}ArcNode;typedef struct VNode{char cityname[10];ArcNode planefirstarc,trainfirstarc; }VNode,AdjList[MAX_VERTEX_NUM];typedef struct{AdjList vertices;int vexnum,planearcnum,trainarcnum; }ALGraph;typedef struct Node{int adjvex;int route;struct Node next;}Node;typedef struct QNode{int adjvex;struct QNode next;}QNode;typedef struct{QNode front;QNode rear;}LinkQueue;typedef struct TimeNode{int adjvex;int route;int begintime[2];int arrivetime[2];struct TimeNode child[MAX_ROUTE_NUM]; }TimeNode,TimeTree;struct arc{int co;char vt[10];char vh[10];int bt[2];int at[2];float mo;}a[MAX_ARC_SIZE];char city[MAX_VERTEX_NUM][10];int TTime[2];int time[2];int time1[2];int time2[2];int c[MAX_VERTEX_NUM];int d[MAX_VERTEX_NUM];void Administer(ALGraph G);void cityedit(ALGraph G);void CopyTimeTree(TimeTree p,TimeTree q);void createcityfile();void CreateGraph(ALGraph G);void createplanefile();void CreateTimeTree(TimeTree p,int i,int j,LinkQueue Q,infolist (arcs)[MAX_VERTEX_NUM]);void createtrainfile();int DeleteplaneArc(ALGraph G);void DeleteQueue(LinkQueue Q,int x);int DeletetrainArc(ALGraph G);void DeleteVertex(ALGraph G);void DemandDispose(int n,ALGraph G);void DestoryTimeTree(TimeTree p);void EnterplaneArc(ALGraph G);void EnterQueue(LinkQueue Q,int x);void EntertrainArc(ALGraph G);void EnterVertex(ALGraph G);void ExpenditureDispose(int k,infolist (arcs)[MAX_VERTEX_NUM],ALGraph G,int v0,int v1,float M,int final);void flightedit(ALGraph G);void initgraph(ALGraph G);void InitQueue(LinkQueue Q);int IsEmpty(LinkQueue Q);int LocateVertex(ALGraph G,char v);void MinExpenditure(infolist arcs,float expenditure,int route);void MinTime(infolist arcs,int time,int route);void PrintGraph(ALGraph G);int save(ALGraph G);void TimeDispose(int k,infolist (arcs)[MAX_VERTEX_NUM],ALGraph G,int v0,int v1,int (T)[2],int final);void TimeTreeDispose(Node head,infolist (arcs)[MAX_VERTEX_NUM]);void trainedit(ALGraph G);void TransferDispose(int k,infolist (arcs)[MAX_VERTEX_NUM],ALGraph G,int v0,int v1);void UserDemand(ALGraph G);void VisitTimeTree(TimeTree p);int main(){ALGraph G;int i;printf("\n\n\n\n\n\n\n\n");printf("\n");printf("~~~~~ 学院:信息科学与技术学院~~~~~\n");printf("~~~~~ 专业:通信工程~~~~~\n");printf("~~~~~ 姓名:~~~~~\n");printf("~~~~~ 学号:0 ~~~~~\n");printf("\n");printf("\n");printf("请按任何键以继续……");getchar();system("cls");printf("\n\n\n\n\n\n\n 请选择程序功能:\n");printf(" \n");printf(" 1=管理员管理 \n");printf(" 2=用户咨询 \n");printf(" 3=显示交通系统 \n");printf(" 4=退出 \n");printf(" \n");printf(" 选择");scanf("%d",&i);getchar();while(i=4){switch(i){case 1:Administer(&G);break;case 2:UserDemand(G);break;case 3:PrintGraph(&G);break;}system("cls");printf("\n\n\n\n\n\n\n\n 请选择程序功能:\n" );printf(" \n");printf(" 1=管理员管理\n");printf(" 2=用户咨询\n");printf(" 3=显示交通系统\n");printf(" 4=退出\n");printf(" \n");printf(" 选择");scanf("%d",&i);getchar();}return 1;}void Administer(ALGraph G){int i;system("cls");printf("\n\n\n\n\n\n\n\n 请选择管理项目:\n");printf(" \n");printf(" 1=初始化交通系统\n");printf(" 2=城市编辑\n");printf(" 3=飞机航班编辑\n");printf(" 4=列车车次编辑\n");printf(" 5=返回上一级菜单\n");printf(" \n");printf(" 选择");scanf("%d",&i);getchar();while(i=5){switch(i){case 1:initgraph(G);break;case 2:cityedit(G);break;case 3:flightedit(G);break;case 4:trainedit(G);break;}system("cls");printf("\n\n\n\n\n\n\n\n\n 请选择管理项目:\n");printf(" \n");printf(" 1=初始化交通系统\n");printf(" 2=城市编辑\n");printf(" 3=飞机航班编辑\n");printf(" 4=列车车次编辑\n");printf(" 5=返回上一级菜单\n");printf(" \n");printf(" 选择");scanf("%d",&i);getchar();}}void initgraph(ALGraph G){int i;system("cls");printf("\n\n\n\n\n\n\n\n\n 请选择初始化方式:\n");printf(" \n");printf(" 1=键盘\n");printf(" 2=文档\n");printf(" \n");printf(" 选择");scanf("%d",&i);getchar();switch(i){case 1:createcityfile();createplanefile();createtrainfile();CreateGraph(G);break;case 2:CreateGraph(G);break;}}void createcityfile(){int i=0;int j;char flag='y';FILE fp;printf("\n请输入城市名称(de)信息:\n"); while(flag=='y'||flag=='Y'){printf("城市名称:");gets(city[i]);i++;printf("继续输入(Y/N)");scanf("%c",&flag);getchar();}printf("\n");if((fp=fopen("","wb"))==NULL){printf("无法打开文件\n");return;}for(j=0;j<i;j++)fprintf(fp,"%10s",city[j]);fclose(fp);}void createplanefile(){int code,bt[2],at[2];float money;int i;int count;char vt[10],vh[10],flag;FILE fp;flag='y';count=0;while(flag=='Y'||flag=='y') {printf("请输入飞机航班(de)信息:\n");printf("飞机航班编号:");scanf("%d",&code);getchar();printf("起始城市:");gets(vt);printf("目(de)城市:");gets(vh);printf("航班费用:");scanf("%f",&money);getchar();printf("起飞时间:");scanf("%d:%d",&bt[0],&bt[1]);getchar();while(bt[0]<0||bt[0]>=24||bt[1]<0||bt[1]>=60){printf("\n时间输入有误,请重新输入\n");scanf("%d:%d",&bt[0],&bt[1]);getchar();}printf("到达时间:");scanf("%d:%d",&at[0],&at[1]);getchar();while(at[0]<0||at[0]>=24||at[1]<0||at[1]>=60) {printf("\n时间输入有误,请重新输入\n");scanf("%d:%d",&at[0],&at[1]);getchar();}a[count].co=code;strcpy(a[count].vt,vt);strcpy(a[count].vh,vh);a[count].bt[0]=bt[0];a[count].bt[1]=bt[1];a[count].at[0]=at[0];a[count].at[1]=at[1];a[count].mo=money;count++;printf("继续输入(Y/N)");scanf("%c",&flag);getchar();printf("\n");}if((fp=fopen("","wb"))==NULL)printf("\n无法打开文件\n");fprintf(fp,"%d",count);for(i=0;i<count;i++)if(fwrite(&a[i],sizeof(struct arc),1,fp)=1) printf("\n文件写入错误\n");fclose(fp);}void createtrainfile(){int code,bt[2],at[2];float money;int i;int count;char vt[10],vh[10],flag;FILE fp;flag='y';count=0;while(flag=='y'||flag=='Y'){printf("请输入列车车次(de)信息:\n"); printf("列车车次编号:");scanf("%d",&code);getchar();printf("起始城市:");gets(vt);printf("目(de)城市:");gets(vh);printf("车次费用:");scanf("%f",&money);getchar();printf("发车时间:");scanf("%d:%d",&bt[0],&bt[1]);getchar();while(bt[0]<0||bt[0]>=24||bt[1]<0||bt[1]>=60) {printf("\n时间输入有误,请重新输入\n");scanf("%d:%d",&bt[0],&bt[1]);getchar();}printf("到达时间:");scanf("%d:%d",&at[0],&at[1]);getchar();while(at[0]<0||at[0]>=24||at[1]<0||at[1]>=60) {printf("\n时间输入有误,请重新输入\n");scanf("%d:%d",&at[0],&at[1]);getchar();}a[count].co=code;strcpy(a[count].vt,vt);strcpy(a[count].vh,vh);a[count].bt[0]=bt[0];a[count].bt[1]=bt[1];a[count].at[0]=at[0];a[count].at[1]=at[1];a[count].mo=money;count++;printf("继续输入(Y/N)");scanf("%c",&flag);getchar();printf("\n");}if((fp=fopen("","wb"))==NULL)printf("\n无法打开文件\n");fprintf(fp,"%d",count);for(i=0;i<count;i++)if(fwrite(&a[i],sizeof(struct arc),1,fp)=1) printf("\n文件写入错误\n");fclose(fp);}int LocateVertex(ALGraph G,char v){int j,k;j=-1;for(k=0;k<G->vexnum;k++)if(strcmp(G->vertices[k].cityname,v)==0) {j=k;break;}return(j);}void CreateGraph(ALGraph G){int i,j,k;int arc_num;int count1,count2;int m,t;ArcNode p,q;FILE fp;i=0;if((fp=fopen("","rb"))==NULL){printf("\n无法打开文件\n");return;}while(feof(fp)){fscanf(fp,"%10s",city[i]);i++;}fclose(fp);j=0;while(j<i){strcpy(G->vertices[j].cityname,city[j]); G->vertices[j].planefirstarc=NULL;G->vertices[j].trainfirstarc=NULL;j++;}G->vexnum=i;if((fp=fopen("","rb"))==NULL)printf("\n无法打开文件\n");k=0;fscanf(fp,"%d",&count1);while(k<count1){if(fread(&a[k],sizeof(struct arc),1,fp)=1) printf("\n文件读入错误\n");k++;}fclose(fp);k=0;arc_num=0;while(k<count1){i=LocateVertex(G,a[k].vt);j=LocateVertex(G,a[k].vh);q=G->vertices[i].planefirstarc;m=0;while(q=NULL){if(q->adjvex==j){t=q->+1;q->[t].number=a[k].co;q->[t].expenditure=a[k].mo;q->[t].begintime[0]=a[k].bt[0]; q->[t].begintime[1]=a[k].bt[1];q->[t].arrivetime[0]=a[k].at[0];q->[t].arrivetime[1]=a[k].at[1];q->=t;m=1;break;}q=q->nextarc;}if(m==0){p=(ArcNode)malloc(sizeof(ArcNode));p->adjvex=j;p->[0].number=a[k].co;p->[0].expenditure=a[k].mo;p->[0].begintime[0]=a[k].bt[0];p->[0].begintime[1]=a[k].bt[1];p->[0].arrivetime[0]=a[k].at[0];p->[0].arrivetime[1]=a[k].at[1];p->=0;p->nextarc=G->vertices[i].planefirstarc; G->vertices[i].planefirstarc=p;arc_num++;}k++;}G->planearcnum=arc_num;if((fp=fopen("","rb"))==NULL){printf("\n无法打开文件\n");return;}k=0;fscanf(fp,"%d",&count2);while(k<count2){if(fread(&a[k],sizeof(struct arc),1,fp)=1) printf("\n文件读入错误\n");k++;}fclose(fp);k=0;arc_num=0;while(k<count2){i=LocateVertex(G,a[k].vt);j=LocateVertex(G,a[k].vh);q=G->vertices[i].trainfirstarc;m=0;while(q=NULL){if(q->adjvex==j){t=q->+1;q->[t].number=a[k].co;q->[t].expenditure=a[k].mo;q->[t].begintime[0]=a[k].bt[0]; q->[t].begintime[1]=a[k].bt[1]; q->[t].arrivetime[0]=a[k].at[0]; q->[t].arrivetime[1]=a[k].at[1]; q->=t;m=1;break;}q=q->nextarc;}if(m==0){p=(ArcNode)malloc(sizeof(ArcNode));p->adjvex=j;p->[0].number=a[k].co;p->[0].expenditure=a[k].mo;p->[0].begintime[0]=a[k].bt[0];p->[0].begintime[1]=a[k].bt[1];p->[0].arrivetime[0]=a[k].at[0];p->[0].arrivetime[1]=a[k].at[1];p->=0;p->nextarc=G->vertices[i].trainfirstarc; G->vertices[i].trainfirstarc=p;arc_num++;}k++;}G->trainarcnum=arc_num;}int save(ALGraph G){int i,j,k,t;ArcNode q;FILE fp;j=0;while(j<G->vexnum){strcpy(city[j],G->vertices[j].cityname); j++;}i=0;if((fp=fopen("","wb"))==NULL)printf("\n错误,无法打开文件\n");while(i<G->vexnum){fprintf(fp,"%10s",city[i]);i++;}fclose(fp);k=0;for(i=0;i<G->vexnum;i++){q=G->vertices[i].planefirstarc;while(q=NULL){for(t=0;t<=q->;t++){strcpy(a[k].vt,G->vertices[i].cityname);strcpy(a[k].vh,G->vertices[q->adjvex].cityname); a[k].co=q->[t].number;a[k].mo=q->[t].expenditure;a[k].bt[0]=q->[t].begintime[0];a[k].bt[1]=q->[t].begintime[1];a[k].at[0]=q->[t].arrivetime[0];a[k].at[1]=q->[t].arrivetime[1];k++;}q=q->nextarc;}}if((fp=fopen("","wb"))==NULL){printf("\n无法打开文件\n");return 0;}i=0;fprintf(fp,"%d",k);while(i<k){if(fwrite(&a[i],sizeof(struct arc),1,fp)=1)printf("\n文件写入错误\n");i++;}fclose(fp);k=0;for(i=0;i<G->vexnum;i++){q=G->vertices[i].trainfirstarc;while(q=NULL){for(t=0;t<=q->;t++){strcpy(a[k].vt,G->vertices[i].cityname);strcpy(a[k].vh,G->vertices[q->adjvex].cityname); a[k].co=q->[t].number;a[k].mo=q->[t].expenditure;a[k].bt[0]=q->[t].begintime[0];a[k].bt[1]=q->[t].begintime[1];a[k].at[0]=q->[t].arrivetime[0];a[k].at[1]=q->[t].arrivetime[1]; k++;}q=q->nextarc;}}if((fp=fopen("","wb"))==NULL){printf("\n无法打开文件\n");return 0;}i=0;fprintf(fp,"%d",k);while(i<k){if(fwrite(&a[i],sizeof(struct arc),1,fp)=1) printf("\n文件写入错误\n");i++;}fclose(fp);return 1;}void cityedit(ALGraph G){int i;printf("\n请选择城市编辑项目:\n");printf("1=增加城市\n2=删除城市\n"); printf("选择");scanf("%d",&i);getchar();if(i==1)EnterVertex(G);if(i==2)DeleteVertex(G);}void EnterVertex(ALGraph G){char v[10],c;int i;printf("\n请输入新增城市(de)名称:"); gets(v);i=LocateVertex(G,v);if(i>=0&&i<G->vexnum){printf("\n错误此城市已存在\n");return;}else{printf("\n确认(Y/N)");c=getchar();getchar();if(c=='Y'||c=='y'){i=G->vexnum;strcpy(G->vertices[i].cityname,v); G->vertices[i].planefirstarc=NULL; G->vertices[i].trainfirstarc=NULL; G->vexnum=i+1;save(G);}elsereturn;}}void DeleteVertex(ALGraph G){int i,j,k,n;char v[10],c;ArcNode p,q,m;printf("\n请输入删除(de)城市:");gets(v);printf("\n确认(Y/N)");c=getchar();getchar();if(c=='Y'||c=='y'){n=0;while(n<G->vexnum&&strcmp(G->vertices[n].cityname,v)=0) n++;if(n==G->vexnum)printf("\n错误无法找到此城市\n");else{i=LocateVertex(G,v);p=G->vertices[i].planefirstarc;while(p=NULL){q=p;p=p->nextarc;free(q);}p=G->vertices[i].trainfirstarc;while(p=NULL){q=p;p=p->nextarc;free(q);}for(j=i;j<G->vexnum-1;j++){strcpy(G->vertices[j].cityname,G->vertices[j+1].cityname); G->vertices[j].planefirstarc=G->vertices[j+1].planefirstarc;G->vertices[j].trainfirstarc=G->vertices[j+1].trainfirstarc;}G->vertices[j].planefirstarc=NULL;G->vertices[j].trainfirstarc=NULL;for(k=0;k<G->vexnum-1;k++){p=G->vertices[k].planefirstarc;while(p=NULL){if(p->adjvex>i){p->adjvex=p->adjvex-1;q=p;p=p->nextarc;}else if(p->adjvex==i){if(p==G->vertices[k].planefirstarc){m=p;G->vertices[k].planefirstarc=p->nextarc; p=p->nextarc;free(m);}else{q->nextarc=p->nextarc; m=p;p=p->nextarc;free(q);}}else{q=p;p=p->nextarc;}}}for(k=0;k<G->vexnum-1;k++){p=G->vertices[k].trainfirstarc; while(p=NULL){if(p->adjvex>i){p->adjvex=p->adjvex-1;q=p;}else if(p->adjvex==i){if(p==G->vertices[k].trainfirstarc){m=p;G->vertices[k].trainfirstarc=p->nextarc; p=p->nextarc;free(m);}else{q->nextarc=p->nextarc;m=p;p=p->nextarc;free(q);}}else{q=p;}}}}G->vexnum--;save(G);}elsereturn;}void flightedit(ALGraph G){int i;printf("\n请选择飞机航班编辑项目:\n"); printf("1=新增航班\n2=删除航班\n");printf("选择");scanf("%d",&i);getchar();if(i==1)EnterplaneArc(G);if(i==2)DeleteplaneArc(G);}void trainedit(ALGraph G){int i;printf("\n请选择列车车次编辑项目:\n"); printf("1=新增车次\n2=删除车次\n");printf("选择");scanf("%d",&i);getchar();if(i==1)EntertrainArc(G);if(i==2)DeletetrainArc(G);}void EnterplaneArc(ALGraph G){int i,j,bt[2],at[2];int code;float money;int m,t;char vt[10],vh[10],c;ArcNode p,q;printf("\n请输入新增飞机航班(de)信息:\n");printf("飞机航班编号:");scanf("%d",&code);getchar();printf("起始城市:");gets(vt);printf("目(de)城市:");gets(vh);printf("航班费用:");scanf("%f",&money);getchar();printf("起飞时间:");scanf("%d:%d",&bt[0],&bt[1]);getchar();while(bt[0]<0||bt[0]>=24||bt[1]<0||bt[1]>=60) {printf("\n时间输入有误,请重新输入\n");scanf("%d:%d",&bt[0],&bt[1]);getchar();}printf("到达时间:");scanf("%d:%d",&at[0],&at[1]);getchar();while(at[0]<0||at[0]>=24||at[1]<0||at[1]>=60) {printf("\n时间输入有误,请重新输入\n");scanf("%d:%d",&at[0],&at[1]);getchar();}printf("\n确认(Y/N)");c=getchar();getchar();if(c=='Y'||c=='y'){i=LocateVertex(G,vt);j=LocateVertex(G,vh);if(i==-1){printf("\n错误无法找到起始城市\n");return;}if(j==-1){。
数据结构--交通咨询系统
数据结构--交通咨询系统目录1 概述 (2)1.1 问题描述 (2)1.2 实现意义 (2)2 系统分析 (2)2.1 需求分析 (2)2.1.1程序的功能 (2)2.1.2输入输出的要求 (2)2.2 设计思想 (2)2.3 设计要求 (3)3 概要设计 (3)3.1用邻接矩阵建立交通网络模块 (3)3.2 查询任意两个顶点之间的最短路径 (4)3.3 查询一个城市到其他所有城市的最短路径 (5)4 详细设计 (5)4.1 用邻接矩阵构造图结构函数CreateMGraph() (5) 4.2 费洛伊德Floyd() (6)4.3 迪杰斯特拉Dijkstra() (6)4.4 主要函数流程图及其函数调用 (7)4.4.1 主要函数流程图 (7)4.4.2 一个城市到其他城市的路径调用 (8)4.4.3 任意两个城市之间路径调用 (8)5 运行与测试 (8)5.1 有向图存储结构的建立模块的输出 (9)5.2 单源路径迪杰斯特拉算法模块的输出 (10)5.3 费洛伊德算法模块的输出 (10)6 总结与心得 (10)参考文献 (11)附录 (11)1 概述1.1 问题描述在交通网络非常发达,交通工具和交通方式不断更新的今天,人们在出差、旅游或做其它出行时,不仅关心节省费用,而且对里程和所需时间等问题也感兴趣。
对于这样一个人们关心的问题,可用一个图结构来表示交通网络系统,利用计算机建立一个交通咨询系统。
图中顶点表示城市之间的交通关系。
这个交通系统可以回答旅客提出的各种问题。
比如任意一个城市到其他城市的最短路径,任意两个城市之间的最短路径问题。
1.2 实现意义便于人们的日常出行,且更好地满足了用户的出行需求。
这种最短路径问题的计算方法既简单又便于实现,同时大大提高了计算机的运行速率。
2 系统分析2.1 需求分析2.1.1程序的功能(1)用户自己可以建立不同的路径之间的关系网(2)可以查询某个城市到达其余各城市的最短路径。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
全国交通咨询模拟 数据结构 源代码
在全国范围内建立一个交通咨询模拟系统,可以为用户提供交通信息查询和路
线规划的功能。为了实现这个系统,我们需要设计和实现合适的数据结构,并编写
相应的源代码。
首先,我们需要考虑的是如何表示交通网络。一个简单而有效的方法是使用图
来表示道路和交通节点。我们可以使用邻接矩阵或邻接表来表示图。在这个模拟系
统中,每个城市可以看作是一个节点,每条道路可以看作是两个节点之间的边。邻
接矩阵可以用一个二维数组来表示,其中数组的每个元素表示两个节点之间的距离
或道路的权重。邻接表则使用链表来表示每个节点的邻接节点。
接下来,我们需要考虑如何实现交通信息查询功能。用户可以输入起始城市和
目的城市,系统需要返回最短路径或最快路径。为了实现这个功能,我们可以使用
Dijkstra算法或A*算法。Dijkstra算法可以找到两个节点之间的最短路径,而A*算
法则可以找到两个节点之间的最快路径。这些算法需要在图的基础上进行计算,并
使用合适的数据结构来存储节点和路径信息。
除了交通信息查询,用户还可以查询特定城市的交通拥堵情况。为了实现这个
功能,我们可以为每个城市维护一个拥堵指数。拥堵指数可以表示道路的通行能力
或交通流量。当用户查询某个城市的交通拥堵情况时,系统可以返回该城市的拥堵
指数,并根据指数的高低提供相应的建议。
在实现这个交通咨询模拟系统时,我们还需要考虑数据的存储和更新。可以使
用数据库来存储城市、道路和拥堵指数等信息。数据库可以提供高效的数据查询和
更新功能,并且可以方便地与系统的源代码进行交互。
以下是一个简单的伪代码示例,展示了如何使用数据结构和算法实现交通咨询
模拟系统:
```
class City:
def __init__(self, name):
self.name = name
self.adjacent_cities = []
self.congestion_index = 0
def add_adjacent_city(self, city, distance):
self.adjacent_cities.append((city, distance))
def update_congestion_index(self, index):
self.congestion_index = index
class TrafficConsultation:
def __init__(self):
self.cities = {}
def add_city(self, name):
city = City(name)
self.cities[name] = city
def add_road(self, city1, city2, distance):
self.cities[city1].add_adjacent_city(self.cities[city2], distance)
self.cities[city2].add_adjacent_city(self.cities[city1], distance)
def update_congestion_index(self, city, index):
self.cities[city].update_congestion_index(index)
def shortest_path(self, start_city, end_city):
# 使用Dijkstra算法计算最短路径
# 返回最短路径和距离
def fastest_path(self, start_city, end_city):
# 使用A*算法计算最快路径
# 返回最快路径和时间
def get_congestion_index(self, city):
# 返回城市的拥堵指数
# 创建交通咨询模拟系统实例
consultation = TrafficConsultation()
# 添加城市
consultation.add_city("北京")
consultation.add_city("上海")
consultation.add_city("广州")
# 添加道路
consultation.add_road("北京", "上海", 1000)
consultation.add_road("北京", "广州", 1500)
consultation.add_road("上海", "广州", 1200)
# 更新拥堵指数
consultation.update_congestion_index("北京", 80)
consultation.update_congestion_index("上海", 70)
consultation.update_congestion_index("广州", 90)
# 查询最短路径和最快路径
shortest_path, distance = consultation.shortest_path("北京", "广州")
fastest_path, time = consultation.fastest_path("北京", "广州")
# 查询拥堵指数
congestion_index = consultation.get_congestion_index("北京")
```
以上是一个简单的交通咨询模拟系统的设计和实现示例。根据实际需求,可以
进一步完善和优化代码,以满足更复杂的交通信息查询和路线规划需求。希望这个
示例能够帮助您理解如何使用数据结构和算法来实现全国交通咨询模拟系统。