| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2300 人关注过本帖
标题:急求课程设计内容:(某公园导游图)
只看楼主 加入收藏
夜中梦
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2007-5-12
收藏
得分:0 
呵呵,有趣

2007-06-14 18:28
旺旺
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-4-25
收藏
得分:0 

/********************以下是a.c文件********************/

#include "stdafx.h"
#using <mscorlib.dll>
#include <math.h>
#include <string.h>
#include <stdio.h>

struct message
{int num;
char name[100];
char pro[500];
}school[10]={{1,"行政楼\n"},
{2,"食堂\n"},
{3,"赛博楼,信息分院办公室所在地\n"},
{4,"求是楼,实验楼计算机中心\n"},
{5,"格致楼,法学管理学院"},
{6,"工程实习中心,金工实习\n"},
{7,"仰仪楼,机电计测分院\n"},
{8,"体育馆,旁边有篮球场`足球场`还有网球场\n"},
{9,"一号教学楼,主要以阶梯教室为主\n"},
{10,"二号教学楼,小教室为多\n"}};
#define maxlong 10
void road(int c[10][10],int a,int b)

{int i,j,k,next;
int max=1000;
int path[maxlong][maxlong],A[maxlong][maxlong];
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{if(c[j]!=max) path[j]=j;
else path[j]=0;A[j]=c[j];
}
for(k=0;k<10;k++)
for(i=0;i<10;i++)
for(j=0;j<10;j++)
if(A[j]>(A[k]+A[k][j]))
{A[j]=A[k]+A[k][j];
path[j]=path[k];
}
printf("%d\n",A[a-1][b-1]);
next=path[a-1][b-1];
if(next==-1)
printf("没有此路径\n");
else
{printf("%d",a);
while(next!=(b-1))
{printf("-->%d",next+1);
next=path[next][b-1];
}
printf("-->%d\n",b);
}
}
void result(int a)

{printf("%s,%s\n",school[a-1].name,school[a-1].pro);
}


using namespace System;

int _tmain()
{
int A[10][10]={{0,15,100,45,50,450,35,550,80,90},{15,0,85,30,35,435,20,535,65,75},{100,85,0,30,60,400,420,380,355,520},
{45,30,30,0,20,300,280,230,270,490},{50,35,60,20,0,320,700,580,260,450},{450,435,400,280,320,0,100,140,160,200},
{35,20,420,280,700,100,0,40,60,180},{550,535,380,230,580,40,40,0,20,160},{80,65,355,270,260,160,60,20,0,120},{90,75,520,490,450,200,180,160,120,0}};
int a,b,c;
printf("1行政楼,2食堂,3赛博楼,4求是楼,5格致楼,6工程实习中心,7仰仪楼,8体育馆,9一号教学楼,10二号教学楼\n");
printf("请输入起点和终点的代码:");
scanf("%d,%d",&a,&b);
road(A,a,b);
printf("输入想知道的景点的代码:");
scanf("%d",&c);
result(c);
}

/*********************一下是q.c文件***********************/

#include "stdio.h"
#define null 0 /*宏替换*/
#define num 20
#define maxdist 10000
typedef struct /*定义结构体存景点代码、名称、简介*/
{
int code;
char name[num];
char pr[num];
}graph;
void save( int c[num][num],int n,int i,int d[num],int p[num]) /*最短路径的C语言函数*/
{
int s[num];
int mindist,dist;
int j,k,u,w;
for(j=0;j<n;j++)
{
d[j]=c[i][j];
s[j]=0;
if((d[j]<maxdist)&&(d[j]!=0))
p[j]=i;
else
p[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]+c[u][k];

if(dist<d[k])
{
d[k]=dist;
p[k]=u;
}
}
}
}
void input(int v,int n,int d[],int p[]) /*输出最短路径和最短距离函数*/
{
int i,j,k,pre;
for(i=0;i<n;i++)
if(i!=v)
{
printf("\n%d",i);
pre=p[i];
while(pre!=-1)
{
printf("<--%d",pre); /*输出最短路径所经过的景点*/
pre=p[pre];
}
if(d[i]==maxdist)
printf("<--%d",v);
printf("\tshortestway:%d",d[i]); /*输出最短距离*/
}
}
main() /*程序主函数*/
{
graph pl[10]={{0,"classroom","go to class"}, /*景点名称和简介*/
{1,"forest","tree and grass"},
{2,"restaurant","eat food"},
{3,"building","teaching room"},
{4,"expriment","action myself"},
{5,"gate","shool gate"},
{6,"playground","playing ball"},
{7,"life-center","service center"},
{8,"super market","buy evergthing"},
{9,"camera room","see movie"}};
int i,j,k,n=10;
int d[num],p[num],sd[num][num],sp[num][num],a[num][num];
clrscr();
for(i=0;i<n;i++) /*给景点之间的路径赋最大值*/
{
for(j=0;j<n;j++)
a[i][j]=maxdist;
}
a[0][2]=30; /*景点之间的路径长度*/
a[0][5]=40;
a[0][1]=20;
a[1][5]=60;
a[1][4]=40;
a[1][6]=30;
a[2][3]=35;
a[2][7]=40;
a[3][10]=20;
a[3][8]=15;
a[4][9]=30;
a[4][8]=35;
a[4][10]=10;
a[5][10]=10;
a[5][8]=45;
a[5][2]=20;
a[6][0]=70;
a[7][0]=50;
a[8][9]=20;
a[9][1]=55;
clrscr();
printf("\t --Welcome You Use Guide--\n"); /*程序良好界面的设置和操作说明*/
printf("\t*****************************************\n");
printf("\t* *\n");
printf("\t*\tInformation-i\tVisit-v\t\t*\n\t*\t About-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 code:i v q \t*\n");
printf("\t*clear the screen:c \t\t\t*\n");
printf("\t*****************************************\n");
do /*循环输入字符进行操作*/
{
switch(getchar()) /*switch语句判断要进行的操作*/
{
case'a':{ /*程序知识产权声明*/
printf("This is a guide program\n");
printf("designer:hua time:2006.1.1\n");
}break;
case'i':{ /*输入景点代码查景点名称和简介*/
while(1)
{
printf("input number 0->9: (!=0->9 q)\n");
scanf("%d",&i);
if(i<0||i>9) /*输入非0->9退出*/
break;
printf("%s,%s\n",pl[i].name,pl[i].pr);
}
}break;
case'c': clrscr();break; /*界面清屏*/
case'v': { /*输入景点代码查到其它景点的最短距离*/
do
{
printf("\ninput the number:(0-9): (!=0->9 q)\n");
scanf("%d",&i);
if(i<0||i>9) /*输入非0->9退出*/
break;
save(a,n,i,d,p);
printf("\n\nThe shortroad is:\n");
input(i,n,d,p);

}
while(1);
}break;
default: exit(1); /*非正常字符退出*/
}
}
while(getchar());
getchar();
}

上面的代码高手修改一下总可以吧!

2007-06-30 16:18
快速回复:急求课程设计内容:(某公园导游图)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020422 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved