• 大小: 2KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-12
  • 语言: 其他
  • 标签: Experiment  2  Europe  by  Rail  

资源简介

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


评论

共有 条评论