校园导航系统数据结构课程设计_第1页
校园导航系统数据结构课程设计_第2页
校园导航系统数据结构课程设计_第3页
校园导航系统数据结构课程设计_第4页
校园导航系统数据结构课程设计_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

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

文档简介

1、课程设计报告书课程名称 数据结构 设计题目 校园导航系统 专业班级 计算机11-4 班 学 号 1101050110 姓 名 刘冬冬 指导教师 彭延军 2013 年 12 月目录1.设计时间 22.设计目的 23.设计任务 24.设计内容 24.1需求分析 24.2总体设计 34.3详细设计 44.4测试与分析124.4.1测试124.4.2分析134.5 附录145 总结与展望 206.参考文献 217.成绩评定 211 设计时间 2013年12月3日2 设计目的1加深对数据结构这一课程所学内容的进一步理解与巩固2通过完成课程设计,逐渐培养自己的编程能力;3培养给出题目后,构建框架,用计算机

2、解决的能力;4通过调试程序积累调试C程序设计的经验; 3设计任务给出校园各主要建筑的名称信息及有线路联通的建筑之间的距离,利用校园导航系统计算出给定的起点到终点之间的最近距离及线路。4 设计内容 4.1需求分析 1程序所能达到的功能: (1) map输出山东科技大学平面图。(2) init()按相应编号输入各个节点内容,对相应路径赋值的函数。(3) floyd()- -弗洛伊德求最短路径(4) information()输出简介的函数(5) Path()最短路径的输出函数(6) shortestpath()调用弗洛伊德和最短路径输出的函数(7) main()主函数2输入的形式和输入值的范围:输

3、入数字和字母: 字母:以s查询最短路径;以i查询信息;以e退出程序。 数字:从1到9输入。3输出的形式:从A到B得最短路径为: A-到-C-到-D-到-B 最短距离为:xxx米。4测试数据包括在正确的输入及输出结果及含有错误的输入及输出结果:Input:sOutput:Please enter the number two to query : 1 7 Output:The shortest path from Area C dormitory building to library is: Area C dormitory building-Area C restaurant-library

4、; The shortest distance is:150meters.Input:i Output:Please enter the number of query site: 3Output:name: Area B dormitory building introduction:Area B student rest areainput:e output:Thank you for you use 4.2总体设计1抽象数据类型定义typedef structchar name100 ;int number; char introduce100;Vertex;2主程序模块的整体流程 1、

5、进入主函数,调用init(),map()。2、选择“s”,调用shortestpath函数,并同时调用floyd和way函数。3、选择“i”,调用information函数4、选择“e”,退出。3.各模块调用关系如下: 主函数 e i s shortestpath Information Exit4.3详细设计1.有向网节点结构体类型定义:typedef structchar name100 ;int number; char introduce100;Vertex;2. 主程序和其它主要函数伪码算法1)主程序int main() char i; printf( Welcome to use

6、the shandong university of science and technology of navigation systemnnnn); init(); map(); char c; do printf(Please enter the s to query the shortest pathn); printf(Please enter the i to query informationn); printf(Please input e to exit the programnnn); loop: scanf(%c,&c); if(c = A & c = Z) c += 3

7、2; if(c = n) goto loop; if(c != n) if(c = s) shortestpath(); continue; else if(c = i) Information(); continue; else if(c = e) printf(nnnttttThank you for you usennn); return 0; else printf(input error!n); continue; while(1); return 0;2)赋值init函数void init()int i, j;vertex1.number = 1;strcpy(vertex1.na

8、me,Area C dormitory building); strcpy(roduce, Area C student rest area); vertex2.number = 2; strcpy(, Area A dormitory building); strcpy(roduce,Area A student rest area); vertex3.number = 3; strcpy(, Area B dormitory building); strcpy(roduce,A

9、rea B student rest area); vertex4.number = 4; strcpy(, Area C restaurant); strcpy(roduce,Area C student dining area); vertex5.number = 5; strcpy(,Area A restaurant); strcpy(roduce,Area A student dining area); vertex6.number = 6; strcpy(,Area

10、B restaurant); strcpy(roduce,Area B student dining area); vertex7.number = 7; strcpy(,library); strcpy(roduce,Student borrowing books area); /*vertex7.number = 8; strcpy(,Area A restaurant); strcpy(roduce,Area A student dining area);*/ vertex8

11、.number = 8; strcpy(,No. 1 teaching building); strcpy(roduce,Students in class area); vertex9.number = 9; strcpy(,No. 13 teaching building); strcpy(roduce,Information institute, college building); for(i = 1; i MAX_VERTEX_NUM; +i) for(j = 1; j MAX_VERTEX_

12、NUM; +j) distij = INFINITY; for(i = 1; i MAX_VERTEX_NUM; +i) distii = 0; dist12 = dist21 = 20; dist23 = dist32 = 40; dist14 = dist41 = 50; dist25 = dist52 = 30; dist36 = dist63 = 50; dist45 = dist54 = 70; dist56 = dist65 = 90; dist47 = dist74 = 100; dist58 = dist85 = 120; dist69 = dist96 = 80; dist7

13、8 = dist87 = 60; dist89 = dist98 =120;3)输出山东科技大学平面图的map函数void map()printf( the science and technology of Shandong university mapn);printf(nn);printf( (1)Area C dormitory building-(2)Area A dormitory building-(3)Area B dormitory buildingn);printf( | | | n);printf( | | | n);printf( | | | n);printf( (4

14、)Area C restaurant -(5)Area A restaurant-(6)Area B restaurantn);printf( | | | n);printf( | | | n);printf( | | | n);printf( (7)library-(8)No. 1 teaching building-(9)No. 13 teaching buildingn); printf(nnn);4)输出地点信息的information函数void Information()int number;while(1)printf(Please enter the number of que

15、ry site:);scanf(%d,&number);if(number 0)printf(nname: %snintroduction:%sn,,roduce);return;elseprintf(input error!n);5)最短路径floyd函数void floyd()/*弗洛伊德算法*/int i, j, u;for(i = 1; i MAX_VERTEX_NUM; +i)for(j = 1; j MAX_VERTEX_NUM; +j)shortestij = distij;pathij = 0;for(u = 1

16、; u MAX_VERTEX_NUM; +u)for(i = 1; i MAX_VERTEX_NUM; +i)for(j = 1; j (shortestiu + shortestuj)shortestij = shortestiu + shortestuj;pathij = pathji = u;6)输出路径Path算法void Path(int i, int j)/*最短路径的输出*/int u = 0;int a,b;a = i;b = j; if(shortestij != INFINITY)printf(nThe shortest path from %s to %s is:nn,v

17、,);printf(%s,);while(pathij != 0)u = pathij;while(pathiu != 0) u = pathiu;printf(-%s,);i = u;printf(-%s;n,);printf(nThe shortest distance is:%d meters.n,shortestab);7)调用floyd和Path的最短路径shortestpath算法void shortestpath()int i, j;while(1)printf(

18、Please enter the number two to query :);scanf(%d%d, &i, &j);if(i 0 & i 0 & j MAX_VERTEX_NUM)floyd();/printf(=n);Path(i,j);return;3. 函数的调用关系exitexit mainMain Init map e i s Information() exit Shortsetpath()4.4测试与分析4.4.1测试1) 打开程序后,出现我校平面图和菜单选项,如图所示2)2) 选“i”,查询对应地点的信息,如输入“3”,而后会继续输出菜单,如图所示 3)选“s”,查询两点之

19、间的信息,如输入“1 7”,而后会继续输出菜单,如图所示4)选“e”,推出程序,如图所示4.4.2分析1.本次作业的核心是利用弗洛伊德算法计算给定图中两点最短距离;给出图中所要求点的信息。在调试过程中,除了简单语法错误外,就是对弗洛伊德算法的理解和实现,以及菜单的设置,这是我以前没有实现过的。出于简单化,并没有对有向图中各个点进行输入,而是在程序中直接赋值。2.在对各个功能操作的实现上,由于有弗洛伊德算法时间复杂度大多数是O(n3),空间上增加了二维数组,空间复杂度为O(n+s)。4.5 附录Map.h#include #include /#include #define MAX_VERTEX

20、_NUM 10#define INFINITY 10000000typedef struct char name100;int number;char introduce100;Vertex;Vertex vertexMAX_VERTEX_NUM;int distMAX_VERTEX_NUMMAX_VERTEX_NUM;int shortestMAX_VERTEX_NUMMAX_VERTEX_NUM;int pathMAX_VERTEX_NUMMAX_VERTEX_NUM;void map()printf( the science and technology of Shandong univ

21、ersity mapn);printf(nn);printf( (1)Area C dormitory building-(2)Area A dormitory building-(3)Area B dormitory buildingn);printf( | | | n);printf( | | | n);printf( | | | n);printf( (4)Area C restaurant -(5)Area A restaurant-(6)Area B restaurantn);printf( | | | n);printf( | | | n);printf( | | | n);pri

22、ntf( (7)library-(8)No. 1 teaching building-(9)No. 13 teaching buildingn); printf(nnn);void init()int i, j;vertex1.number = 1;strcpy(,Area C dormitory building); strcpy(roduce, Area C student rest area); vertex2.number = 2; strcpy(, Area A dormitory building); strcp

23、y(roduce,Area A student rest area); vertex3.number = 3; strcpy(, Area B dormitory building); strcpy(roduce,Area B student rest area); vertex4.number = 4; strcpy(, Area C restaurant); strcpy(roduce,Area C student dining area); vertex5.number =

24、5; strcpy(,Area A restaurant); strcpy(roduce,Area A student dining area); vertex6.number = 6; strcpy(,Area B restaurant); strcpy(roduce,Area B student dining area); vertex7.number = 7; strcpy(,library); strcpy(roduce,Student borrow

25、ing books area); /*vertex7.number = 8; strcpy(,Area A restaurant); strcpy(roduce,Area A student dining area);*/ vertex8.number = 8; strcpy(,No. 1 teaching building); strcpy(roduce,Students in class area); vertex9.number = 9; strcpy(,No. 13 te

26、aching building); strcpy(roduce,Information institute, college building); for(i = 1; i MAX_VERTEX_NUM; +i) for(j = 1; j MAX_VERTEX_NUM; +j) distij = INFINITY; for(i = 1; i MAX_VERTEX_NUM; +i) distii = 0; dist12 = dist21 = 20; dist23 = dist32 = 40; dist14 = dist41 = 50; dist25 = dist52 = 3

27、0; dist36 = dist63 = 50; dist45 = dist54 = 70; dist56 = dist65 = 90; dist47 = dist74 = 100; dist58 = dist85 = 120; dist69 = dist96 = 80; dist78 = dist87 = 60; dist89 = dist98 =120;void Information()int number;while(1)printf(Please enter the number of query site:);scanf(%d,&number);if(number 0)printf

28、(nname: %snintroduction:%sn,,roduce);return;elseprintf(input error!n);void floyd()/*弗洛伊德算法*/int i, j, u;for(i = 1; i MAX_VERTEX_NUM; +i)for(j = 1; j MAX_VERTEX_NUM; +j)shortestij = distij;pathij = 0;for(u = 1; u MAX_VERTEX_NUM; +u)for(i = 1; i MAX_VERTEX_NUM; +i)for(

29、j = 1; j (shortestiu + shortestuj)shortestij = shortestiu + shortestuj;pathij = pathji = u;void Path(int i, int j)/*最短路径的输出*/int u = 0;int a,b;a = i;b = j;/printf(=1n);if(shortestij != INFINITY)/printf(=2n);printf(nThe shortest path from %s to %s is:nn,,);printf(%s,vertexi.na

30、me);while(pathij != 0)u = pathij;while(pathiu != 0) u = pathiu;printf(-%s,);i = u;printf(-%s;n,);printf(nThe shortest distance is:%d meters.n,shortestab);void shortestpath()int i, j;while(1)printf(Please enter the number two to query :);scanf(%d%d, &i, &j);if(i 0 & i 0 & j MAX_VERTEX_NUM)floyd();/printf(=n);Path(i,j);return;Map.c#include #include int main

温馨提示

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

评论

0/150

提交评论