diff --git a/rute.cpp b/rute.cpp index 133519a11e217425a4cb694270091e193189bddd..68f75167195a04e249198bc0b63fc8938be81326 100644 --- a/rute.cpp +++ b/rute.cpp @@ -1,6 +1,6 @@ /** * Kode-fil for rute-klassen - * + * * @file rute.cpp * @author Sondre Sand & Frederik Simonsen */ @@ -11,3 +11,6 @@ using namespace std; // TODO: Fyll på her etter som header-fila tar mer form +//Rute::Rute(){ + +//} diff --git a/rute.h b/rute.h index a65270b01441e04d8f1d92442fe27a82e7de5379..1fbc3b3fcecaf57502d92161ac366a35c6648546 100644 --- a/rute.h +++ b/rute.h @@ -26,6 +26,7 @@ class Rute { std::list <Stopp*> stoppene; public: + Rute(); }; diff --git a/ruter.cpp b/ruter.cpp index 4bf06f7e544f01a0fe529ae7a17807730dd9dbf3..ec3f0120623c191a2e36a0288a19e01c62c17f48 100644 --- a/ruter.cpp +++ b/ruter.cpp @@ -1,6 +1,6 @@ /** * Kode-fil for ruter-klassen - * + * * @file ruter.cpp * @author Sondre Sand & Frederik Simonsen */ @@ -51,26 +51,35 @@ void Ruter::lesFraFil() { } /** Lager en rute - * - * + * + * */ void Ruter::nyRute() { char valg; string nvn; int key, index; + vector <int> tid; Rute* nyTransport = nullptr; key = lesInt("\nNytt rutenummer: ", 1, 999); rutene[key] = new Rute(); valg = lesChar("\nB(u)ss eller B(a)ne?: "); switch (valg) { - case 'U': nyTransport = new Buss; break; - case 'A': nyTransport = new Bane; break; - cout << "Stoppested navn: "; - getline(cin, nvn); gStoppestederBase.finnDuplikat(nvn); + case 'U': rutene[key] = new Buss; break; + case 'A': rutene[key] = new Bane; break; + } + cout << "\nStoppested navn: "; getline(cin, nvn); + while (!gStoppestederBase.sjekkNavn(nvn)){ + cout << "\nStoppestedet finnes ikke! "; + cout << "\nStoppested navn: "; getline(cin, nvn); + } index = gStoppestederBase.finnIndex(nvn); cout << "index tall: " << index; //test for å se om finnIndex fungerer + + + if(tid.size()==0){ + cout << "Tid til neste stopp: "; } } @@ -111,5 +120,5 @@ void Ruter::skrivMeny() { * Skriver informasjon om ruter til fil */ void Ruter::skrivTilFil() { - + } diff --git a/stoppested.cpp b/stoppested.cpp index 6f765977a830fae88757019c6873f1eb4a86fece..585e7f3a1ef5c110668cc8441362c0e3a319d698 100644 --- a/stoppested.cpp +++ b/stoppested.cpp @@ -55,5 +55,7 @@ void Stoppested::skrivData() { cout << setw(20) << navn; } - +std::vector <int> Stoppested::hentTTN() { + return tidtilnabo; +} diff --git a/stoppested.h b/stoppested.h index 1357821f94b7d2cb25d426612c5593131f29910f..4e53cd2d5078dcacb3f8c593af6437d2af973a2c 100644 --- a/stoppested.h +++ b/stoppested.h @@ -25,8 +25,8 @@ class Stoppested { Stoppested(); Stoppested(std::string nvn, std::ifstream & inn); Stoppested(const std::string nvn); + std::vector <int> hentTTN(); std::string hentStoppestedNavn(); - int hentTTN(); void skrivData(); void lesData(); }; diff --git a/stoppesteder.cpp b/stoppesteder.cpp index f95e5a207ea1f7e6dc0fa8c050786a0c493dd7c1..16277a4bd13a45b051691c78eaad9543db413592 100644 --- a/stoppesteder.cpp +++ b/stoppesteder.cpp @@ -152,10 +152,35 @@ void Stoppesteder::skrivTilFil() { } int Stoppesteder::finnIndex(const string nvn) { - auto it = find(stopper.begin(), stopper.end(), nvn); - if(it!=stopper.end()) { - int index = distance(stopper.begin(), it); - return index; - }else cout << "Ikke funnet " << nvn; - + for (int i=0; i < stopper.size(); i++){ + string navn=stopper[i]->hentStoppestedNavn(); + if(navn==nvn){ + return i; + } + } +} + +bool Stoppesteder::sjekkNavn(const string nvn) { + for (int i=0; i < stopper.size(); i++) { + string navn=stopper[i]->hentStoppestedNavn(); + if(navn==nvn){ + return true; + }else return false; + } +} + +vector <int> Stoppesteder::sjekkTTN(const vector <int> indeks) { + vector <int> tom; + for (int i=0; i < stopper.size(); i++) { + vector <int> index=stopper[i]->hentTTN(); + if(indeks==index){ + return index; + }else return tom; +} + +vector <int> Stoppesteder::indexHentTTN(const vector <int> index) { + vector <int> TTN; + + TTN=stopper.at(index-1)->hentTTN(); + return TTN; } \ No newline at end of file diff --git a/stoppesteder.h b/stoppesteder.h index d0843dd7dbcd3164c68bc0d61b0d7e5850dd071f..6896f3009c8e80cd2d350f7d33ba8f1341859379 100644 --- a/stoppesteder.h +++ b/stoppesteder.h @@ -20,7 +20,10 @@ class Stoppesteder { std::vector <Stoppested*> stopper; public: Stoppested* finnDuplikat(std::string nvn); - int finnIndex(const std::string nvn); + int finnIndex(const std::string nvn); + bool sjekkNavn(const std::string nvn); + std::vector <int> sjekkTTN(const std::vector <int> index); + std::vector <int> indexHentTTN(const int index); void handling(); void nyStop(); void lesFraFil();