东软实训《电子地图管理系统》代码Word文档格式.docx
《东软实训《电子地图管理系统》代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《东软实训《电子地图管理系统》代码Word文档格式.docx(17页珍藏版)》请在冰豆网上搜索。
![东软实训《电子地图管理系统》代码Word文档格式.docx](https://file1.bdocx.com/fileroot1/2022-10/9/f3329551-f154-4c8b-a247-61235f436054/f3329551-f154-4c8b-a247-61235f4360541.gif)
//读取文件
voidQsort(intl,intr);
//排序
intBinsearch(ints,intt,intkey);
//二分查找
intSearch();
//检索
voidUpdate();
//更新
structRoadRecord
{
shortussize;
longulLinkID;
shortusRoadnamesize;
intusDispclass;
intusBrunch;
intusRoadnameflag;
charRoadname[20];
};
structRoadRecordroad[Length];
structDatestore//定义结构体存储数据
intn;
charTotalsize[4];
charLinkID_1[5];
charRoadnamesize[2];
charRoad_flag[2];
staticstructDatestoreDs[Length];
structdateout
longLinkID;
intDispclass;
intBrunch;
intRoadnameflag;
structdateoutdate[Length];
intReadFile()//模块一读取文件
intm;
charfilename[50];
unsignedshortustotalsize;
unsignedlongulLinkID;
unsignedshortusRoadnamesize;
FILE*fp_1=fopen("
D:
\\GTBL.dat"
"
rb+"
);
FILE*fp_2=fopen("
\\Newout.txt"
w+"
if(fp_1==NULL)//文件不存在手动输入文件路径
{
printf("
\n\t无法打开文件“GTBL.dat”或文件不再D盘根目录下\n\n请手动输入文件路径(路径中请勿有中文):
"
scanf("
%s"
filename);
if((fp_1=fopen(filename,"
))==NULL)
{
printf("
\n\t无法打开文件“GTBL.dat”或文件不存在!
\n\n"
return0;
}
else
\n\t文件打开成功!
}
if(fp_2==NULL)
\n\t无法打开文件“newout.txt”或文件不存在!
return0;
}
printf("
\n\t文件读取中......\n"
while(fread(Ds[Sizecount].Totalsize,2,1,fp_1)==1)
{
fread(Ds[Sizecount].LinkID_1,4,1,fp_1);
//读取LinkID字符
fread(Ds[Sizecount].Roadnamesize,2,1,fp_1);
//读取Roadnamesize字符串
fread(Ds[Sizecount].Road_flag,4,1,fp_1);
ustotalsize=MCGETSHORT(Ds[Sizecount].Totalsize);
//调用宏函数将字符串信息转化为数值类型
ulLinkID=MCGETLONG(Ds[Sizecount].LinkID_1);
usRoadnamesize=MCGETSHORT(Ds[Sizecount].Roadnamesize);
//赋值将数值信息传到结构体中
Ds[Sizecount].n=ustotalsize-12;
road[Sizecount].ussize=ustotalsize;
road[Sizecount].ulLinkID=ulLinkID;
road[Sizecount].usRoadnamesize=usRoadnamesize;
m=(int)Ds[Sizecount].Road_flag[3]&
255;
road[Sizecount].usDispclass=m&
15;
road[Sizecount].usBrunch=(m&
112)/16;
road[Sizecount].usRoadnameflag=(m&
128)/128;
date[Sizecount].Dispclass=road[Sizecount].usDispclass;
date[Sizecount].Brunch=road[Sizecount].usBrunch;
date[Sizecount].Roadnameflag=road[Sizecount].usRoadnameflag;
date[Sizecount].LinkID=ulLinkID;
fread(Ds[Sizecount].Roadname,sizeof(char),ustotalsize-12,fp_1);
//从文件中读取道路名称
strcpy(date[Sizecount].Roadname,Ds[Sizecount].Roadname+4);
fprintf(fp_2,"
LinkID="
%d\t"
date[Sizecount].LinkID);
Flag="
date[Sizecount].Roadnameflag);
Brunch"
date[Sizecount].Brunch);
Dispclass="
date[Sizecount].Dispclass);
Roadname="
%s\t"
date[Sizecount].Roadname);
\n"
Sizecount++;
fclose(fp_1);
fclose(fp_2);
\n\t文件读取成功\n\n生成文件<
\\Newout.txt>
return1;
}
voidQsort(intl,intr)//模块二排序(快速排序)
intn=date[l].LinkID,i=l,j=r;
date[Length-2]=date[l];
Ds[Length-2]=Ds[l];
if(l>
=r)
return;
while(i<
j)
while(i<
j&
&
date[j].LinkID>
=n)
--j;
date[i]=date[j];
Ds[i]=Ds[j];
date[i].LinkID<
=n)
++i;
date[j]=date[i];
Ds[j]=Ds[i];
date[i]=date[Length-2];
Ds[i]=Ds[Length-2];
Qsort(l,i-1);
Qsort(i+1,r);
intBinsearch(ints,intt,intkey)//二分查找
intlow=s,high=t,mid;
if(s<
=t)
mid=low+(high-low)/2;
if(date[mid].LinkID==key)
returnmid;
elseif(date[mid].LinkID>
key)
returnBinsearch(low,mid-1,key);
returnBinsearch(mid+1,high,key);
return-1;
intSearch()//模块三检索
intsel,i,flag=0,n,key,mid,s=2,t=Sizecount;
FILE*p,*p1,*p2;
//分别保存不同的道路检索信息
\n请输入检索方式:
\n\t1:
指定LinkID检索\n\t2:
指定交叉Link列表示Class番号检索\n\t3:
指定查找岔路数检索\n\t4:
指定道路名称检索\n\t0:
返回\n请选择:
while((scanf("
%d"
&
sel))!
=1)//判断输入的数据是否为数字
fflush(stdin);
\n\t输入错误,请重新输入!
switch(sel)
case1:
//LinkID检索
请输入LinkID:
scanf("
n);
key=n;
mid=Binsearch(s,t,key);
if(mid!
=-1)
{
printf("
\n\t检索到的信息不足5条,信息将显示在屏幕上!