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

scanf(\ printf(\到达时刻(00:00,24小时制):\ scanf(\ printf(\票价:\ if (traveltype)

{

InsertFlight(name,s_city,e_city,s_hour*60+s_minute,e_hour*60+e_minute,cost);

} {

else

InsertTrain(name,s_city,e_city,s_hour*60+s_minute,e_hour*60+e_minute,cost);

}

SaveSysInfo();

printf(\ break; case 4: //删除路线 InitSysData(); printf(\输入班次:\ scanf(\ DelPath(name); SaveSysInfo();

printf(\ break; case 5: //最小耗费 InitSysData();

printf(\起始城市:\ scanf(\ startcity=SeekCity(name); if (startcity<0)

{

printf(\City Name:No such

页脚

city!\\n\

break;

}

printf(\终点城市:\ scanf(\ endcity=SeekCity(name); if (endcity<0)

{

printf(\city!\\n\

break;

}

printf(\类型(列车0,航班1) :\ scanf(\

if (traveltype!=0&&traveltype!=1)

{

printf(\ break;

}

CalcMinCost(startcity,endcity,traveltype); printf(\ break;

case 6: //最短时间路线 InitSysData();

printf(\起始城市:\ scanf(\ startcity=SeekCity(name); if (startcity<0)

{

printf(\City Name:No such city!\\n\

break;

}

printf(\终点城市:\

页脚

scanf(\ endcity=SeekCity(name); if (endcity<0)

{

printf(\City Name:No such city!\\n\

break;

}

printf(\类型(列车0,航班1) :\ scanf(\

if (traveltype!=0&&traveltype!=1)

{

printf(\ break;

}

CalcMinTime(startcity,endcity,traveltype); printf(\ break; } } }

四、主函数中的各个调用的函数代码具体如下:

(1)显示菜单: int ShowMenu() {

printf(\

printf(\添加城市\\n2: 删除城市\\n3: 添加交通路线\\n4: 删除交通路线\\n5: 查询最小费用路线\\n6: 查询最快路线\\n0: 退出\ printf(\ printf(\ return 1; }

(2)查找城市并返回城市序号:

页脚

int SeekCity (char *name) {

int i;

for (i=0;i

(3)储存信息到文件: int SaveSysInfo() {

FILE *fp;int i,j,total; fp=fopen(CityFile,\ fprintf(fp,\ for (i=0;i

{ }

fprintf(fp,\ fclose(fp);total=0; fp=fopen(TrainFile,\ for (i=0;i

{ }

total+=AdjList[i].TrainNum; fprintf(fp,\ for (i=0;i

{

{

for (j=0;j

fprintf(fp,\ CityName[i],

{ }

{ }

if (strcmp(name,CityName[i])==0) return i;

return -1;

页脚

CityName[AdjList[i].Train[j].EndCity]); fprintf(fp,\AdjList[i].Train[j].StartTime/60,

AdjList[i].Train[j].StartTime`, AdjList[i].Train[j].StopTime/60, AdjList[i].Train[j].StopTime`, AdjList[i].Train[j].Cost);

} }

-:-

%d\\n\

fclose(fp);total=0; fp=fopen(FlightFile,\ for (i=0;i

{ }

total+=AdjList[i].FlightNum; fprintf(fp,\ for (i=0;i

{

{

for (j=0;j

fprintf(fp,\ CityName[i],

CityName[AdjList[i].Flight[j].EndCity]); fprintf(fp,\AdjList[i].Flight[j].StartTime/60,

AdjList[i].Flight[j].StartTime`, AdjList[i].Flight[j].StopTime/60, AdjList[i].Flight[j].StopTime`, AdjList[i].Flight[j].Cost); }

(4)添加城市:

int InsertCity (char *Name)

} }

-:-

%d\\n\

fclose(fp);return 1;

页脚