资源简介
Experiment 2 Europe by Rail RailSystem.cpp 可运行
![](http://www.nz998.com/pic/56921.jpg)
代码片段和文件信息
#include “RailSystem.h“
#define INT_MAX 2147483647
void RailSystem::reset(void) {
// TODO: reset the data objects of the
// City objects‘ contained in cities
map::iterator it = cities.begin();
while (it != cities.end())
{
it->second->total_distance = 0;
it->second->total_fee = 0;
it->second->visited = false;
it->second->from_city = ““;
it ++;
}
}
RailSystem::RailSystem(string const &filename) {
load_services(filename);
}
void RailSystem::load_services(string const &filename) {
ifstream inf(filename.c_str());
string from to;
int fee distance;
if ( inf.good() ) {
// Read in the from city to city the fee and distance.
inf >> from >> to >> fee >> distance;
while ( inf.good() ) {
// TODO: Add entries in the cities container and
// and services in the rail system for the new
// cities we read in.
string targe = from;
list serviceList;
//put the info into the same city
while (targe == from)
{
Service * newService = new Service(to fee distance);
serviceList.push_back(newService);
if (inf.good())
{
inf >> from >> to >> fee >> distance;
}
else
{
from = ““;
}
}
//put the city connection into the map.
outgoing_services.insert(pair >(targe serviceList));
}
}
map >::iterator it = outgoing_services.begin();
//give info to the cities.
while (it != outgoing_services.end())
{
City * newCity = new City(it->first);
cities.insert(pair(it->first newCity));
it++;
}
inf.close();
}
RailSystem::~RailSystem(void) {
// TODO: release all the City* and Service*
// from cities and outgoing_services
map >::iterator it_serviceList = outgoing_services.begin();
while (it_serviceList != outgoing_services.end())
{
list::iterator it_service = it_serviceList->second.begin();
while (it_service != it_serviceList->second.end())
{
delete *it_service;
it_service++;
}
it_serviceList++;
}
map::iterator it_city = cities.begin();
while (it_city != cities.end())
{
delete it_city->second;
it_city++;
}
}
void RailSystem::output_cheapest_route(const string& from
const string& to ostream& out) {
reset();
pair totals = calc_route(from to);
if (totals.first == INT_MAX) {
out << “There is no route from “ << from << “ to “ << to << “\n“;
} else {
out << “The cheapest route from “ << from << “ to “ << to << “\n“;
out << “costs “ << totals.first << “ euros and spans “ << totals.second
<< “ kilometers\n“;
cout << recover_route(to) << “\n\n“;
}
}
bool RailSystem::is_valid_cit
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6599 2017-06-19 16:17 实验源代码2\RailSystem.cpp
目录 0 2017-06-23 21:50 实验源代码2
----------- --------- ---------- ----- ----
6599 2
- 上一篇:深度学习文本识别数据集
- 下一篇:数据可视化大作业
相关资源
- 登录注册界面.zip48872
- 电信中兴光猫超密获取工具使用方法
- 条码字体barcode128
- 易语言播放器组件无缝转换(Demo2.e)
- 价值2k的H漫画小说系统
- stm32f407上的两个can发送和接收例程
- Scrach 欢乐狙击手.sb2
- 04741计算机网络原理知识点整理.docx(
- 2018全国大学生计算机博弈大赛 棋谱
- 程序员专用字体YaHei.Consolas.1.11b42517
- STM32 led 时钟
- STM32 2.4G通信例程
- GBT 15532-2008 计算机软件测试规范
- Omron ETN21模块进行modbustcp通讯
- 200smart单按钮启停.smart
- 直流无刷电机方波驱动 stm32 例程代码
- 联想H61主板BIOS升级F9KT58AUS支持22NM.i
- 右键属性文件校验插件可同时生成十
- STM32中文资料
- IAR7.20H破解机注册机
- IAR-Keygen-2019+附使用教程.zip
- F28335无刷直流电机开闭环控制
- concept2.6无需安装1
- MCS_51单片机与8255A的接口设计
- cc2541 BLE DEMO
- CC2540、CC2541透传模块-AT指令手册
- cc2530寄存器手册
- 基于蓝牙4.0的设备通信方案设计与实
- STM32蓝牙和串口程序
- 联想扬天电脑用户手册
评论
共有 条评论