设为首页 加入收藏

TOP

7.5.5 公交换乘的实现(5)
2013-10-07 14:53:18 来源: 作者: 【 】 浏览:61
Tags:7.5.5 公交换乘 实现

7.5.5  公交换乘的实现(5)

上述代码中通过参数传递开始站、终点站和线路,通过遍历记录集找到相应的线路,找到开始站时就开始计数,如果站点为终点站时变量flag为false就停止计数,则变量busnum中保存的就是两个站点间的站点数。函数Match()实现对站点进行匹配。其中的代码如下所示:

代码位置:见光盘中本章源代码的CInfoMatio类。

  1. 1  BOOL CInfoMation::Match(CString percept,CString station)  
  2. 2  {  
  3. 3   CStationSet m_StationSet;                               //定义记录集对象  
  4. 4   bool flag=false;                                        //定义布尔变量  
  5. 5   if(!m_StationSet.IsOpen())                              //打开记录集  
  6. 6       m_StationSet.Open();  
  7. 7   for(int i=0;i<e_road;i++)                               //路线比较  
  8. 8   {  
  9. 9       m_StationSet.MoveFirst();                           //移动到首条记录  
  10. 10          while(!m_StationSet.IsEOF())                        //遍历记录集  
  11. 11          {  
  12. 12              if(m_StationSet.m_ID==E_RoadWay[i]&&m_StationSet.m_ID=  
  13. 13                    percept&&m_StationSet.m_STATION==station)  
  14. 14              {  
  15. 15                  m_percept=m_StationSet.m_ID;  
  16. 16                  flag=true;                              //设置标记  
  17. 17                  return 1;  
  18. 18              }  
  19. 19              else  
  20. 20                  m_StationSet.MoveNext();                    //移动到下一条记录  
  21. 21          }  
  22. 22      }  
  23. 23      if(!flag)                                           //返回值  
  24. 24          return 0;  
  25. 25      else  
  26. 26          return 1;  
  27. 27  }  

第7~22行代码为查找匹配站点的信息。

第23~26行代码为函数的返回值。

上述代码中变量e_road保存了所有经过终点站的车次的总数,数组E_RoadWay中保存了经过终点站的所有车次,通过遍历记录集查找符合条件的站点。函数Precept()实现了生成乘车方案。该函数中的代码如下:

代码位置:见光盘中本章源代码的CInfoMatio类。

  1. 1  BOOL CInfoMation::Precept(CString start,CString end)  
  2. 2  {  
  3. 3   CString str;                                            //定义字符串变量  
  4. 4   CStationSet m_StationSet;                               //定义记录集对象  
  5. 5   CMapPublicApp *app=(CMapPublicApp *)AfxGetApp();        //获取应用类指针  
  6. 6   if(!m_StationSet.IsOpen())                              //打开记录集  
  7. 7       m_StationSet.Open();  
  8. 8   m_StationSet.MoveFirst();                               //移动到首条记录  
  9. 9   for(int i=0;i<s_road;i++)  
  10. 10      {  
  11. 11          while(!m_StationSet.IsEOF())                        //遍历记录集  
  12. 12          {  
  13. 13              if(m_StationSet.m_ID==S_RoadWay[i])         //查找线路  
  14. 14              {  
  15. 15                  if(Match(m_StationSet.m_ID,m_StationSet.m_STATION))  
  16. 16                  {  
  17. 17                      str.Format("\r\n方案%d: 从%s乘 %s路 到 %s转乘 %s路 到%s下车",  
  18. 18                      Num,start,m_StationSet.m_ID,m_StationSet.m_STATION,m_   
  19. percept,end);  
  20. 19                      app->m_show+=str;  
  21. 20                      m_BusRoad[Num_BusRoad].Precept=Num++;  
  22. 21                          m_BusRoad[Num_BusRoad++].Number=  
  23. 22                             Dif_StationNum(start,m_StationSet.m_ID,  
  24. 23                             m_StationSet.m_STATION,m_percept,end);  
  25. 24                      m_percept="";  
  26. 25                      break;  
  27. 26                  }  
  28. 27              }  
  29. 28              m_StationSet.MoveNext();                        //移动到下一条记录  
  30. 29          }  
  31. 30      }  
  32. 31      m_StationSet.Close();                                   //关闭记录集  
  33. 32      if(str!="")  
  34. 33          return 1;  
  35. 34      else  
  36. 35          return 0;  
  37. 36  }  

第9~30行代码为查找信息生成最佳的乘车方案。

第32~35行代码为函数的返回值。

上述代码中变量s_road保存了所有经过开始站的车次的总数,数组S_RoadWay中保存了经过开始站的所有车次,通过遍历记录集查找符合条件的站点,调用函数Match()查看站点是否匹配,生成乘车方案。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇7.5.4 车站查询的实现(2) 下一篇7.6.1 公交信息维护模块功能分析

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: