您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > 程序设计报告---城市管理
课程设计报告设计题目:城市管理学生姓名:魏于博专业:电子信息工程班级:电信工17-1班学号:2017212064指导教师:方帅完成日期:2018年6月29日合肥工业大学计算机与信息学院(1)需求和规格说明问题描述:问题描述:用无序表实现一个城市数据库。每条数据库记录包括城市名(任意长的字符串)和城市的坐标(用整数x和y表示)。实现数据的插入、删除、查询功能,并实现指定距离内的所有城市。设计算法实现指定一定数目的具体城市,寻找遍历这些城市并回到出发点的最佳路径,观察随着城市数目的增加,算法执行效率的变化。编程任务:1)用列表对城市进行记录和管理,实现城市的增加、删除和查询功能,并实现文件保存和读取2)计算城市之间距离,统计输出距离某城市一定范围内的所有城市。3)实现一定规模城市的遍历最佳路径选择。4)分析随着城市数目增加时,算法执行效果的改变,深刻理解旅行商问题。(2)设计建立一个CityNode,包含城市的名称,横纵坐标和指针。再建立一CityManage类属性和方法定义类名成员类别类型成员名描述CityNode属性Stringcityname城市名称intx城市的横坐标inty城市的纵坐标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北京117.查看所有城市(5)附录程序代码#includeiostream#includestring#includecmath#includefstream#includestdlib.husingnamespacestd;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);boolInsert_CityNode_3(stringcityname,floatx,floaty);boolSearch_CityNode(stringcityname);boolSearch_CityNode(floatx,floaty);boolDelete_CityNode(stringcityname);boolDelete_CityNode(floatx,floaty);floatDistance(stringcityname1,stringcityname2);voidSaveFile(stringcityname,floatx,floaty);voidReadFile();voidOperation();voidSaveAgain();voidClear();voidIsExist(floatx,floaty,stringcityname,int&temp);boolDistance_In_Range(intnum,floatx,floaty);boolTravel_Edge();boolTravel_Edge_ALL();boolZDCZ(stringcityname);private:CityNode*head;CityNode*head2;};CityManage::CityManage(){head=newCityNode;head-next=NULL;head2=newCityNode;head2-next=NULL;}boolCityManage::Insert_CityNode(stringcityname,floatx,floaty)//(添加城市){CityNode*p=newCityNode;p-cityname=cityname;p-x=x;p-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-next=NULL;number=1;returntrue;}p-next=head-next;head-next=p;number++;returntrue;}returntrue;}boolCityManage::Insert_CityNode_2(stringcityname,floatx,floaty)//(添加城市---文件读入){CityNode*p=newCityNode;p-cityname=cityname;p-x=x;p-y=y;if(head-next==NULL){head-next=p;p-next=NULL;number=1;returntrue;}p-next=head-next;head-next=p;number++;returntrue;}boolCityManage::Insert_CityNode_3(stringcityname,floatx,floaty)//(添加城市---文件读入){CityNode*p=newCityNode;p-cityname=cityname;p-x=x;p-y=y;if(head2-next==NULL){head2-next=p;p-next=NULL;number2=1;returntrue;}p-next=head2-next;head2-next=p;number2++;returntrue;}boolCityManage::ZDCZ(stringcityname){CityNode*p;p=newCityNode;p=head-next;while(p!=NULL){if(p-cityname==cityname){Insert_CityNode_3(p-cityname,p-x,p-y);returntrue;}p=p-next;}returntrue;}boolCityManage::Search_CityNode(stringcityname)//(通过城市名字查找){CityNode*p;p=newCityNode;p=head-next;while(p!=NULL){if(p-cityname==cityname){cout*****************************endl;coutcitynamep-x,p-yendl;cout*****************************endl;returntrue;}p=p-next;}cout未发现此城市endl;returnfalse;}boolCityManage::Search_CityNode(floatx,floaty)//(用过城市坐标查找){CityNode*p;p=newCityNode;p=head-next;while(p!=NULL){if(p-x==x&&p-y==y){coutendl;cout*****************************endl;coutp-citynamep-x,p-yendl;cout*****************************endl;coutendl;returntrue;}p=p-next;}cout所在坐标下没有城市endl;returnfalse;}voidCityManage::IsExist(floatx,floaty,stringcityname,int&temp)//(判断是否已经存在){CityNode*k;k=newCityNode;k=head-next;while(k!=NULL){if(k-x==x&&k-y==y||k-cityname==cityname){cout该城市已存在endl;temp=1;break;}k=k-next;}}boolCityManage::Delete_CityNode(stringcityname)//(用过城市名字删除){CityNode*p,*s;p=newCityNode;s=newCityNode;s=head;p=head-next;while(p!=NULL){if(p-cityname==cityname){s-next=p-next;deletep;cout该城市已删除endl;number--;returntrue;}p=p-next;s=s-next;}returnfalse;}boolCityManage::Delete_CityNode(floatx,floaty)//(通过城市坐标删除){CityNode*p,*s;p=newCityNode;s=newCityNode;s=head;p=head-next;while(p!=NULL){if(p-x==x&&p
本文标题:程序设计报告---城市管理
链接地址:https://www.777doc.com/doc-3629103 .html