資源簡介
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?“?<????}?else?{
????????out?<“The?cheapest?route?from?“?<????????out?<“costs?“?<????????<“?kilometers\n“;
????????cout?<????}
}
bool?RailSystem::is_valid_cit
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????6599??2017-06-19?16:17??實驗源代碼2\RailSystem.cpp
?????目錄??????????0??2017-06-23?21:50??實驗源代碼2
-----------?---------??----------?-----??----
?????????????????6599????????????????????2
- 上一篇:深度學習文本識別數據集
- 下一篇:數據可視化大作業
評論
共有 條評論