校园导航系统源代码
- 格式:docx
- 大小:19.42 KB
- 文档页数:13
#1 数据结构实验之校园导游咨询#include<stdlib.h>#include<stdio.h>#include<iostream.h>#include<string.h>#include<math.h>#include "stdio.h"#define null 0#define num 20#define maxdist 10000typedef struct{char data[num];int edges[num][num];}graph;void dijkstra(graph g,int n,int i,int d[num],int p[num]) {int s[num];int mindist,dist;int j,k,u;for(j=0;j<n;j++){d[j]=g.edges[i][j];s[j]=0;if((d[j]<maxdist)&&(d[j]!=0)) p[j]=i;elsep[j]=-1;}s[i]=1;for(j=0;j<n-1;j++){mindist=maxdist;u=i;for(k=0;k<n;k++)if((s[k]==0)&&(d[k]<mindist)) {u=k;mindist=d[k];}s[u]=1;for(k=0;k<n;k++)if(s[k]==0){dist=d[u]+g.edges[u][k];if(dist<d[k]){d[k]=dist;p[k]=u;}}}void opdijk(int v0,int n,int d[],int p[]) {int i,pre;for(i=0;i<n;i++)if(i!=v0){printf("\n%d",i);pre=p[i];while(pre!=-1){printf("<--%d",pre);/****************************/ pre=p[pre]; }if(d[i]==maxdist)printf("<--%d",v0);printf("\tshortestway:%d",d[i]);}}void floyd(graph g,int n,int d[][num],int p[][num]){int i,j,k;for(i=0;i<n;i++)for(j=0;j<n;j++){d[i][j]=g.edges[i][j];if((d[i][j]<maxdist)&&(d[i][j]!=0))p[i][j]=j;elsep[i][j]=-1;}for(i=0;i<n;i++)d[i][i]=0;for(k=0;k<n;k++)for(i=0;i<n;i++)for(j=0;j<n;j++)if(d[i][j]>d[i][k]+d[k][j]){d[i][j]=d[i][k]+d[k][j] ;p[i][j]=p[i][k];}}void opfloy(int n,int d[][num],int path[][num]) {int i,j,next;for(i=0;i<n;i++){printf("\n\nyuandian is v%d:",i);for(j=0;j<n;j++){printf("\nthe shortest way from%dto%dis:\n",i,j);printf("%d",i);next=path[i][j];while(next!=-1){printf("->%d",next);next=path[next][j];}if(d[i][j]==maxdist)printf("<-%d",j);/***************************/ printf("\t%d",d[i][j]);}}}void main(){graph g;int i,j,k,n;int d[num],p[num],sd[num][num],sp[num][num];//clrscr();n=11;g.data[0]='a';g.data[1]='b';g.data[2]='c';g.data[3]='d';g.data[4]='e';g.data[5]='f';g.data[6]='g';g.data[7]='h';g.data[8]='i';g.data[9]='j';g.data[10]='k';for(i=0;i<n;i++)for(j=0;j<n;j++)g.edges[i][j]=maxdist; for(j=0;j<n;j++)g.edges[i][j]=0;g.edges[0][2]=30;g.edges[0][5]=40;g.edges[0][1]=20;g.edges[1][5]=60;g.edges[1][4]=40;g.edges[1][6]=30;g.edges[2][3]=35;g.edges[2][7]=40;g.edges[3][10]=20;g.edges[3][8]=15;g.edges[4][9]=30;g.edges[4][8]=35;g.edges[4][10]=10;g.edges[5][10]=10;g.edges[5][8]=45;g.edges[5][2]=20;g.edges[6][0]=70;g.edges[7][0]=50;g.edges[8][9]=20;g.edges[9][1]=55;g.edges[10][0]=125;//clrscr();printf("\t --WELCOME TOU USE GUIDE!!--\n");printf("\t*****************************************\n");printf("\t* *\n");printf("\t*\tINFOMATION-i\tVISIT-v\t\t*\n\t*\t ABOUT ME-a\tQUIT-q\t\t*\n");printf("\t*\t\t\t\t\t*\n\t*\t\t\t\t\t*\n\t*\t\t\t\t\t*\n\t*\t\t\t\t\t*\n \t*\t\t\t\t\t*\n");printf("\t*****************************************\n");printf("\t*PLEASE ENTER AN ORDER:i? v? m? q?\t*\n");printf("\t*CLEAR THE SCREEN:c\t\t3\t*\n");printf("\t*****************************************\n");do{/*gets(t);*/switch(getchar()){case'a':{printf("NAME:****** CLASS:02computer(3)\n"); printf("PRIVATE EMAIL:devo800@\n"); }break;/* case'g':{FILE *tp;*//* break; */case'i':{FILE *tp;char ch;if((tp=fopen("d:\\info.txt","rt"))==null) {printf("\ncan't open!");getchar();exit(1);}ch=fgetc(tp);while(ch!=EOF){putchar(ch);ch=fgetc(tp);}fclose(tp);}break;case'c':break;case'v':{do{printf("\nINPUT JIE DIAN(0-10):\n"); scanf("%d",&i);{dijkstra(g,n,i,d,p);printf("\n\nyuandian is v%d:",i); opdijk(i,n,d,p);}}while(1);}break;default: exit(1);}}while(getchar());getchar();}*--------------------校园导游系统------------------*/#include<stdio.h>#include<process.h>#define INT_MAX 1000000#define n 10int cost[n][n];//边的值int shortest[n][n];//两点间的最短距离int path[n][n];//经过的景点的;void floyed();int display(int i,int j);void introduce()//introduce of the palce{ int a;printf("Place 1:凯旋门\n"); printf("Place 2:图书馆\n");printf("Place 3:行政楼\n"); printf("Place 4:飞翔门\n"); printf("Place 5:大广场\n");printf("Place 6:ABC教学楼\n"); printf("Place 7:体育场\n"); printf("Place 8:月亮湾\n"); printf("Place 9:English Coner\n"); printf("Place 10:树人广场\n");do{printf("您想查询哪个景点的详细信息?请输入景点编号:");scanf("%d",&a);getchar();switch(a){case 1:。
#include<stdio.h>#include<stdlib.h>#include<dos.h>#include<windows.h>#include<malloc.h>#define Max 100#define N 9//景点个数。
typedef int AdjMatrix[Max][Max];typedef struct{int vexs[Max];AdjMatrix arcs;}Matrix_Graph;//图的矩阵表示法。
void menu();//景点名、操作提示。
void creat(Matrix_Graph *G);//图的建立。
void path(Matrix_Graph G,int s,int e);//两景点之间最短的路径,s表示起始景点,e //最终到达景点。
#define Max 100#define N 9void menu(){printf("1---南大门\n");printf("2---老师办公室\n");printf("3---图书馆\n");printf("4---一号教学楼\n");printf("5---宿舍\n");printf("6---食堂\n");printf("7---北大门\n");printf("8---44号教学楼\n");printf("9---学校广场\n");printf("\n菜单:\n");printf("请选择位置对应数字项目:\n");printf("1----介绍\n");printf("2----路径\n");printf("0----退出\n");}void creat(Matrix_Graph *G){int i,j;for(i=1;i<=N;i++) G->vexs[i]=i;//初始化,0号位不用。
一、问题描述及基本要求【问题描述】设计一个校园导游程序,为来访的客人提供各种信息查询服务。
【基本要求】(1)设计你的学校的校园平面图,所含景点不少于10个。
以图中顶点表示学校各景点,存放景点名称、代号、简介等信息;以边表示路径,存放路径长度等相关信息。
(2)为来访客人提供图中任意景点的问路查询,即查询任意两个景点之间的一条最短的简单路径。
(3)为来访客人提供图中任意景点相关信息的查询。
【测试数据】由读者根据实际情况指定。
【实现提示】一般情况下,校园的道路是双向通行的,可设校园平面图是一个无向网。
顶点和边均含有相关信息。
二、数据结构(1)typedef struct VData{int num;char name[20];char jieshao[100];}VData;(2)typedef struct ANode{int adj;}ANode;(3)typedef struct{VData vertex[maxnum];ANode arcs[maxnum][maxnum];int vexnum,arcnum;}AdjM;三、重点设计及代码(1)两个景点之间的全部路径void DFS_path(AdjM g, int m,int n,int k){int s;if(pre[k]==n && k<11){for(s=0;s<k;s++)printf("% ->",g.vertex[pre[s]].name);printf("%s",g.vertex[pre[s]].name); ,此时s==k)printf("\n\n");}else{s=0;while(s<g.vexnum) {if((g.arcs[pre[k]][s].adj<INFINITY) && (visited[s]==0)){visited[s]=1;pre[k+1]=s;DFS_path(g,m,n,k+1);visited[s]=0;}s++;}}}void all_path(AdjM g){int i,m,n;printf("\n\n请输入你要查询的两个景点编号:\n\n");scanf("%d %d",&m,&n);printf("\n\n");pre[0]=m;for(i=0;i<g.vexnum;i++)visited[i]=0;visited[m]=1;DFS_path(g,m,n,0);}(2)任意两个地点之间最短路径算法ShortestPath_Floyd(AdjM *g) {int i,k,j,l,flag=1,path[maxnum][maxnum][maxnum],dist[maxnum][maxnum]; printf("景点编号如下:\n");for(i=0;i<g->vexnum;i++)printf(" %-4d %-15s\n",i,g->vertex[i].name);for(i=0;i<g->vexnum;i++)for(j=0;j<g->vexnum;j++){dist[i][j]=g->arcs[i][j].adj;for(l=0;l<g->vexnum;l++)path[i][j][l]=0;if(dist[i][j]<INFINITY){path[i][j][i]=1;path[i][j][j]=1;}}for(i=0;i<g->vexnum;i++)for(j=0;j<g->vexnum;j++)for(l=0;l<g->vexnum;l++)if(dist[j][i]+dist[i][l]<dist[j][l]){dist[j][l]=dist[j][i]+dist[i][l];for(k=0;k<g->vexnum;k++)path[j][l][k]=path[j][i][k]+path[i][l][k];}while(flag==1){printf("请输入出发地和目的地:");scanf("%d %d",&k,&j);if(k>=0&&k<g->vexnum&&j>=0&&j<g->vexnum) flag=0;}printf("%s",g->vertex[k].name);for(l=0;l<g->vexnum;l++)if(path[k][j][l]&&k!=l&&j!=l)printf(">>>>>%s",g->vertex[l].name);printf(">>>>>%s",g->vertex[j].name);printf(" 总路线长%d米\n",dist[k][j]);}四、源代码#include<stdio.h>#include<stdlib.h>#include<conio.h>#include<string.h>#define maxnum 15#define INFINITY 32768int pre[maxnum];int visited[maxnum];typedef struct VData{int num;char name[20];char jieshao[100];}VData;typedef struct ANode{int adj;}ANode;typedef struct{VData vertex[maxnum];ANode arcs[maxnum][maxnum];int vexnum,arcnum;}AdjM;AdjM CreatUDN(void){int i,j;AdjM g;g.vexnum=14;g.arcnum=30;g.vertex[0].num=0;strcpy(g.vertex[0].name,"学校主大门");strcpy(g.vertex[0].jieshao,"南京信息工程大学主大门气势恢宏,是进入大学的主要通道。
基于QT的校园导航系统的设计与实现摘要本文主要是介绍利用Linux系统和QT制作校园导航系统的设计方法。
使用的操作系统是Linux系统,但是在windows系统下也是可以使用的,所使用的语言是c++,开发工具是QT。
设计的主要目的是能够简单地观看整个校园的风景,使不熟悉校园的人能够知道每个景点的位置、介绍,查看学校的建筑物,包括建筑物的图片以及建筑物的描述。
尤其,这个系统可以找出两个建筑物之间最短的距离,从而迅速地帮助不熟悉校园的人了解整个校园环境,然后找到最好的方法去参观整个校园,除此之外,该系统还可以查询两个景点之间的所有路径,有助于来往者跟好的选择路径。
导航系统是在Linux系统(Linux 下开发,windows下也可以运行)下,先利用QT制作出用户界面,再利用C++编程语言设计出基本功能并与界面相结合。
本文设计的导航系统能够实现以下三大功能:第一,它可以测量两个建筑物之间的距离,同时在查询两个景点之间的路径信息的同时,提供起始点与终点建筑物的图片信息,便于更好的确认;第二,它可以帮助来访者从众多的路线中选出最短的一条,同时会提供两点之间的所有路径;第三,它可以在标志性建筑添加一些描述信息和图片,还可以查看从该建筑物到所有其他建筑物的路径信息。
关键词路径规划;最短路径算法;校园导航;qtThe school navigate system based on Linuxand Qt CreatorAbstractMainly introduced in this paper using the Linux system and QT campus navigation system design method. Use of the operating system is Linux system, but also can use under Windows system, the language is used by c + +, development tools is QT.The main purpose of design is to be able to simply watch the scenery of the whole campus, who is familiar with the campus can know the location of each scenic spot, introduction, see the school buildings, including the structure of the pictures and the description of the building. Especially, the system can find out the shortest distance between two buildings, so as to help people who are not familiar with the campus rapidly understand the campus environment, and find the best way to visit the whole campus, in addition, the system can also query all paths between two spots, help going back and forth with good choice path. Navigation system is in the Linux system (under Linux development, also can run under Windows), the first user produced using QT, using c + + programming language basic design. Function and combining with the interface.The navigation system is designed in this paper can achieve the following three functions: first, it can measure the distance between the two buildings, at the same time the query path information between two sites at the same time, provide the picture of the starting point and end point building information, to facilitate better confirmation; Second, it can help visitors from many choose the shortest route, at the same time will provide all the path between two points; Third, it can add some description in landmark information and pictures, you can also view from the building to all the other path information of the building.Key words path planning; ant algorithm; the campus navigation; qt目录摘要 (i)Abstract .................................................................................................................................... i i 1 绪论 .. (1)1.1概述 (1)1.2研究背景 (1)1.3研究目标 (1)1.4本章小结 (1)2 QT简介 (2)2.1 QT的背景介绍 (2)2.2 QT实现的结构原理 (2)2.3 QT QWidget简介 (3)2.3.1 详细描述 (3)2.3.2 QWidget 事件简介 (4)2.4 QT应用程序的实现 (6)2.5 本章小结 (7)3 需求分析 (8)3.1 需求分析概述 (8)3.2 需求分析的特点 (8)3.3 需求分析需要完成的任务 (8)3.4 实际需求分析 (9)3.4.1 用户需求分析 (9)3.4.2 功能需求分析 (9)3.4.3 实际需求分析 (9)3.4.4 系统性能需求分析 (9)3.5 本章小结 (10)4 总体设计 (11)4.1 总体设计概述 (11)4.2 系统总体设计描述 (11)4.3 系统总体设计模块划分 (11)4.3.1 主要模块划分图 (12)4.3.2 显示系统主界面模块设计 (12)4.3.3 查询导航有关人员模块设计 (13)4.3.4 导航主界面的模块的设计 (13)4.4 本章总结 (14)5 详细设计 (15)5.1 详细设计概述 (15)5.2 校园导航系统主程序流程图 (15)5.3 单源最短路径算法介绍 (16)5.3.1 Dijkstra(迪杰斯特拉)算法 (16)5.3.2 floyed(弗洛耶德)算法 (17)5.4 图中节点与路径的存储 (19)5.4.1 节点的存储 (19)5.4.2 节点间路径长度的存储 (19)5.4.3 整个图的存储 (20)5.5本章总结 (20)6 系统实现及运行结果 (21)6.1 界面设计 (21)6.1.1 主窗体设计 (21)6.1.2 子页面布局设计 (24)6.1.3 更换起始点的实现 (27)6.1.4 点击主页面中的查询路径具体实现 (29)6.1.5 点击查看景点信息描述的实现 (29)6.2 图的创建 (31)6.3 路径查询的具体实现 (31)6.3.1 单源最短路径算法具体实现 (32)6.3.2 所有可达路径的查询的具体实现 (33)6.3.3 每一个点到它可达的所有点的查询的具体实现 (33)6.4 选择系统是否退出的具体实现 (34)6.5 本章小结 (35)7 测试 (36)7.1 测试目标 (36)7.2 测试预期结果 (36)7.3 测试用例的设计 (36)7.4 本章小结 (38)结论 (39)参考文献 (40)致谢 (41)外文原文 (42)中文翻译 (47)1 绪论1.1概述现在科技越来越发达,手机上的软件,电脑上的软件越来越多,所以开发小的程序也越来越有必要。
Tips:这个系统是学校《⼤数据应⽤开发语⾔》的⼤作业,本身想直接在⽹上copy⼀下,结果发现校园导航系统的c/java等版本很多很多,⽽python版本⾮常之少,于是只能⾃⼰写⼀个简单版本的了。
包含三个模块:查询学校地图模块、查询两点最短路径、查询多路径信息。
@TOC前⾔随着社会经济的发展,政府对教育建设的投资越来越⼤。
众多⾼校开始扩建⼯程,校园占地⾯积⼤,楼宇种类多。
体现出国家对教育的重视程度逐年上升,科教兴国战略时⾸当其冲。
⾯对越来越⼤的学校,“迷路”成为众多⾼校新⽣不得⾯临的话题,这便需要校园导航系统来解决师⽣如何查询楼宇、如何快速到达⽬的地问题。
本系统采取基于Floyd算法来完成查询两点最短路径、查询多路径信息等问题。
⼀、题⽬功能描述:设计你的学校的校园景点,所含景点不少于10个.有景点名称,代号,简介等信息; 为来访客⼈提供图中任意景点相关信息的查询.测试数据:由读者根据实际情况指定.⼆、需求分析1.要求(1)⽤Python语⾔实现程序设计;(2)进⾏相关信息处理;(3)画出查询模块的流程图;(4)系统的各个功能模块要求⽤函数的形式实现;(5)界⾯友好(良好的⼈机互交),程序要有注释。
2.运⾏环境(1)MacOS Big Sur 11.6.2系统(2)PyCharm CE 20213.开发语⾔⼤数据开发语⾔(Python)三、概要设计1.系统流程图2.函数流程图四、详细设计1.类的分析与设计定义⼀个Attractions 类来实现输⼊和存放景点编号、名称。
定义⼀个Campus 类来存放校园⽆向图的边和节点,并给各结点定义名称。
定义⼀个Passing 类来存放路径栈、路径数、栈顶数class Attractions : num = 0 #景点编号 name = '' #景点名称class Campus :att = ["","南⼤⻔","⾏政楼","三号楼","四号楼","图书馆","⻄⼤⻔","7号楼","⼋号楼","九号楼","操场","体育馆","⼤操场"] #景点 edges = [[INF ] * M ] * M #边 Nodes_Num = 0edges_Num = 0 #总结点数,总边数class passing():pathStack= [[0]*M] ##路径栈top=0count=0 #栈顶位置,路径数visited= [[False]*M] #判断是否已经经过定义⼀个DIS类来存放path路径和distence⽬的地。
校园导航系统源代码(总9页)--本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--#define INFINITY 10000#define MAX_VERTEX_NUM 40#define MAX 40#include<>#include<>#include<>#include<>typedef struct ArCell{int adj; /*路径长度 */}ArCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];typedef struct/*图中顶点表示主要景点,存放景点的编号、名称、简介等信息, */{char name[30];int num;char introduction[100];/*简介*/}infotype;typedef struct{infotype vexs[MAX_VERTEX_NUM];AdjMatrix arcs;int vexnum,arcnum;}MGraph;MGraph b;void cmd(void);MGraph InitGraph(void);void show1();void list();void Menu(void);void ShortestPath_DIJ(MGraph * G);void Search(MGraph *G);int LocateVex(MGraph *G,char* v);/**********主函数************************/void main(void){system("color 5f"); /*修改控制台的颜色信息,改为白字蓝底的模式*/ system("mode con: cols=140 lines=130"); /*设置批处理运行时窗口大小的*/cmd();}/********自定义函数***************//* cmd函数(根据目录选择要进行的项目)*/void cmd(void){char k;b=InitGraph();show1();Menu();while(1){scanf("\n%c",&k);switch(k){case'x':system("cls");show1();Menu();list();ShortestPath_DIJ(&b);printf("---------------------------------欢迎您的使用--------------------------------\n");printf("\n请您继续选择服务:");break;case'y':system("cls");Menu();list();Search(&b);printf("---------------------------------欢迎您的使用--------------------------------\n");printf("\n请您继续选择服务:");break;case'z':system("cls");printf(" ┏━━━━━━━━━━━━━━━━━━━━┓\n");printf(" ┃感谢使用┃\n");printf(" ┃安徽建筑术大学┃\n");printf(" ┃智能导航系统┃\n");printf(" ┗━━━━━━━━━━━━━━━━━━━━┛\n");exit(0);default:printf("输入信息错误!\n请输入x或y或z.\n");break;}}}/* 迪杰斯特拉算法来计算出起点到各个顶点之间的最短路径,v0为起点 */ void ShortestPath_DIJ(MGraph * G){int v,w,i,min,t=0,x,flag=1,v0,v1,have[100],k;int final[20], D[20], p[23][23];while(flag){printf("请输入起始景点编号:\n");scanf("%d",&v0);if(v0<0||v0>G->vexnum)printf("景点编号不存在!");printf("请输入终止景点编号:\n");scanf("%d",&v1);if(v1<0||v1>G->vexnum)printf("景点编号不存在!");if(v0>=0&&v0<G->vexnum&&v1>=0&&v1<G->vexnum)flag=0;}for(v=0;v<G->vexnum;++v){final[v]=0;D[v]=G->arcs[v0][v].adj;for(w=0;w<G->vexnum;++w)p[v][w]=INFINITY;if(D[v]<INFINITY){p[v][v0]=1;p[v][v]=1;}}D[v0]=0;final[v0]=1;have[0]=v0;for(i=1;i<G->vexnum;++i){min=INFINITY;for(w=0;w<G->vexnum;++w)if(!final[w])if(D[w]<min){v=w;min=D[w];}final[v]=1;have[k]=v;k++;for(w=0;w<G->vexnum;++w)if(!final[w]&&((min+(G->arcs[v][w].adj))<D[w])){D[w]=min+G->arcs[v][w].adj;for(x=0;x<G->vexnum;x++)p[w][x]=p[v][x];p[w][w]=1;}}for(i=0;i<G->vexnum;i++){if(p[v1][have[i]]==1){printf("-->%s",G->vexs[have[i]].name);}}if((v1-v0)==1)printf("\n路径长度:%d\n",G->arcs[v0][v1]);else printf("\n路径长度:%d\n",D[v1]);}um,G->vexs[k].name,G->vexs[k].introduction);printf("┗━━┻━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");}择出发点和目的地┃\n");printf(" ┃ y.查看景点信息┃\n");printf(" ┃ z.退出系统┃\n");printf(" ┗━━━━━━━━━━━━━━━━━━━━┛\n");printf("请选择服务");}/*MGraph函数(图的构建)*/MGraph InitGraph(void){MGraph G;int i,j;=17; um=i;strcpy[0].name,"学校北门");strcpy[0].introduction,"学校的正门,气势宏伟");strcpy[1].name,"宿舍楼1");strcpy[1].introduction,"睡觉的地方");strcpy[2].name,"宿舍楼2");strcpy[2].introduction,"睡觉的地方");strcpy[3].name,"宿舍楼15");strcpy[3].introduction,",,,,,,,,");strcpy[4].name,"九月桥");strcpy[4].introduction,"连接生活区和教学区的桥。
Java实现的具有GUI的校园导航系统0.写在前⾯2020-5-18 更新这个东西已经是两年前的了,现在问我具体细节我也不是很清楚了,⽽且现在review两年前的代码感觉写的好烂。
请⼤家有问题下⾯留⾔,不要加我的企鹅了,正在准备考研,⽐较忙。
⼀点建议:1.当时会的⽐较少,对象实例化对于单纯的数据查询来说效率极低⽽且很蠢,我现在更建议使⽤数据库,或者简单点⽤xml or json都可以,建议想写的好⼀点的同学把⾥⾯的数据读写逻辑改⼀改,⽤数据库不⾹吗2.这个是分客户端服务端的,服务端相当于⽤底层⼿撸了⼀个相当简单的tomcat,所有的界⾯都是要从Client进去的。
先开server再开Client,在注册时以邀请码判断是否为管理员。
以管理员⾝份进⼊client之后再去添加信息。
3.如果注册时报access is denied 在Flie的路径下加⼀层⽂件夹,如下⼩⼀个⽉没更新博客了,主要是临近期末,各科的⼤作业都下来了,今天把⾃⼰奋⽃了⼀个礼拜的校园导航系统贴在上⾯,也算满⾜下⾃⼰的⼩成就感('ᴗ' )و实验要求如下:以我校为例,设计⼀个校园导航系统,主要为来访的客⼈提供信息查询。
系统有两类登陆账号,⼀类是游客,使⽤该系统⽅便校内路线查询;⼀类是管理员,可以使⽤该系统查询校内路线,可对校园景点路线可编辑。
说简单点,就是给定⼀个地图数据,然后地图上有好⼏个点,每个点间有距离,这个程序提供了查询两点间最短路径的功能。
当然,你可以为他增加很多细节,⽐如查看景点信息啊,后台的管理啊等等,这些都是加分项。
⽼师推荐使⽤C,其实题⽬也是这么要求的。
但是使⽤C有⼏个⽐较⿇烦的问题:第⼀,要是只实现基本的功能⽤C的话肯定是没什么问题,但是要是想添枝加叶的话,C的代码就没法看了,写起来⿇烦读起来也难受。
第⼆,地图是有地图数据的,要是⽤C的话⼀般⼈都会直接printf N多⾏的地图吧,这也是⼀个⽐较⿇烦的事⼉。
#define INFINITY 10000#define MAX_VERTEX_NUM 40#define MAX 40#include<stdlib.h>#include<stdio.h>#include<conio.h>#include<string.h>typedef struct ArCell{int adj; /*路径长度 */}ArCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];typedef struct/*图中顶点表示主要景点,存放景点的编号、名称、简介等信息, */{char name[30];int num;char introduction[100];/*简介*/}infotype;typedef struct{infotype vexs[MAX_VERTEX_NUM];AdjMatrix arcs;int vexnum,arcnum;}MGraph;MGraph b;void cmd(void);MGraph InitGraph(void);void show1();void list();void Menu(void);void ShortestPath_DIJ(MGraph * G);void Search(MGraph *G);int LocateVex(MGraph *G,char* v);/**********主函数************************/void main(void){system("color 5f"); /*修改控制台的颜色信息,改为白字蓝底的模式*/ system("mode con: cols=140 lines=130"); /*设置批处理运行时窗口大小的*/ cmd();}/********自定义函数***************//* cmd函数(根据目录选择要进行的项目)*/void cmd(void){char k;b=InitGraph();show1();Menu();while(1){scanf("\n%c",&k);switch(k){case'x':system("cls");show1();Menu();list();ShortestPath_DIJ(&b);printf("---------------------------------欢迎您的使用--------------------------------\n");printf("\n请您继续选择服务:");break;case'y':system("cls");Menu();list();Search(&b);printf("---------------------------------欢迎您的使用--------------------------------\n");printf("\n请您继续选择服务:");break;case'z':system("cls");printf(" ┏━━━━━━━━━━━━━━━━━━━━┓\n");printf(" ┃感谢使用┃\n");printf(" ┃安徽建筑术大学┃\n");printf(" ┃智能导航系统┃\n");printf(" ┗━━━━━━━━━━━━━━━━━━━━┛\n");exit(0);default:printf("输入信息错误!\n请输入x或y或z.\n");break;}}}/* 迪杰斯特拉算法来计算出起点到各个顶点之间的最短路径,v0为起点 */void ShortestPath_DIJ(MGraph * G){int v,w,i,min,t=0,x,flag=1,v0,v1,have[100],k;int final[20], D[20], p[23][23];while(flag){printf("请输入起始景点编号:\n");scanf("%d",&v0);if(v0<0||v0>G->vexnum)printf("景点编号不存在!");printf("请输入终止景点编号:\n");scanf("%d",&v1);if(v1<0||v1>G->vexnum)printf("景点编号不存在!");if(v0>=0&&v0<G->vexnum&&v1>=0&&v1<G->vexnum) flag=0;}for(v=0;v<G->vexnum;++v){final[v]=0;D[v]=G->arcs[v0][v].adj;for(w=0;w<G->vexnum;++w)p[v][w]=INFINITY;if(D[v]<INFINITY){p[v][v0]=1;p[v][v]=1;}}D[v0]=0;final[v0]=1;have[0]=v0;for(i=1;i<G->vexnum;++i){min=INFINITY;for(w=0;w<G->vexnum;++w)if(!final[w])if(D[w]<min){v=w;min=D[w];}final[v]=1;have[k]=v;k++;for(w=0;w<G->vexnum;++w)if(!final[w]&&((min+(G->arcs[v][w].adj))<D[w])){D[w]=min+G->arcs[v][w].adj;for(x=0;x<G->vexnum;x++)p[w][x]=p[v][x];p[w][w]=1;}}for(i=0;i<G->vexnum;i++){if(p[v1][have[i]]==1){printf("-->%s",G->vexs[have[i]].name);} }if((v1-v0)==1)printf("\n路径长度:%d\n",G->arcs[v0][v1]);else printf("\n路径长度:%d\n",D[v1]);}//ShortestPath_DIJ end/*查找函数的建立 */void Search(MGraph *G){int k,flag=1;while(flag){printf("请输入要查询的景点编号:");scanf("%d",&k);if(k<0||k>G->vexnum){printf("景点编号不存在!请重新输入景点编号:");scanf("%d",&k);}if(k>=0&&k<G->vexnum)flag=0;}printf("┏━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");printf("┃编号┃景点名称┃简介┃\n");printf("┃%-4d┃%-16s┃%-58s┃\n",G->vexs[k].num,G->vexs[k].name,G->vexs[k].introduction);printf("┗━━┻━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");}//Search endvoid show1(){ printf("\t\t ★★欢迎使用安徽建筑大学智能导航系统★★\n");printf("\t\t\t安徽建筑大学南校区简略版平面图\n\n");printf("\t 学校北门\n");printf("\t ┃ \n");printf("\t ┏━━北食堂━━━━━━━━━宿舍楼1\n");printf("\t ┃┃\n");printf("\t ┃宿舍楼2\n");printf("\t ┃━━━━━━九月桥━━━━━┃\n");printf("\t ┃┃\n");printf("\t 主教楼┃ \n");printf("\t ┃┃\n");printf("\t 日月广场┃\n");printf("\t ┃┃\n");printf("\t 图书馆┃\n");printf("\t ┃┃\n");printf("\t 还在建┃\n");printf("\t ┃┃\n");printf("\t 南食堂━━━━━━━━━━━━宿舍楼15\n");printf("\t ┃┃\n");printf("\t ┃┃\n");printf("\t ━━━━━━━━━━━━━━南苑超市\n");}void list(){printf("学校景点列表:\n");printf("0:学校北门");printf("1:宿舍楼1 ");printf("2:宿舍楼2 ");printf("3:宿舍楼15 ");printf("4:九月桥\n");printf("5:主教楼 ");printf("6:图书馆 ");printf("7:日月广场 ");printf("8:体育场\n");printf("9:还在建");printf("10:南食堂 ");}/*目录函数的构建*/void Menu(){printf("\n 安徽建筑大学南校区导游图\n");printf(" ┏━━━━━━━━━━━━━━━━━━━━┓\n");printf(" ┃ x.选择出发点和目的地┃\n");printf(" ┃ y.查看景点信息┃\n");printf(" ┃ z.退出系统┃\n");printf(" ┗━━━━━━━━━━━━━━━━━━━━┛\n");printf("请选择服务");}/*MGraph函数(图的构建)*/MGraph InitGraph(void){MGraph G;int i,j;G.vexnum=17; //顶点是17个G.arcnum=25; //弧线有25个for(i=0;i<G.vexnum;i++)G.vexs[i].num=i;strcpy(G.vexs[0].name,"学校北门");strcpy(G.vexs[0].introduction,"学校的正门,气势宏伟");strcpy(G.vexs[1].name,"宿舍楼1");strcpy(G.vexs[1].introduction,"睡觉的地方");strcpy(G.vexs[2].name,"宿舍楼2");strcpy(G.vexs[2].introduction,"睡觉的地方");strcpy(G.vexs[3].name,"宿舍楼15");strcpy(G.vexs[3].introduction,",,,,,,,,");strcpy(G.vexs[4].name,"九月桥");strcpy(G.vexs[4].introduction,"连接生活区和教学区的桥。