程序设计报告城市管理Word下载.docx

上传人:b****4 文档编号:6536024 上传时间:2023-05-06 格式:DOCX 页数:33 大小:555.33KB
下载 相关 举报
程序设计报告城市管理Word下载.docx_第1页
第1页 / 共33页
程序设计报告城市管理Word下载.docx_第2页
第2页 / 共33页
程序设计报告城市管理Word下载.docx_第3页
第3页 / 共33页
程序设计报告城市管理Word下载.docx_第4页
第4页 / 共33页
程序设计报告城市管理Word下载.docx_第5页
第5页 / 共33页
程序设计报告城市管理Word下载.docx_第6页
第6页 / 共33页
程序设计报告城市管理Word下载.docx_第7页
第7页 / 共33页
程序设计报告城市管理Word下载.docx_第8页
第8页 / 共33页
程序设计报告城市管理Word下载.docx_第9页
第9页 / 共33页
程序设计报告城市管理Word下载.docx_第10页
第10页 / 共33页
程序设计报告城市管理Word下载.docx_第11页
第11页 / 共33页
程序设计报告城市管理Word下载.docx_第12页
第12页 / 共33页
程序设计报告城市管理Word下载.docx_第13页
第13页 / 共33页
程序设计报告城市管理Word下载.docx_第14页
第14页 / 共33页
程序设计报告城市管理Word下载.docx_第15页
第15页 / 共33页
程序设计报告城市管理Word下载.docx_第16页
第16页 / 共33页
程序设计报告城市管理Word下载.docx_第17页
第17页 / 共33页
程序设计报告城市管理Word下载.docx_第18页
第18页 / 共33页
程序设计报告城市管理Word下载.docx_第19页
第19页 / 共33页
程序设计报告城市管理Word下载.docx_第20页
第20页 / 共33页
亲,该文档总共33页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

程序设计报告城市管理Word下载.docx

《程序设计报告城市管理Word下载.docx》由会员分享,可在线阅读,更多相关《程序设计报告城市管理Word下载.docx(33页珍藏版)》请在冰点文库上搜索。

程序设计报告城市管理Word下载.docx

类型

成员名

描述

CityNode

属性

String

cityname

城市名称

int

x

城市的横坐标

y

城市的纵坐标

CityNode*

next

其连接作用

Class中的方法

boolInsert_CityNode(stringcityname,intx,inty);

(添加城市)

boolInsert_CityNode_2(stringcityname,intx,inty);

(添加城市---文件读入)

boolInsert_CityNode_3(stringcityname,floatx,floaty);

(遍历指定城市中使用)

boolSearch_CityNode(stringcityname);

(通过城市名字查找)

boolSearch_CityNode(intx,inty);

(用过城市坐标查找)

boolDelete_CityNode(stringcityname);

(用过城市名字删除)

boolDelete_CityNode(intx,inty);

(通过城市坐标删除)

floatDistance(stringcityname1,stringcityname2);

(两城市间的距离)

voidSaveFile(stringcityname,intx,inty);

(保存文件)

voidReadFile();

(读取文件)

voidOperation();

(switc语句,便于操作)

voidSaveAgain();

(删除节点时重新保存文件)

voidClear();

(遍历指定城市后清空链表)

voidIsExist(intx,inty,stringcityname,int&

temp);

(判断是否已经存在)

boolDistance_In_Range(intnum,intx,inty);

(一定范围内的城市)

boolTravel_Edge();

(将城市和坐标分别存在数组中,便于求最短路径)

voidTravel_Path();

(贪心算法求最短路径)

boolTravel_Edge_ALL();

(遍历所有城市)

boolZDCZ(stringcityname);

(添加需要便利的指定城市)

CityNode*head;

(保存所有城市数据)

CityNode*head2;

(保存指定城市的信息)

(3)

用户手册

(4)调试及测试

1.添加城市

若城市已存在,则提示存在,不能添加

2.查找城市

通过名称查找

通过坐标查找

3.删除城市

通过名称删除

通过坐标删除

4..查看两城市间的距离

5..查找距离定点一定距离的城市

6.查找最优路径

《1》制定城市查询最短路径

《2》全部城市最短路径

测试数据(环形数据能更好的检测)

中国91合肥96广州56深圳51安徽16北京11

7.查看所有城市

(5)附录程序代码

#include<

iostream>

string>

cmath>

fstream>

stdlib.h>

usingnamespacestd;

intnumber=0,number2=0;

floatWeight[100][100];

stringcitys[100];

structCityNode

{

stringcityname;

floatx,y;

CityNode*next;

};

structminedge

intvex;

intlow;

minedgeEdge[100];

voidTravel();

classCityManage

public:

CityManage();

//~CityManage();

boolInsert_CityNode(stringcityname,floatx,floaty);

boolInsert_CityNode_2(stringcityname,floatx,floaty);

boolSearch_CityNode(floatx,floaty);

boolDelete_CityNode(floatx,floaty);

voidSaveFile(stringcityname,floatx,floaty);

voidClear();

voidIsExist(floatx,floaty,stringcityname,int&

boolDistance_In_Range(intnum,floatx,floaty);

boolTravel_Edge_ALL();

boolZDCZ(stringcityname);

private:

CityNode*head;

CityNode*head2;

CityManage:

:

CityManage()

head=newCityNode;

head->

next=NULL;

head2=newCityNode;

head2->

}

boolCityManage:

Insert_CityNode(stringcityname,floatx,floaty)

//(添加城市)

CityNode*p=newCityNode;

p->

cityname=cityname;

x=x;

y=y;

inttemp1=0;

IsExist(x,y,cityname,temp1);

if(temp1==0)

{

SaveFile(cityname,x,y);

cout<

<

"

添加成功"

<

endl;

if(head->

next==NULL)

{

head->

next=p;

p->

number=1;

returntrue;

}

p->

next=head->

next;

head->

number++;

returntrue;

}

returntrue;

Insert_CityNode_2(stringcityname,floatx,floaty)

//(添加城市---文件读入)

if(head->

number=1;

number++;

Insert_CityNode_3(stringcityname,floatx,floaty)

if(head2->

head2->

number2=1;

next=head2->

number2++;

ZDCZ(stringcityname)

CityNode*p;

p=newCityNode;

p=head->

while(p!

=NULL)

if(p->

cityname==cityname)

Insert_CityNode_3(p->

cityname,p->

x,p->

y);

p=p->

Search_CityNode(stringcityname)

//(通过城市名字查找)

cout<

*****************************"

cityname<

"

x<

"

y<

>

cout<

未发现此城市"

returnfalse;

Search_CityNode(floatx,floaty)

//(用过城市坐标查找)

CityNode*p;

x==x&

&

y==y)

cityname<

所在坐标下没有城市"

voidCityManage:

IsExist(floatx,floaty,stringcityname,int&

temp)

//(判断是否已经存在)

CityNode*k;

k=newCityNode;

k=head->

while(k!

if(k->

k->

y==y||k->

该城市已存在"

temp=1;

break;

k=k->

Delete_CityNode(stringcityname)

//(用过城市名字删除)

CityNode*p,*s;

s=newCityNode;

s=head;

s->

next=p->

deletep;

该城市已删除"

number--;

s=s->

Delete_CityNode(floatx,floaty)

//(通过城市坐标删除)

SaveAgain()

ofstreamfout("

City.txt"

ios:

out);

SaveFile(p->

floatCityManage:

Distance(stringcityname1,stringcityname2)

//(两城市间的距离)

floatc1x,c1y,c2x,c2y,dis;

s=head->

cityname==cityname1)

c1x=p->

x;

c1y=p->

y;

//if(p->

cityname!

=cityname1)

if(p==NULL)

未找到您所输入的第一个城市"

return0;

while(s!

if(s->

cityname==cityname2)

c2x=s->

c2y=s->

//if(s->

=cityname2)

if(s==NULL)

未找到您所输入的第二个城市"

return1;

dis=sqrt((c1x-c2x)*(c1x-c2x)+(c1y-c2y)*(c1y-c2y));

到"

;

s->

的距离为:

dis<

returndis;

Distance_In_Range(intnum,floatx,floaty)

//(一定范围内的城市)

intn=0;

if(sqrt((pow(p->

x-x,2)+pow(p->

y-y,2)))<

=num)

n++;

if(n==0)

该范围内没有发现城市!

Clear()

while(head2->

next)

p=head2->

free(p);

number2--;

Travel_Edge()

//(将城市和坐标分别存在数组中,便于求最短路径)

p=head2->

inta=0,b=0,c=0;

for(a=0;

a<

100;

a++)

for(b=0;

b<

b++)

Weight[a][b]=100;

number2;

s=p->

for(b=a+1;

Weight[b][a]=Weight[a][b]=sqrt(pow(abs(p->

x-s->

x),2)+pow(abs(p->

y-s->

y),2));

s=s->

for(c=0;

c<

c++)

citys[c]=p->

cityname;

Travel_Edge_ALL()

number;

voidTravel(intNumber)//(求最短路径)

inti,j,k,l;

intS[100];

//用于存储已访问过的城市//用于存储两个城市之间的距离

floatsum=0;

//用于记算已访问过的城市的最小路径长度

floatDtemp;

//保证Dtemp比任意两个城市之间的距离都大(其实在算法描述中更准确的应为无穷大)

intflag;

////最为访问的标志,若被访问过则为1,从未被访问过则为0

/*初始化*/

i=1;

//i是至今

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2