东软实训《电子地图管理系统》代码.docx
《东软实训《电子地图管理系统》代码.docx》由会员分享,可在线阅读,更多相关《东软实训《电子地图管理系统》代码.docx(17页珍藏版)》请在冰豆网上搜索。
![东软实训《电子地图管理系统》代码.docx](https://file1.bdocx.com/fileroot1/2022-10/9/f3329551-f154-4c8b-a247-61235f436054/f3329551-f154-4c8b-a247-61235f4360541.gif)
东软实训《电子地图管理系统》代码
#include
#include
#include
#include
#defineMCGETCHAR(date)(*((char*)(date)))
#defineMCGETSHORT(date)((unsignedshort)((((unsignedshort)(*((char*)(date))))<<8)|(((unsignedshort)(*((char*)(date)+1)))&0x00ff)))
#defineMCGETLONG(date)((((unsignedlong)MCGETSHORT((date)))<<16)|(((unsignedlong)MCGETSHORT((char*)(date)+2))&0x0000ffff))
#defineMCGET3BN(date)((((unsignedlong)MCGETCHAR((date)))<<16)|(((unsignedlong)MCGETSHORT((char*)(date+1))&0x0000ffff))
#defineLength65535
intSizecount=2;
intMark_1=0,Mark_2=0;
intReadFile();//读取文件
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];
charRoadname[20];
};
staticstructDatestoreDs[Length];
structdateout
{
longLinkID;
intDispclass;
intBrunch;
intRoadnameflag;
charRoadname[20];
};
structdateoutdate[Length];
intReadFile()//模块一读取文件
{
intm;
charfilename[50];
unsignedshortustotalsize;
unsignedlongulLinkID;
unsignedshortusRoadnamesize;
FILE*fp_1=fopen("D:
\\GTBL.dat","rb+");
FILE*fp_2=fopen("D:
\\Newout.txt","w+");
if(fp_1==NULL)//文件不存在手动输入文件路径
{
printf("\n\t无法打开文件“GTBL.dat”或文件不再D盘根目录下\n\n请手动输入文件路径(路径中请勿有中文):
");
scanf("%s",filename);
if((fp_1=fopen(filename,"rb+"))==NULL)
{
printf("\n\t无法打开文件“GTBL.dat”或文件不存在!
\n\n");
return0;
}
else
{
printf("\n\t文件打开成功!
\n\n");
}
}
if(fp_2==NULL)
{
printf("\n\t无法打开文件“newout.txt”或文件不存在!
\n\n");
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=");
fprintf(fp_2,"%d\t",date[Sizecount].LinkID);
fprintf(fp_2,"Flag=");
fprintf(fp_2,"%d\t",date[Sizecount].Roadnameflag);
fprintf(fp_2,"Brunch");
fprintf(fp_2,"%d\t",date[Sizecount].Brunch);
fprintf(fp_2,"Dispclass=");
fprintf(fp_2,"%d\t",date[Sizecount].Dispclass);
fprintf(fp_2,"Roadname=");
fprintf(fp_2,"%s\t",date[Sizecount].Roadname);
fprintf(fp_2,"\n");
Sizecount++;
}
fclose(fp_1);
fclose(fp_2);
printf("\n\t文件读取成功\n\n生成文件\\Newout.txt>\n\n");
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{
while(i=n)
{
--j;
}
{
date[i]=date[j];
Ds[i]=Ds[j];
}
while(i{
++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);
}
else
{
returnBinsearch(mid+1,high,key);
}
}
return-1;
}
intSearch()//模块三检索
{
intsel,i,flag=0,n,key,mid,s=2,t=Sizecount;
charRoadname[20];
FILE*p,*p1,*p2;//分别保存不同的道路检索信息
printf("\n请输入检索方式:
\n\t1:
指定LinkID检索\n\t2:
指定交叉Link列表示Class番号检索\n\t3:
指定查找岔路数检索\n\t4:
指定道路名称检索\n\t0:
返回\n请选择:
");
while((scanf("%d",&sel))!
=1)//判断输入的数据是否为数字
{
fflush(stdin);
printf("\n\t输入错误,请重新输入!
\n");
printf("\n请输入检索方式:
\n\t1:
指定LinkID检索\n\t2:
指定交叉Link列表示Class番号检索\n\t3:
指定查找岔路数检索\n\t4:
指定道路名称检索\n\t0:
返回\n请选择:
");
}
switch(sel)
{
case1:
//LinkID检索
{
printf("请输入LinkID:
");
scanf("%d",&n);
key=n;
mid=Binsearch(s,t,key);
if(mid!
=-1)
{
printf("\n\t检索到的信息不足5条,信息将显示在屏幕上!