《校园导游咨询系统》开发及升级延伸

原创 2005年05月20日 21:52:00

一:问题的提出

    现代社会,新兴科技日新月异,信息千变万化,人们在渴望得到最多最广的信息的同时又渴望得到信息的路径能越来越简单,易操作,而且能在简易的操作中得到更多的信息。这就要求信息咨询系统的开发者在开发之时能尽可能的全面理解客户的想法要求,而且在开发的时候能更简易的操作和更新,也为系统的延伸开发作必要的准备,这些思想都符合软件工程的开发思想。现就以设计一个《学校校园导游咨询系统》为例,设计一个校园导游咨询程序,为来访的客人提供各种信息查询服务,也为其开发及延伸提供一些思考。下面简单介绍软件工程的著名的七条原理:1-用分阶段的生命周期计划严格管理;2-坚持阶段评审; 3-实行严格的产品控制; 4-采纳现代程序设计技术; 5-结果应能清楚地审查; 6-开发小组的人员应少而精; 7-承认不断改进软件工程实践的必要性。软件工程的过程:1-开发过程;2-管理过程;3-供应过程;4获取过程;5-操作过程;6-维护过程;7-支持过程。

二:问题的基本要求

    A:设计一个学校的校园平面图,所包含的景色不少于6个,在这个图中顶点表示为校园内各个景色,存放景点的名称、代号、简介等信息,以边来表示路径,存放路径长度等信息

    B:为来访的游客提供图中任何景点相关的信息的查询。

     C:为来访的游客提供图中任意景点的问题查询,即查询任意景点之间上的一条最短的简单路径。

三:问题的实现提示

一般情况下,校园的路径是双向通行的,可设校园平面图是一个无向网,顶点和边均包含有相关信息。

四:问题的实现步骤

1、没有时间做数据检查的功能,所以输入数据时应按提示输入正确的数据,否则会出错。出错时,可以连续按Ctrl+CCtrl+Break终止程序。

2、英文水平有限,所以程序中的提示可能含义模糊。

3、使用者可以自己编辑景点信息和边信息,文件VIEWS保存景点信息,文件WAYS保存边信息。

4、文件VIEWS FloyedWAYS Floyed中保存了课本中弗洛伊德(Floyed)算法例子的数据,只需更名为VIEWSWAYS,就能直接验证,其计算结果与课本一致。同理,文件VIEWS DijkstraWAYS Dijkstra中保存了课本中狄克斯特拉(Dijkstra)算法例子的数据。

5、在程序中,我用-1表示无限大,所以实现上跟课本有些差异,但算法思想还是相同的。

6、输出效果不太好看,操作也不太方便,将就着用吧。

7SIZE_view是程序支持的景点最大数目,SIZE_way是程序支持的边最大数目。程序支持20个景点和300条边,不够的话把源代码第二、三行的数字改一改。

8view_count是当前景点的数目,way_count是当前边的数目。

9struct view_info是景点信息。name是景点的名称,info是景点的简介。views是所有景点的列表。

10struct way_info是边信息,即图的边信息。start_id是起始景点的编号,end_id是结束景点的编号,即边两个端点的编号,这里的边是指有向边。dist是路径长度,即边的权。ways是所有边的列表。

11struct path_info是路径信息,指从某个景点经过几个景点后到达另一个景点。count是路径所通过的景点数目,path是路径所通过景点的编号的列表,包括起点和终点。path[0]保存的就是起点编号,path[count-1]保存的就是终点编号。

五:学校校园导游咨询系统的原代码

   #include "stdio.h"

#define SIZE_view 20

#define SIZE_way 300

struct view_info    /*景点信息结构*/

       {

       char name[20];

       char info[100];

       } views[SIZE_view];

 

 

 

 

 

struct way_info    /*路径信息结构*/

       {

       int start_id;

       int end_id;

       int dist;

       } ways[SIZE_way];

 

 

 

 

 

struct path_info   /*路径查询结构*/

       {

       int count;

       int path[SIZE_view];

       };

 

 

 

 

 

int view_count, way_count;

 

 

 

 

 

main()

{

int com_menu;

clrscr();

 

 

 

 

 

printf("***********************************************************/n”);

printf("**                      Wellcome                         **/n”);

printf("***********************************************************/n”);

printf("/n");

printf("/n");

 

 

 

 

 

ReadViewsFile();

ReadWaysFile();

 

 

 

 

 

com_menu = 1;

while (com_menu != 0)

       {

       printf("/n");

       printf("Welcome! You can do:/n");

       printf("  1 -------- Show the info of views./n");  /*显示景点信息*/

       printf("  2 -------- Add a view./n");   /*增加景点方便系统后台管理*/

       printf("  3 -------- Delete a view./n");  /*删除景点方便系统后台管理*/

       printf("  4 -------- Show the info of ways./n"); /*显示路径信息*/

       printf("  5 -------- Add a way./n");  /*增加路径 方便系统后台管理*/

       printf("  6 -------- Delete a way./n"); /*删除路径方便系统后台管理*/

       printf("  7 -------- Search the best way./n"); /*寻找最佳路径*/

       printf("  0 -------- Quit/n");/ *退出系统查询系统*/

       printf("  What will you do: ");

       scanf("%d", &com_menu);

       switch(com_menu)

             {

             case 1:

                     ShowView();

                     break;

              case 2:

                     AddView();

                     break;

              case 3:

                     DelView();

                     break;

              case 4:

                     ShowWay();

                     break;

              case 5:

                     AddWay();

                     break;

              case 6:

                     DelWay();

                     break;

              case 7:

                     SearchWay();

                     break;    

              }

       }

printf("/n/n");

printf("Quiting.../n");

return;

}

 

 

 

 

 

ReadViewsFile()

{

int i;

FILE *fp;

view_count = 0;

if ((fp = fopen("VIEWS", "rb")) == NULL)   /*读取VIEWS文件*/

       {

       /* printf("  Open file VIEWS failed./n");

       exit(0); */

       return;

       }

for (i = 0; i < SIZE_view; i++)

       {

       if (fread(&views[i], sizeof (struct view_info), 1, fp) == 1)

              view_count = view_count + 1;

       else

              break;

       }

fclose(fp);

}

 

 

 

 

 

ReadWaysFile()

{

int i;

FILE *fp;

way_count = 0;

if ((fp = fopen("WAYS", "rb")) == NULL)  /*读取WAYS文件*/

       {

       return;

       }

for (i = 0; i < SIZE_way; i++)

       {

       if (fread(&ways[i], sizeof (struct way_info), 1, fp) == 1)

              way_count = way_count + 1;

       else

              break;

       }

fclose(fp);

}

 

 

 

 

 

 

 

 

 

 

AddView()

{

int i;

int count;

FILE *fp;

struct view_info new_view;

printf("Adding a view.../n");

if ((fp = fopen("VIEWS", "ab")) == NULL)  /*读取VIEWS文件

       {

       printf("  Open file VIEWS failed./n");

       exit(0);

       }

printf("  The name of new view: ");

scanf("%s", new_view.name);

printf("  The info of new view: ");

scanf("%s", new_view.info);

if (fwrite(&new_view, sizeof (struct view_info), 1, fp) == 1)

       {

       views[view_count] = new_view;

       view_count = view_count + 1;

       printf("Add a view successfully.");

       }

else

       printf("  Write error./n");

fclose(fp);

printf("/n/n");

return;

}

 

 

 

 

 

 

 

 

 

 

/*删除景点的同时,遍历路径表,将大于所删序号的编号减小1*/

DelView()

{

int i, select_id;

FILE *fp;

printf("Deleting a view.../n");

select_id = 1;

while (select_id != 0)

       {

       if (view_count == 0)

              {

              printf("  There is not any view. You can't delete any view./n/n/n");

              return;

              }

       printf("  All views in the school:/n");

       for (i = 0; i < view_count; i++)

              printf("    %d: %s/n", i + 1, views[i].name);

       printf("  Press 1-%d to delete a view, or press 0 to cancel: ", view_count);

       scanf("%d", &select_id);

       if (select_id > 0 && select_id <= view_count)

              {

              view_count = view_count - 1;

              for (i = select_id - 1; i < view_count; i++)

                     views[i] = views[i+1];

              fp = fopen("VIEWS", "wb+");

              for (i = 0; i < view_count; i++)

                     fwrite(&views[i], sizeof (struct view_info), 1, fp);

              fclose(fp);

              }

       }

printf("/n/n");

return;

}

 

 

 

 

 

 

 

 

 

 

ShowView()

{

int i, select_id;

FILE *fp;

printf("Showing the info of views.../n");

if (view_count == 0)

       {

       printf("  There is not any view./n/n/n");

       return;

       }

printf("  All views in the school:/n");

for (i = 0; i < view_count; i++)

       printf("    %d: %s/n", i+1, views[i].name);

select_id = 1;

while (select_id != 0)

       {

       printf("  Press 1-%d to show the info of view, or press 0 to cancel: ", view_count);

       scanf("%d", &select_id);

       if (select_id > 0 && select_id <= view_count)

              printf("    %s: %s/n", views[select_id-1].name, views[select_id-1].info);

       }

printf("/n/n");

return;

}

 

 

 

 

 

 

 

 

 

 

AddWay()

{

int i;

int tmp_num;

FILE *fp;

struct way_info new_way;

printf("Adding a way.../n");

if (view_count == 0)

       {

       printf("  There is not any view. You can't add a way./n/n/n");

       return;

       }

printf("  All views in the school:/n");

for (i = 0; i < view_count; i++)

       printf("    %d: %s/n", i+1, views[i].name);

if (view_count == 1)

       {

       printf("  There is only one view. You can't add a way./n/n/n");

       return;

       }

if ((fp = fopen("WAYS", "ab")) == NULL)

       {

       printf("  Open file WAYS failed./n");

       exit(0);

       }

tmp_num = 0;

while (1)

{

       printf("  ID of 1st view: ");

       scanf("%d", &tmp_num);

       if (tmp_num == 0)

              {

              printf("/n/n");

              return;

              }

       if (tmp_num > 0 && tmp_num <= view_count)

              {

              new_way.start_id = tmp_num - 1;

              break;

              }

       else

              printf("  Wrong ID! Please input 1-%d, or 0 to cancel./n", view_count);

}

while (1)

{

       printf("  ID of 2nd view: ");

       scanf("%d", &tmp_num);

       if (tmp_num == 0)

              {

              printf("/n/n");

              return;

              }

       if (tmp_num > 0 && tmp_num <= view_count)

              {

              new_way.end_id = tmp_num - 1;

              break;

              }

       else

              printf("  Wrong ID! Please input 1-%d, or 0 to cancel./n", view_count);

}

while (1)

{

       printf("  Distance: ");

       scanf("%d", &tmp_num);

       if (tmp_num == 0)

              {

              printf("/n/n");

              return;

              }

       if (tmp_num > 0)

              {

              new_way.dist = tmp_num;

              break;

              }

       else

              printf("  Error! Please input positive whole number, or 0 to cancel./n");

}

if (fwrite(&new_way, sizeof (struct way_info), 1, fp) == 1)

       {

       ways[way_count] = new_way;

       way_count = way_count + 1;

       printf("Add a view successfully.");

       }

else

       printf("  Write error./n");

fclose(fp);

printf("/n/n");

return;

}

 

 

 

 

 

 

 

 

 

 

DelWay()

{

int i, select_id;

FILE *fp;

printf("Deleting a way.../n");

select_id = 1;

while (select_id != 0)

       {

       if (way_count == 0)

              {

              printf("  There is not any way. You can't delete any way./n/n/n");

              return;

              }

       printf("  All ways in the school:/n");

       for (i = 0; i < way_count; i++)

              printf("    %d: from %s to %s, distance is %d/n", i+1, views[ways[i].start_id].name,

                     views[ways[i].end_id].name, ways[i].dist);

       printf("  Press 1-%d to delete a way, or press 0 to cancel: ", way_count);

       scanf("%d", &select_id);

       if (select_id > 0 && select_id <= way_count)

              {

              way_count = way_count - 1;

              for (i = select_id - 1; i < way_count; i++)

                     ways[i] = ways[i+1];

              fp = fopen("WAYS", "wb+");

              for (i = 0; i < way_count; i++)

                     fwrite(&ways[i], sizeof (struct way_info), 1, fp);

              fclose(fp);

              }

       }

printf("/n/n");

return;

}

 

 

 

 

 

 

 

 

 

 

ShowWay()

{

int i;

printf("Showing the info of ways.../n");

if (way_count == 0)

       {

       printf("  There is not any way./n/n/n");

       return;

       }

printf("  All ways in the school:/n");

for (i = 0; i < way_count; i++)

       printf("    %d: from %s to %s, distance is %d/n", i+1, views[ways[i].start_id].name,

              views[ways[i].end_id].name, ways[i].dist);

}

 

 

 

 

 

 

 

 

 

 

SearchWay()

{

int select_id;

printf("Searching the best way.../n");

if (view_count == 0)

       {

       printf("  There is not any view./n/n/n");

       return;

       }

if (way_count == 0)

       {

       printf("  There is not any way./n/n/n");

       return;

       }

printf("  Algorithms:/n");

printf("    1: Dijkstra/n");   /*用狄克斯特拉(Dijkstra)算法求取最佳路径*/

printf("    2: Floyed/n");   /*用弗洛伊德(Floyed)算法求取最佳路径*/

printf("    0: Cancel/n");   /*退出求取最佳路径*/

select_id = 1;

while (1)

       {

       printf("  You will do: ");

       scanf("%d", &select_id);

       switch (select_id)

              {

              case 0:

                     return;

                     break;

              case 1:

                     Dijkstra();

                     return;

                     break;

              case 2:

                     Floyed();

                     return;

                     break;

              }

       }

}

 

 

 

 

 

 

 

 

 

 

Dijkstra()   /*狄克斯特拉(Dijkstra)算法*/

{

int j, k, w, m, start_num;

int used_list[SIZE_view], dist_list[SIZE_view];

int GA[SIZE_view][SIZE_view];

struct path_info path_list[SIZE_view];

printf("  All views in the school:/n");

for (j = 0; j < view_count; j++)

       printf("    %d: %s/n", j+1, views[j].name);

printf("  Please input the number of start view: ");

scanf("%d%", &start_num);

start_num = start_num - 1;

 

 

 

 

 

for (j = 0; j < view_count; j++)

       for (k = 0; k < view_count; k++)

              if (j == k)

                     GA[j][k] = 0;

              else

                     GA[j][k] = -1;

for (j = 0; j< way_count; j++)

       {

       w = ways[j].start_id;

       m = ways[j].end_id;

       GA[w][m] = ways[j].dist;

       }

 

 

 

 

 

for (j = 0; j< view_count; j++)

       {

       if (j != start_num)

              used_list[j] = 0;

       else

              used_list[j] = 1;

       dist_list[j] = GA[start_num][j];

       if (dist_list[j] > 0)

              {

              path_list[j].count = 2;

              path_list[j].path[0] = start_num;

              path_list[j].path[1] = j;

              continue;

              }

       if (dist_list[j] == 0)

              {

              path_list[j].count = 1;

              path_list[j].path[0] = j;

              continue;

              }

       path_list[j].count = 0;

       }

for (k = 0; k< view_count - 2; k++)

       {

       w = -1;

       m = start_num;

       for (j = 0; j< view_count; j++)

              if (used_list[j] == 0)

                     {

                     if (dist_list[j] == -1)

                            continue;

                     if ((w == -1) || (w != -1 && dist_list[j] < w))

                            {

                            m = j;

                            w = dist_list[j];

                            }

                     }

       if (m != start_num)

              used_list[m] = 1;

       else

              break;

       for (j = 0; j< view_count; j++)

              {

              if (used_list[j] == 0)

                     {

                     if ((dist_list[m] == -1 || GA[m][j] == -1))

                            continue;

                     if ((dist_list[j] == -1) || (dist_list[j] != -1 && dist_list[m] + GA[m][j] < dist_list[j]))

                            {

                            dist_list[j] = dist_list[m] + GA[m][j];

                            path_list[j].count = path_list[m].count + 1;

                            for (w = 0; w < path_list[m].count; w++)

                                   path_list[j].path[w] = path_list[m].path[w];

                            path_list[j].path[path_list[j].count-1] = j;

                            }

                     }

              }

       }

printf("  Dijkstra table:/n");

for (j = 0; j< view_count; j++)

       printf("/t%d", used_list[j]);

printf("/n");

for (j = 0; j< view_count; j++)

       printf("/t%d", dist_list[j]);

printf("/n");

for (j = 0; j< view_count; j++)

       {

       printf("/t");

       for (k = 0; k< path_list[j].count; k++)

              printf("%d", path_list[j].path[k] + 1);

       }

printf("/n");

for (j = 0; j< view_count; j++)

       {

       printf("  From %s to %s: ", views[start_num].name, views[j].name);

       if (path_list[j].count == 0)

              printf("no way./n");

       else

              {

              printf("distance is %d, and path is ", dist_list[j]);

              printf("%s", views[start_num].name);

              for (k = 1; k< path_list[j].count; k++)

                     printf(" -> %s", views[path_list[j].path[k]].name);

              printf("/n");

              }

       }

printf("/n/n");

}

 

 

 

 

 

 

 

 

 

 

Floyed()    /*弗洛伊德(Floyed)算法*/

{

int i, j, k, m, start_num, end_num;

int dist_list[SIZE_view][SIZE_view];

struct path_info path_list[SIZE_view][SIZE_view];

 

 

 

 

 

printf("  Floyed table:/n");

for (i = 0; i< view_count; i++)

       for (j = 0; j< view_count; j++)

              {

              if (i == j)

                     {

                     dist_list[i][j] = 0;

                     continue;

                     }

              dist_list[i][j] = -1;

              path_list[i][j].count = 0;

              for  (k = 0; k< way_count; k++)

                     {

                     if (ways[k].start_id == i && ways[k].end_id == j)

                            {

                            dist_list[i][j] = ways[k].dist;

                            path_list[i][j].count = 2;

                            path_list[i][j].path[0] = i;

                            path_list[i][j].path[1] = j;

                            break;

                            }

                     }

              }

for (k = 0; k< view_count; k++)

       for (i = 0; i < view_count; i++)

              for (j = 0; j< view_count; j++)

                     {

                     if (i == k || j == k || i == j)

                            continue;

                     if (dist_list[i][k] == -1 || dist_list[k][j] == -1)

                            continue;

                     if ((dist_list[i][j] == -1) || ((dist_list[i][j] != -1) &&

                            (dist_list[i][k] + dist_list[k][j] < dist_list[i][j])))

                            {

                            dist_list[i][j] = dist_list[i][k] + dist_list[k][j];

                            path_list[i][j].count = path_list[i][k].count + path_list[k][j].count - 1;

                            for (m = 0; m < path_list[i][k].count; m++)

                                   path_list[i][j].path[m] = path_list[i][k].path[m];

                            for (m = 0; m < path_list[k][j].count; m++)

                                   path_list[i][j].path[m+path_list[i][k].count] = path_list[k][j].path[m+1];

                            }

                     }

for (i = 0; i< view_count; i++)

       {

       for (j = 0; j< view_count; j++)

              {

              printf("/t%d", dist_list[i][j]);

              }

       printf("/n");

       }

 

 

 

 

 

printf("  All views in the school:/n");

for (i = 0; i < view_count; i++)

       printf("    %d: %s/n", i+1, views[i].name);

printf("  Please input the start number and end number: ");

scanf("%d%d", &start_num, &end_num);

start_num = start_num - 1;

end_num = end_num - 1;

printf("  From %s to %s: ", views[start_num].name, views[end_num].name);

if (dist_list[start_num][end_num] == -1)

       printf("no way./n");

else

       {

       printf("distance is %d, and path is ", dist_list[start_num][end_num]);

       k = path_list[start_num][end_num].path[0];

       printf("%s", views[k].name);

       for (m = 1; m < path_list[start_num][end_num].count; m++)

              {

              k = path_list[start_num][end_num].path[m];

              printf(" -> %s", views[k].name);

              }

       }

printf("/n/n");

return;

}

 

 

 

 

 

文件包含内容的图片

上面图片内容的几点说明:

  1VIEWS文件包含为景点信息内容

  2VIEWS Dijkstra 文件包含为景点狄克斯特拉(Dijkstra)算法

  3VIEWS Floyed 文件包含为弗洛伊德(Floyed)算法

  4WAYS文件包含为路径信息内容

  5WAYS Dijkstra 文件包含为路径狄克斯特拉(Dijkstra)算法

  6WAYS Floyed 文件包含为路径弗洛伊德(Floyed)算法

上面文件的大小即里面的内容可以在原程序里面的各个结构去去修改所定义的大小。

运行后所得到的.exe文件的界面为:

关于.exe界面的几点说明

    1:显示景点信息

    2:增加景点

    3:删除景点

    4:显示路径信息

    5:增加路径

    6:删除路径

    7:寻找最佳路径

    0:退出查询系统

 

 

 

 

 

六:学校校园导游系统的升级延伸

这个校园导游系统的升级延伸方向有很多,比如应用于开发数据库,,

版权声明:本文为博主原创文章,未经博主允许不得转载。

数据结构-校园导游咨询系统…

原文地址:数据结构-校园导游咨询系统(c语言版)作者:陶陶//本程序最好在VC++中运行,但这是C程序,在TC中,显示结果会出现乱码,TC不支持汉字 #include "string.h" #incl...

数据结构-校园导游咨询系统

#include "string.h"#include "stdio.h"#include "malloc.h"#include "stdlib.h"#define Max 20000#define ...
  • raywwen
  • raywwen
  • 2011年06月16日 09:43
  • 1666

校园导游咨询系统

  • 2015年07月28日 17:33
  • 6KB
  • 下载

校园导游咨询系统

  • 2015年01月11日 15:48
  • 9KB
  • 下载

校园导游咨询(图的应用)

校园导游咨询(图的应用) [问题描述] 设计一个校园导游程序,为来访的客人提供各种信息查询服务。 (1)设计学校的校园平面图,所含景点不少于10个,以图中顶点表示校内各景点,存放景点名称、代号、简介等...

武汉理工大学校园导游咨询系统

  • 2009年06月29日 16:28
  • 192KB
  • 下载

校园导游咨询系统报告

  • 2016年09月16日 09:41
  • 566KB
  • 下载

图的应用:校园导游系统(含Dijkstra和Floyd算法)

/* 问题描述:用无向网表示你所在学校的校园景点平面图,图中顶点表示主要景点, 存放景点的编号、名称、简介等信息,图中的边表示景点间的道路,存放路径长度等信息。 要求能够回答有关景点介绍、游览路...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:《校园导游咨询系统》开发及升级延伸
举报原因:
原因补充:

(最多只允许输入30个字)