全国交通咨询模拟系统实验报告 下载本文

页眉内容

(14)计算最小费用路线:

int CalcMinCost (int StartCity,int EndCity,int TravelType) {

int ma[Dij_MAXN][Dij_MAXN]; int i,j,min,end;

for (i=0;i

for (i=0;i

min=32767;j=0;

41

for (i=0;i

min=32767;j=0;

while (j

min=32767;

end=AdjList[i].Train[j].EndCity; while { }

ma[i][end]=min;

if (AdjList[i].Train[j].Cost

min=AdjList[i].Train[j].Cost; } j++;

(end==AdjList[i].Train[j].EndCity&&j

页脚内容

页眉内容

}

}

while (j

{ }

min=32767;

end=AdjList[i].Flight[j].EndCity; while { }

ma[i][end]=min;

if (AdjList[i].Flight[j].Cost

min=AdjList[i].Flight[j].Cost; } j++;

(end==AdjList[i].Flight[j].EndCity&&j

Dijkstra(ma,StartCity,EndCity,TravelType); return 1;

五、功能模块间函数的调用关系,如下图所示: SearchMinTime() 最短时间: InitSysData() SeekCity(name) CalcMinTime(start city,endcity,travelty pe) SaveSysInfo() 显示菜单: ShowMenu() 添加城市: InitSysData() InsertCity(Name) SaveSysInfo() 页脚内容41 int main() DelCity(): SeekCity(name) 页眉内容

最小费用: InitSysData() SeekCity(name) SeekCity(name) Calcmincost(startci删除路线: ty,endcity,traveltyp InitSysData() e) DelPath(name) SaveSysInfo() SaveSysInfo() CalcMinCost(): Dijkstra(ma,StertCity,EndCity,TravelT Dijkstra(): ype) Dijkstra_OutPut(m atx,PreCity,p_end,TravelType) 六、调试结果: 1、主界面:

页脚内容

41

删除城市: InitSysData() DelCity(Name) SaveSysInfo() 添加路线: InitSysData() InsertFlight(name,s_city,e_city,s_hour*60+s_minute,e_hour*60+e_minute,cost) InsertFlight(name,s_city,e_city,s_hour*60+s_minute,e_hour*60+e_minute,cost) SaveSysInfo() InsertTrain(): InsertFlight(): SeekCity(StartCity) SeekCity(StartCity) SeekCity(EndCity) SeekCity(EndCity) 页眉内容

2、添加城市:输入命令1后,按提示输入城市名,而后返回主界面

原city文件:

页脚内容

41

页眉内容

添加城市后的city文件:

3、删除城市:输入命令2后,按提示输入城市名,而后返回主界面

页脚内容

41