Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C language to realize Campus Tour Guide system

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use C language to realize the campus tour guide system, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.

Design purpose

China has a vast land and abundant resources, profound cultural heritage, rich and colorful tourism resources, and the "university punching fever" is becoming more and more popular. Many university campuses in China have become "scenic spots" for tourists to sign in. In order to provide more convenient and quick service information for tourists visiting Xi'an University of posts and Telecommunications, and to provide students with suitable walking routes. Therefore, the development of "Xi'an University of posts and Telecommunications Campus Navigation system" to provide better services for tourists and students.

The theme of this course is campus navigation system, the main purpose of which is to combine students' theoretical knowledge with practical application, so as to prevent students from "talking on paper". Experience the design process of practical application to cultivate students' ability to think independently and deal with specific problems. The theory is single, but the practical application problems are changeable, even in conflict with the theory. How to meet the needs of practical problems and deal with the conflict between theory and application is what every student should learn.

For the developers of the "campus navigation system", that is, the students themselves, the improvement of their ability is mainly divided into the following points:

① deepens its understanding of the logical structure of data like "graph" in its mind.

② requires students to be proficient in the creation of adjacency matrix and adjacency table of "graph".

③ writes code independently to improve students' logical thinking ability.

④ knows how to use some of the most basic "graph" operations.

Design content

The functions of the system are all divided into two groups: management and tourists.

① visitor rights include: display the basic information of the map, query the basic information of the traffic route of a location, query the least transit path between the two places, simple path, shortest path and so on.

After the ② manager logs in, in addition to using all the permissions of the user, he can also exercise the advanced permissions of the map system, such as adding new vertices, adding new routes, revoking old routes, and so on.

The following picture shows the plan of the campus navigation system:

Functional module diagram

< 0 || s == e){ printf( "\t\t\t\t\t\t输入错误!\n\n" ); } else{ ClearVisited(&G); //给标志数组初始化 count1=0; printf("\n\t\t\t从%s到%s的所有简单路径有:\n", G.vex[s].name, G.vex[e].name); DfsAll(&G,s,e); //调用函数进行实现功能 } printf("\n\n\t\t\t\t\t\t是否继续查询所有简单路径?\n" ); printf("\t\t\t\t\t\t1:是\n" ); printf("\t\t\t\t\t\t0:返回上级菜单\n" ); scanf("%d", &flag); } system("cls");}//中转最少 ,也可以用广搜,顶点A到顶点B所含边的数目最少的路线,从A出发广度优先遍历,遇到顶点B就可以停止了 void DfsLitter(AdjMatrix *G,int start,int end){ int shuai = 0; int i,j; G->

Vex.visited = 1; way2 [count2] = start; for (I = 1; I vexnum; iTunes +) {if (G-> arcs [start] [I]! = INFINITY & & G-> vex [I] .visited = = 0 & & I! = end) {count2++; way2 [count2] = I; DfsLitter / / Recursive G-> vex.visited = 0; count2--; shuai = 0; continue;} / / all paths were found at this time if (G-> arcs [start] [I]! = INFINITY & & G-> vex.visited = = 0 & & I = = end & & shuai = = 0) {count2++ Way2 [count2] = end; shuai = 1; if (count2

< minc){ //如果count2比最大顶点数小 minc = count2; //就赋值 for(i = 0; i G.vexnum || s G.vexnum || e < 0 || s == e) printf("\t\t\t\t\t\t输入错误!\n\n"); else{ ClearVisited(&G); minc = MAXVEX; count2 = 0; printf("\n\t\t\t从%s到%s的中转最少简单路径为:\n", G.vex[s].name, G.vex[e].name); DfsLitter(&G,s,e); //深搜寻找 printf("\t\t\t%5s ",G.vex[minway[0]].name); for(i = 1; i arcs[s][i]; //将邻接数组每一行所对应的列的值填入dist数组中 if(G->

Arcs [s] [I]! = INFINITY) {/ / if the weight is not equal to infinity, then there is a path path [I] [1] = s; / / record the starting point, path [I] record each vertex on the shortest path from the source point to Vi} path [s] [0] = 1; / / set the flag indicating that the source point is start for (I = 2; I vexnum) Find the shortest paths mindist = INFINITY; / / set the minimum initial value to infinite for (j = 1; j vexnum; jacks +) {/ / choose the path with the lowest weight if (! path [j] [0] & & dist [j])

< mindist){//j未加入集合S //path数组记录某定点是否加到S中 k = j; //当前起点到顶点k权值最小 mindist = dist[j]; } } if(mindist == INFINITY){ return; //不存在start到其他顶点的路径 } path[k][0] = 1; // 将顶点k加入到集合S中,说明该顶点已经被考察 //看有没有更小的,进而更新修改路径 for(j = 1;j vexnum; j++){ //修改路径 if(!path[j][0] && G->

Arcs [k] [j] arcs [k] [j]

< dist[j]){ //第k行有路且未被选中过的顶点 &&到k的最小权值+k到j的权值arcs[k][j]; t = 1; while(path[k][t] != 0){ //记录最新的最短路径 path[j][t] = path[k][t]; t++; } path[j][t] = k; path[j][t+1] = 0; } } }}//打印两点间的最短路径void DijkstraPrint(int start, int end ,AdjMatrix G,int path[][MAXVEX]){ int i = 2; int length = 0; printf( "\n\t从%s到%s的最短路径是:", G.vex[start].name, G.vex[end].name ); printf( " %s", G.vex[start].name ); while(path[end][i]){ //记录的路径 printf("-->

% s ", G.vex [path [end] [I] .name); length + = G.arcs [end] [I]] [path [path] [I]]; iTunes;} printf ("->% s ", G.vex [end] .name); length + = G.arcs [end] [iMur1]] [name]; printf (", length is% dM ", length) Printf ("\ n");} / / the shortest path of the sub-menu void ShortPath (AdjMatrix Gpenint dist [], int path [] [MAXVEX]) {int iGraint dist [] [MAXVEX]; int flag = 1; while (flag = = 1) {system ("cls"); printf ("\ t\ t-shortest path query -\ n") PrintPlace (& G); printf ("\ n\ t\ t enter the starting point number:"); scanf ("% d", & s); printf ("\ t\ t input end point number:"); scanf ("% d", & e); if (s > G.vexnum | | s G.vexnum | | e

< 0 || s == e){ printf("\t\t\t\t\t\t输入错误!\n\n"); } else{ ClearVisited(&G); //菜单 Dijkstra(&G,s,e,dist,path); //算法 DijkstraPrint(s,e,G,path);//打印 } printf("\n\t\t\t\t\t\t是否继续查询最短路径?\n"); printf("\t\t\t\t\t\t1:是\n"); printf("\t\t\t\t\t\t0:返回上级菜单\n"); scanf("%d",&flag); } system("cls");}//路径二级主菜单 void SearchPath(AdjMatrix G,int dist[],int path[][MAXVEX]){ int x,flag = 1; while(flag == 1){ //二级菜单 printf("\t\t\t1. 所有简单路径\n"); //各顶点均不重复 printf("\t\t\t2. 最短的简单路径(中转最少)\n"); printf("\t\t\t3. 最佳访问路径(最短路径长度)\n"); printf("\t\t\t0. 返回主菜单\n"); printf("\t\t\t请选择您需要的操作:"); scanf("%d",&x); switch(x){ case 1: system("cls");AllPath(G,dist,path);break; case 2: system("cls");LitterPath(G);break; case 3: system("cls");ShortPath(G,dist,path);break; case 0: flag = 0; break; default:printf( "\t\t\t\t\t\t\t输入信息错误,请重新输入!\n" ); break; } system("cls"); }}//注册信息void enroll(){ char a[100]; //注册用户名 char b[100]; //注册密码 char s[100]; //再次确定密码 int len; printf("请输入您的用户名:"); scanf("%s",a); printf("请设置您的密码:"); reset: scanf("%s",b); //用到了if goto语句 len = strlen(b); //读取密码长度 if(len >

9) {printf ("password is too long, please reset:"); goto reset; / / if goto statement} printf ("Please enter the password you set again:"); scanf ("% s", s); if (strcmp (bforce s) = = 0) {/ / string comparison function FILE * fp Fp=fopen ("register.txt", "at"); / / choose the append method to store multiple messages if (fp= = NULL) {printf ("File does not exist or please register first!"); exit (1) } fprintf (fp, "% s% s\ n", a fp b); / / string write function to perform write operation system ("cls"); printf ("\ n\ t-registered successfully -\ n"); string (fp) } else if (strcmp (BBMAS)! = 0) {printf ("the password you entered twice is not the same, please reset the password!" \ n "); goto reset; / / if goto statement}} / / Landing page int land () {int I = 0; / / I is to determine the password length and encrypt char a [10]; char b [10]; char user_name [10]; char user_passwords [10] Printf ("Please enter your user name:"); scanf ("% s", user_name); printf ("Please enter your password:"); while (I

< 9 && (user_passwords[i] = getch()) && user_passwords[i] != '\r'){ //如果输入超限 或者 遇到换行符就跳出循环 printf("*"); //掩饰密码 i++; } user_passwords[i] = 0; //字符串结束标志 '/0' FILE *fp; fp=fopen("register.txt","rt"); //又打开文件 if(fp == NULL){ printf("文件不存在!"); exit(1); } while(fscanf(fp,"%s %s",a,b) != EOF){ //读文件判断账号密码是否正确 if(strcmp(a,user_name) == 0 && strcmp(b,user_passwords) == 0){ //字符串比较函数,看是否正确 system("cls"); printf("\n\t\t\t--------登陆成功--------\n"); return 0; } } if(1){ system("cls"); printf("\n信息输入错误!(请检查注册文件信息)\n"); land(); } fclose(fp);}//增加新地点和信息 void AddPlace(AdjMatrix *G){ int s,e; char filename[30] = "introduce.txt"; char filename1[30] = "flag.txt"; int flag = 1; char p[20]; char i[66]; while (flag == 1){ //增加地点的地名 //增加地点的介绍 printf("请输入新地点的地名:"); scanf("%s",p); printf("请输入新地点的简介:"); scanf("%s",i); G->

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report