Repository navigation
Expand file tree
/
Copy pathPCC.cpp
More file actions
42 lines (37 loc) · 1.58 KB
/
Copy pathPCC.cpp
File metadata and controls
42 lines (37 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "PCC.h"
#include <iostream>
#include "DesignByContract.h"
#include "MetroNet.h"
PCC::PCC() : Tram() {
zitplaatsen = 16;
ENSURE(properlyInitialized(), "constructor must end in properlyInitialized state");
}
PCC::PCC(const int lijnNr, const int voertuigNr,
const int zitplaatsen, const std::string& beginStation,
const int snelheid)
: Tram(lijnNr, voertuigNr, zitplaatsen, beginStation, snelheid) {
REQUIRE(beginStation != "", "newBeginStation must not be empty");
REQUIRE(lijnNr >= 0 , "lijnNr must be bigger or equal to zero");
REQUIRE(voertuigNr >= 0 , "voertuigNr must be bigger or equal to zero");
REQUIRE(zitplaatsen >= 0 , "zitplaatsen must be bigger or equal to zero");
REQUIRE(snelheid >= 0 , "snelheid must be bigger or equal to zero");
ENSURE(properlyInitialized(), "constructor must end in properlyInitialized state");
}
PCC::~PCC() {}
bool PCC::stoptInStation(MetroNet& metronet, std::string station) const {
REQUIRE(properlyInitialized(), "PCC wasn't initialized when calling afstappenInHalte");
REQUIRE(metronet.properlyInitialized(), "MetroNet wasn't initialized when calling afstappenInHalte");
REQUIRE(station != "", "station must not be empty");
std::string current = getCurrentStation();
if (current == station) {
return true;
}
std::string nextStation = metronet.getStation(current)->getVolgende(lijnNr);
while (nextStation != current) {
if (nextStation == station) {
return true;
}
nextStation = metronet.getStation(nextStation)->getVolgende(lijnNr);
}
return false;
}