数据结构课程设计交通咨询系统设计_第1页
数据结构课程设计交通咨询系统设计_第2页
数据结构课程设计交通咨询系统设计_第3页
数据结构课程设计交通咨询系统设计_第4页
数据结构课程设计交通咨询系统设计_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、设计题目 二:交通咨询系统设计 P160一、设计要求1 .问题描述根据不同目的的旅客对交通工具有不同的要求。例如,因公出差的旅客 希望在旅途中的时间尽可能的短,出门旅行的旅客希望旅费尽可能的少, 而老年 人则要求中转次数少。模拟一个全国城市之间的咨询交通程序,为旅客提供两种 或三种最优的交通路线。2 .需求分析二、概要设计1 .主界面设计jPpT rnTA)JMMWKMKW I益刖入你的选择;n*w*u_u (jw 彳* *E*K* 彳*(图“交通咨询系统”主菜单)2 .存储结构设计本系统采用图结构类型存储抽象交通咨询系统的信息。typedef struct TrafficNode无向网操作模

2、块min = AdjListtracki.Traink.Cost;tmp = k;printf(%s, AdjListtracki.T);printf(%2d:%2d-%2d:%2d,AdjListtracki.Traintmp.StartTime / 60,AdjListtracki.Traintmp.StartTime % 60,AdjListtracki.Traintmp.StopTime / 60,AdjListtracki.Traintmp.StopTime % 60);elsefor (i-; i0; i-)printf(n%s:, CityNametrac

3、ki);end = tracki - 1; min = 32767;for (k = 0; kAdjListtracki.Flightk.Cost)min = AdjListtracki.Flightk.Cost;tmp = k;printf(%s, AdjListtracki.F);printf(%2d:%2d-%2d:%2d,AdjListtracki.Flighttmp.StartTime / 60,AdjListtracki.Flighttmp.StartTime % 60,AdjListtracki.Flighttmp.StopTime / 60,AdjLi

4、sttracki.Flighttmp.StopTime % 60);printf(n%s: DESTINATION!, CityNametrack0);printf(nMin Cost: %dn, cost); void Dijkstra(int matxDij_MAXNDij_MAXN, int p_start, int p_end, intTravelType)int PreCityDij_MAXN;添加城市在主菜单下,用户输入1,添加城市名称,输入你的选择这加入城市名二制Sy与ten InfqOKt(图添加城市)2 .删除城市在主菜单下,用户输入2,删除已添加城市名称直输入你的选= 2北

5、上翳到3城市,请重新输入! System InFo Saue OK?(图删除城市)3 .添加交通路线在主菜单下,用户输入3,已添加城市名称。添加起始城市、终点城市名称、乘 车类型、乘车班次、起始时刻、终点时刻、和票价。(图添加交通路线)4 .删除交通路线输入班次号,删除交通路线(图删除交通路线)5 .查询最小费用交通路线清输入你的选择工也搬市=BB色量修眸撕血、二0Tu*ack Lla.y:BB:T55 0: 9 9: 8RH: DESTINATION*in Cost = 567(图查询最小费用交通路线)6 .查询最快交通路线(图查询最快交通路线)7 .清除屏幕8 .退出六、用户手册使用本系统

6、时,用户需先向程序添加城市后,在已有城市基础上添加已有城市的 路线和使用各项功能。七、调试报告程序运行无错误,但当系统输入其他无储存内容时程序会意外中断,代码需要优化。八、程序清单#include #include #include #include # define ERR 0# define OK 1# define Dij_MAXN 100# define MAX_VERTEX_NUM 100# define MAX_STRING_NUM 100# define MAX_TRAFFIC_NUM 100const char CityFile = ;const char TrainFile

7、= ;const char FlightFile = ;typedef short int CityType;rainNum;fprintf(fp, %dn, total); rainNum; j+) ,CityNamei,CityNameAdjListi.Trainj.EndCity);fprintf(fp, %2d:%2d %2d:%2d %dn,AdjListi.Trainj.StartTime / 60, rainj.StartTime % 60,AdjListi.Trainj.StopTime / 60,AdjListi.Trainj.StopTime % 60,

8、 AdjListi.Trainj.Cost);fclose(fp); total = 0;fp = fopen(FlightFile, w);for (i = 0; iCityNum; i+)total += AdjListi.FlightNum;fprintf(fp, %dn, total);for (i = 0; iCityNum; i+)for (j = 0; jAdjListi.FlightNum; j+)fprintf(fp, %s %s %s , AdjListi.F,CityNamei,CityNameAdjListi.Flightj.EndCity);fp

9、rintf(fp, %2d:%2d %2d:%2d %dn,AdjListi.Flightj.StartTime / 60,AdjListi.Flightj.StartTime % 60,AdjListi.Flightj.StopTime / 60,AdjListi.Flightj.StopTime % 60, AdjListi.Flightj.Cost);fclose(fp); return 1;int InsertCity(char *Name) ity = CityNum;AdjListCityNum.FlightNum = 0;AdjListCityNum.TrainNum = 0;C

10、ityNum+;return 1;int DelCity(char *Name) lightNum = AdjListi + 1.FlightNum;AdjListi.TrainNum = AdjListi + 1.TrainNum;for (j = 0; j AdjListi.FlightNum; j+) lightj.Cost = AdjListi + 1.Flightj.Cost;AdjListi.Flightj.EndCity = AdjListi + 1.Flightj.EndCity;strcpy(AdjListi.F, AdjListi +1.Flightj

11、.name);AdjListi.Flightj.StartTime = AdjListi +1.Flightj.StartTime;AdjListi.Flightj.StopTime = AdjListi +1.Flightj.StopTime;CityNum-;return 1;int InsertTrain(char *train, char *StartCity, char *EndCity, intStartTime, int EndTime, int cost)int i, j; rainAdjListi.TrainNum.Cost = cost;AdjListi.TrainAdjL

12、isti.TrainNum.EndCity = j;AdjListi.TrainAdjListi.TrainNum.StartTime = StartTime;AdjListi.TrainAdjListi.TrainNum.StopTime = EndTime;strcpy(AdjListi.TrainAdjListi.TrainN, train);AdjListi.TrainNum+; lightAdjListi.FlightNum.Cost = cost;AdjListi.FlightAdjListi.FlightNum.EndCity = j;AdjListi.Flight

13、AdjListi.FlightNum.StartTime = StartTime;AdjListi.FlightAdjListi.FlightNum.StopTime = EndTime;strcpy(AdjListi.TrainAdjListi.FlightN, flight);AdjListi.FlightNum+;return 1;int DelPath(char *name)int i, j, flag = 0;for (i = 0; iCityNum; i+)for (j = 0; jAdjListi.FlightNum; j+) , name)

14、= 0)flag = 1; break;if (flag)for (; jAdjListi.FlightNum - 1; j+) lightj.Cost =AdjListi.Flightj + 1.Cost;AdjListi.Flightj.EndCity = AdjListi.Flightj +1.EndCity;strcpy(AdjListi.F, AdjListi.Flightj +1.name);AdjListi.Flightj.StartTime = AdjListi.Flightj +1.StartTime;AdjListi.Flightj.StopTime

15、= AdjListi.Flightj +1.StopTime;AdjListi.FlightNum-; break;for (j = 0; jAdjListi.TrainNum; j+)if (strcmp(AdjListi.T, name) = 0)flag = 1; break;if (flag)for (; jAdjListtracki.Traink.Cost)min = AdjListtracki.Traink.Cost;tmp = k;printf(%s, AdjListtracki.T);printf(%2d:%2d-%2d:%2d,Ad

16、jListtracki.Traintmp.StartTime / 60,AdjListtracki.Traintmp.StartTime % 60,AdjListtracki.Traintmp.StopTime / 60,AdjListtracki.Traintmp.StopTime % 60);elsefor (i-; i0; i-)printf(n%s:, CityNametracki);end = tracki - 1; min = 32767;for (k = 0; kAdjListtracki.Flightk.Cost)min = AdjListtracki.Flightk.Cost

17、;tmp = k;printf(%s, AdjListtracki.F);printf(%2d:%2d-%2d:%2d,AdjListtracki.Flighttmp.StartTime / 60,AdjListtracki.Flighttmp.StartTime % 60,AdjListtracki.Flighttmp.StopTime / 60,AdjListtracki.Flighttmp.StopTime % 60);printf(n%s: DESTINATION!, CityNametrack0);printf(nMin Cost : %dn, cost);

18、void Dijkstra(int matxDij_MAXNDij_MAXN, int p_start, int p_end, intTravelType)int PreCityDij_MAXN; .n);return -1;fscanf(fp, %d, &CityNum);for (i = 0; iCityNum; i+)fscanf(fp, %s, &CityNamei);AdjListi.city = i;AdjListi.TrainNum = 0;AdjListi.FlightNum = 0;fclose(fp);fp = fopen(TrainFile, r);if (!fp)pri

19、ntf(nError:Cannot Open Train File.n);return -1;fscanf(fp, %d, &num);for (i = 0; inum; i+)fscanf(fp, %s, &stmp1); rainAdjListj.TrainNum.EndCity = SeekCity(stmp3); rainAdjListj.TrainN, stmp1);fscanf(fp, %d:%d, &hour, &minute);AdjListj.TrainAdjListj.TrainNum.StartTime = hour * 60 + minute;fscanf

20、(fp, %d:%d, &hour, &minute);AdjListj.TrainAdjListj.TrainNum.StopTime = hour * 60 + minute;fscanf(fp, %d, &cost);AdjListj.TrainAdjListj.TrainNum.Cost = cost;AdjListj.TrainNum+;fclose(fp);fp = fopen(FlightFile, r);if (!fp)printf(nError:Cannot Open Flight File.n);return -1;fscanf(fp, %d, &num);for (i =

21、 0; inum; i+)fscanf(fp, %s, &stmp1); lightAdjListj.FlightNum.EndCity = SeekCity(stmp3);strcpy(AdjListj.FlightAdjListj.FlightN, stmp1);fscanf(fp, %d:%d, &hour, &minute);AdjListj.FlightAdjListj.FlightNum.StartTime = hour * 60 + minute;fscanf(fp, %d:%d, &hour, &minute);AdjListj.FlightAdjListj.Fl

22、ightNum.StopTime = hour * 60 +minute;fscanf(fp, %d, &cost);AdjListj.FlightAdjListj.FlightNum.Cost = cost;AdjListj.FlightNum+;fclose(fp); return 1;int SearchMinTime(CityType City, CityType EndCity, int CurTime, intcurPathNo, int TravelType) ity = Pathi.City;MinPathi.TraNo = Pathi.TraNo;curPath = curP

23、athNo;MinTime = CurTime - StartTime;elsecurPathNo+;PathcurPathNo.City = City;if (!TravelType)for (i = 0; i= (CurTime %1440)& (AdjListCity.Traini.StopTime + (CurTime / 1440) * 1440 -StartTimeMinTime)PathcurPathNo.TraNo = i;SearchMinTime(AdjListCity.Traini.EndCity,EndCity, AdjListCity.Traini.StopTime

24、+ (CurTime / 1440) * 1440, curPathNo, TravelType);if (AdjListCity.Traini.StartTime(CurTime % 1440)& (AdjListCity.Traini.StopTime + (CurTime / 1440) * 1440 - StartTimeMinTime)PathcurPathNo.TraNo = i;SearchMinTime(AdjListCity.Traini.EndCity,EndCity, AdjListCity.Traini.StopTime + (CurTime / 1440 + 1) *

25、 1440, curPathNo, TravelType); elsefor (i = 0; i= CurTime) &(AdjListCity.Flighti.StopTime + (CurTime / 1440) * 1440 -StartTimeMinTime)PathcurPathNo.TraNo = i;SearchMinTime(AdjListCity.Flighti.EndCity,EndCity, AdjListCity.Flighti.StopTime + (CurTime / 1440) * 1440, curPathNo, TravelType);if (AdjListC

26、ity.Flighti.StartTimeCurTime) & (AdjListCity.Flighti.StopTime + (CurTime / 1440) * 1440 - StartTimeMinTime)PathcurPathNo.TraNo = i;SearchMinTime(AdjListCity.Flighti.EndCity,EndCity, AdjListCity.Flighti.StopTime+ (CurTime / 1440 + 1) * 1440,curPathNo, TravelType);return 1;int CalcMinTime(int StartCit

27、y, int EndCity, int TravelType)int i;MinTime = 32767; curPath = 0;Path0.City = StartCity;if (!TravelType)for (i = 0; iAdjListStartCity.TrainNum; i+)Path0.TraNo = i;StartTime = AdjListStartCity.Traini.StartTime;SearchMinTime(AdjListStartCity.Traini.EndCity, AdjListStartCity.Traini.StopTime, 0, Travel

28、Type);elsefor (i = 0; iAdjListStartCity.FlightNum; i+)Path0.TraNo = i;StartTime = AdjListStartCity.Flighti.StartTime;SearchMinTime(AdjListStartCity.Flighti.EndCity, AdjListStartCity.Flighti.StopTime, 0, TravelType);if (MinTime = 32767)printf(nNo access to that destination!);return 0;rainMinPath0.Tra

29、No.StartTime;lightMinPath0.TraNo.StartTime;printf(nPath:n);for (i = 0; i = curPath; i+)EndCity,EndCity,if (!TravelType)printf(%s : %s, CityNameMinPathi.City,AdjListMinPathi.City.TrainMinPathi.TraN);elseprintf(%s : %s, CityNameMinPathi.City,AdjListMinPathi.City.FlightMinPathi.TraN);printf

30、( %2d:%2d-%2d:%2dn,AdjListMinPathi.City.TrainMinPathi.TraNo.StartTime / 60,AdjListMinPathi.City.TrainMinPathi.TraNo.StartTime % 60,AdjListMinPathi.City.TrainMinPathi.TraNo.StopTime / 60,AdjListMinPathi.City.TrainMinPathi.TraNo.StopTime % 60);printf(%s: DESTINATION!, CityNameEndCity);printf(nTime Cos

31、t: %2d:%2d, MinTime / 60, MinTime % 60);return 1; int CalcMinCost(int StartCity, int EndCity, int TravelType) int maDij_MAXNDij_MAXN;int i, j, min, end;for (i = 0; iCityNum; i+)for (j = 0; jCityNum; j+)maij = -1;if (TravelType = 0)for (i = 0; iCityNum; i+)min = 32767; j = 0;while (jAdjListi.TrainNum

32、)min = 32767;end = AdjListi.Trainj.EndCity;while (end =AdjListi.Trainj.EndCity&jAdjListi.TrainNum)if (AdjListi.Trainj.Costmin)min = AdjListi.Trainj.Cost;j+;maiend = min;elsefor (i = 0; iCityNum; i+)min = 32767; j = 0;while (jAdjListi.FlightNum)min = 32767;end = AdjListi.Flightj.EndCity;while (end =A

33、djListi.Flightj.EndCity&jAdjListi.FlightNum)if (AdjListi.Flightj.Costmin)(min = AdjListi.Flightj.Cost;j+;maiend = min;Dijkstra(ma, StartCity, EndCity, TravelType);return 1;/=Main ()=int main()(char nameMAX_STRING_NUM; /城市名char s_cityMAX_STRING_NUM; / 始发站char e_cityMAX_STRING_NUM; / 终点站int Command, c

34、ost;int startcity, endcity, traveltype;int s_hour, s_minute, e_hour, e_minute;while (1)(CopyRight();/ 版权信息ShowMenu(); / 主菜单scanf(%d, &Command);/ 输入选择 switch (Command) / 对菜单的内容进行选择 case 0: / 退出return 0;case 1: / 添加城市InitSysData(); / 读出文档中已存的信息 printf(n 输入城市名 :); scanf(%s, &name); / 输入城市名 InsertCity(n

35、ame); / 将城市插入到数组中 SaveSysInfo(); / 把城市的信息写入文档中 printf(System Info Save OK!n); break;case 2: / 删除城市InitSysData(); / 读出文档中已有的信息 printf(n 输入城市名 :); scanf(%s, &name);DelCity(name); /将城市删除SaveSysInfo(); /将处理过的信息写入文档中printf(System Info Save OK!n); break;case 3: / 添加路线InitSysData();printf(起始站城市名:);scanf(%s

36、, &s_city); /起始站printf(终点站城市名:);scanf(%s, &e_city); /终点站printf( 类型(列车0,航班 1) :);scanf(%d, &traveltype);printf( 输入列车 / 飞机班次 :);scanf(%s, &name);printf(起始时刻(00:00 , 24 小时制):);scanf(%2d:%2d, &s_hour, &s_minute);printf(到达时刻(00:00 , 24 小时制):);scanf(%2d:%2d, &e_hour, &e_minute);printf( 票价 :);scanf(%d, &cost);if (traveltype)InsertFlight(name, s_city, e_city, s_hour * 60 + s_minute, e_hour * 60 + e_mi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论