1、校园导游程序数据结构课程设计报告姓名:学号:班级:学院: 日期:一、课程设计题目: 校园导游程序二、需求分析问题描述用无向网表示你所在学校的校园景点平面图,图中顶点表示主要景点,存放景点的编号、名称、简介等信息,图中的边表示景点间的道路,存放路径长度等信息。要求 (1) 查询各景点的相关信息;(2) 查询图中任意两个景点间的最短路径。(3) 查询图中任意两个景点间的所有路径。(4) 增加、删除、更新有关景点和道路的信息。三、概要设计主要通过无向图的算法函数来实现校园导游程序设计。即如下函数:(本程序可完成创建景点操作,但不能完成分步的增加、删除、更新有关景点和道路的信息的操作。)typedef
2、 struct ArCellint adj; /路径长度ArCell,AdjMatrixMAX_VERTEX_NUMMAX_VERTEX_NUM;typedef struct /图中顶点表示主要景点,存放景点的编号、名称、简介等信息,char name30;/景点名int num;/编号char introduction100;/简介infotype;typedef structinfotype vexsMAX_VERTEX_NUM;AdjMatrix arcs;/路径int vexnum,arcnum;/结点数,弧度数MGraph; MGraph b;MGraph InitGraph(voi
3、d); /无向图初始化void Browser(MGraph *G);/输出图的景点信息,编号,景点名,景点信息。void ShortestPath_DIJ(MGraph * G);迪杰斯特拉算法来计算出起点到各个顶点之间的最短路径void Floyd(MGraph *G);/计算两景点间的最短路径int LocateVex(MGraph *G,char* v);查找景点MGraph * CreateUDN(MGraph *G);创建新的图景点void print(MGraph *G);输出路径长度void main(void)/主程序 int i; b=InitGraph(); while(
4、i!=5) printf(n 太原工业导游系统 n); printf( 1.浏览校园全境 n); printf( 2.查看所有游览路径 n); printf( 3.选择出发地点和目的地 n); printf( 4.创建新的景点信息n); printf( 5.退出 n); printf(Option-:); scanf(%d,&i); switch(i) /调用操作函数 case 1:system(cls);Browser(&b);break; case 2:system(cls);ShortestPath_DIJ(&b);break; case 3:system(cls);Floyd(&b);
5、break; case 4:system(cls);CreateUDN(&b);break; case 5:exit(1);break; default:break; 四、详细设计以下为函数的内容:MGraph InitGraph(void) MGraph G; int i,j; G.vexnum=10; G.arcnum=14; for(i=0;iG.vexnum;i+) G.vexsi.num=i; strcpy(G.vexs0.name,体育场); strcpy(G.vexs0.introduction,树胶跑道,足球场等体育用地); strcpy(G.vexs1.name,篮球场);
6、strcpy(G.vexs1.introduction,篮球爱好者的天堂); strcpy(G.vexs2.name,主教学楼); strcpy(G.vexs2.introduction,高层建筑,多媒体教室,适宜学习); strcpy(G.vexs3.name,锅炉房); strcpy(G.vexs3.introduction,长期供热水,冬日供暖); strcpy(G.vexs4.name, 东区食堂); strcpy(G.vexs4.introduction, 标准食堂建筑); strcpy(G.vexs5.name,实验楼); strcpy(G.vexs5.introduction,实
7、验重地,科研开发); strcpy(G.vexs6.name, 办公楼); strcpy(G.vexs6.introduction, 教师办公室和学校部门); strcpy(G.vexs7.name, 图书馆); strcpy(G.vexs7.introduction, 藏书60万册,设施良好,2楼为电子阅览室,环境幽雅); strcpy(G.vexs8.name, 沁园); strcpy(G.vexs8.introduction,绿树成荫,适宜休息和读书); strcpy(G.vexs9.name,西区食堂); strcpy(G.vexs9.introduction, 标准食堂建筑); fo
8、r(i=0;iG.vexnum;i+) for(j=0;jG.vexnum;j+) G.arcsij.adj=INFINITY; G.arcs01.adj=20; G.arcs12.adj=200; G.arcs23.adj=80; G.arcs24.adj=150; G.arcs34.adj=100; G.arcs35.adj=220; G.arcs36.adj=220; G.arcs57.adj=140; G.arcs56.adj=100; G.arcs58.adj=350; G.arcs68.adj=80; G.arcs67.adj=170; G.arcs79.adj=70; G.arc
9、s89.adj=70; for(i=0;iG.vexnum;i+) for(j=0;jG.vexnum;j+) G.arcsji.adj=G.arcsij.adj; return G;/InitGraph endvoid Browser(MGraph *G) int v;printf( 编号 景点名称 简介 n); for(v=0;vvexnum;v+) printf( %-4d %-16s %-56s n,G-vexsv.num,G-vexsv.name,G-vexsv.introduction);void ShortestPath_DIJ(MGraph * G) int v,w,i,min
10、,t=0,x,flag=1,v0; int final20, D20, p2020; while(flag) printf(请输入一个起始景点编号:); scanf(%d,&v0); if(v0G-vexnum) printf(景点编号不存在!请重新输入景点编号:); scanf(%d,&v0); if(v0=0&v0vexnum) flag=0; for(v=0;vvexnum;v+) finalv=0; Dv=G-arcsv0v.adj; for(w=0;wvexnum;w+) pvw=0; if(DvINFINITY) pvv0=1; pvv=1; Dv0=0;finalv0=1; fo
11、r(i=1;ivexnum;i+) min=INFINITY; for(w=0;wvexnum;w+) if(!finalw) if(Dwmin)v=w;min=Dw; finalv=1; for(w=0;wvexnum;w+) if(!finalw&(min+G-arcsvw.adjarcsvw.adj; for(x=0;xvexnum;x+) pwx=pvx; pww=1; for(v=0;vvexnum;v+) if(v0!=v) printf(%s,G-vexsv0.name); for(w=0;wvexnum;w+) if(pvw&w!=v0) printf(-%s,G-vexsw.
12、name); t+; if(tG-vexnum-1&v0!=v)printf( 总路线长%dmnn,Dv); /ShortestPath_DIJ endvoid Floyd(MGraph *G) int v,u,i,w,k,j,flag=1,p101010,D1010; for(v=0;vvexnum;v+) for(w=0;wvexnum;w+) Dvw=G-arcsvw.adj; for(u=0;uvexnum;u+) pvwu=0; if(DvwINFINITY) pvwv=1;pvww=1; for(u=0;uvexnum;u+) for(v=0;vvexnum;v+) for(w=0;wvexnum;w+) if(Dvu+DuwDvw) Dvw=Dvu+Duw; for(i=0;ivexnum;i+) pvwi=pvui|puwi; while(flag) printf(请输入出发点和目的地的编号:); scanf(%d%d,&k,&j); if(kG-vexnum|jG-vexnum) printf(景点编号不存在!请重新输入出发点和目的地的编号:); scanf(%d%d,&k,&j); if(k=0&kvexnum&j=0&jvexnum) flag=0; printf(%s,G-vexsk.name); for(u=0;uvexnum;u+)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1