资源简介
Experiment 2 Europe by Rail RailSystem.cpp 可运行
代码片段和文件信息
#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
- 上一篇:深度学习文本识别数据集
- 下一篇:数据可视化大作业
相关资源
- STM32 dsp库
- 用于车牌识别的字符模板,数字,字
- 窗体程序爬虫
- STC89C52RC 智能家居设计(GSM+人体红外
- 2015_MLDN_mybatis_hibernate_springmvc_等视频
- SOT-23-3包含3D
- 《lcd1602仿真》
- 《21个项目玩转深度学习:基于Tenso
- 基于Systemview的2FSK调制
- ZigBee CC2530,基础实验的代码汇集
- 计算机考研王道四本资料
- ArcGis10.2目视解译教程
- NOI2016DAY1试题
- CST2014安装包与破解文件和安装教程
- STM32F103之实验2控制1个电机并采用编码
- 1602LCD 库文件
- msp430g2553红外遥控小程序
- Origin pro9.0/Origin pro 2017使用一段时间后
- CHZ 9010-2011 地理信息公共服务平台 地
- 智能小车原理图PCB
- VOC增强数据集的数据索引文件
- 卷积编解码,实现了2/33/4删余卷积
- 2019全国高校名单数据
- 基于STM32F1 Modbus通信源代码
- 基于s3c2410的嵌入式时钟设计源码
- rufus-2.18
- 120个微信小程序
- OlePointCloud20190819.rar
- RC522模块程序.rar
- 数画通_70@2150232.rar
评论
共有 条评论