-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAlbatros.cpp
44 lines (39 loc) · 1.76 KB
/
Albatros.cpp
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
43
44
#include "Albatros.h"
#include <iostream>
#include "DesignByContract.h"
#include "MetroNet.h"
Albatros::Albatros() : Tram() {
zitplaatsen = 72;
ENSURE(properlyInitialized(), "constructor must end in properlyInitialized state");
}
Albatros::Albatros(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");
}
Albatros::~Albatros() {}
bool Albatros::stoptInStation(MetroNet& metronet, std::string station) const {
REQUIRE(properlyInitialized(), "Albatros wasn't initialized when calling stoptInStation");
REQUIRE(metronet.properlyInitialized(), "MetroNet wasn't initialized when calling stoptInStation");
REQUIRE(station != "", "station must not be empty");
std::string current = getCurrentStation();
if (current == station) {
if (!metronet.getStation(station)->albatrosCanStop()) return false;
return true;
}
std::string nextStation = metronet.getStation(current)->getVolgende(lijnNr);
while (nextStation != current) {
if (nextStation == station) {
if (!metronet.getStation(station)->albatrosCanStop()) return false;
return true;
}
nextStation = metronet.getStation(nextStation)->getVolgende(lijnNr);
}
return false;
}