diff --git a/bane.h b/bane.h index b1e790e3eba6e79ba0b2eed6861cfb45df0a198a..5d154e81dc6279bbedd828863e5869913f07c397 100644 --- a/bane.h +++ b/bane.h @@ -1,6 +1,6 @@ /** * Header-fil for bane-klassen (Subklasse av ruteklassen) - * + * * @file bane.h * @author Sondre Sand & Frederik Simonsen */ @@ -15,9 +15,10 @@ class Bane : public Rute { private: int antVogner, lengde; - + public: - + Bane(); + }; -#endif \ No newline at end of file +#endif diff --git a/ruter.cpp b/ruter.cpp index b1943b9f6248e58585ceb5186d45ac142d603262..4bf06f7e544f01a0fe529ae7a17807730dd9dbf3 100644 --- a/ruter.cpp +++ b/ruter.cpp @@ -6,6 +6,7 @@ */ #include <iostream> #include <map> +#include <string> #include "LesData3.h" #include "ruter.h" #include "rute.h" @@ -55,7 +56,10 @@ void Ruter::lesFraFil() { */ void Ruter::nyRute() { char valg; - int key; + string nvn; + int key, + index; + Rute* nyTransport = nullptr; key = lesInt("\nNytt rutenummer: ", 1, 999); rutene[key] = new Rute(); @@ -63,9 +67,11 @@ void Ruter::nyRute() { switch (valg) { case 'U': nyTransport = new Buss; break; case 'A': nyTransport = new Bane; break; - + cout << "Stoppested navn: "; + getline(cin, nvn); gStoppestederBase.finnDuplikat(nvn); + index = gStoppestederBase.finnIndex(nvn); + cout << "index tall: " << index; //test for å se om finnIndex fungerer } - } /** diff --git a/stoppested.cpp b/stoppested.cpp index 6b64c39431977739f73d64ade4b5e36ca475f6f1..6f765977a830fae88757019c6873f1eb4a86fece 100644 --- a/stoppested.cpp +++ b/stoppested.cpp @@ -1,6 +1,6 @@ /** * Kode-fil for stoppested-klassen - * + * * @file stoppested.cpp * @author Sondre Sand & Frederik Simonsen */ @@ -9,14 +9,18 @@ #include <string> #include <fstream> #include <vector> +#include <algorithm> #include "stoppested.h" +#include "stoppesteder.h" using namespace std; +extern Stoppesteder gStoppestederBase; + /** * Run-time constructor, ifm. menyvalg S N. * Kopierer medsendt unikt navn til å bli navn * på stoppestedet - * + * * @param nvn - Stoppestedets unike navn som er duplikatsjekket */ Stoppested::Stoppested(const string nvn) { @@ -25,18 +29,18 @@ Stoppested::Stoppested(const string nvn) { /** * Constructor for å lese data dra fil - * + * * @param - samme som index for å vite hva som leses inn */ Stoppested::Stoppested(std::string nvn, ifstream & inn) { navn = nvn; - + } /** * Returnerer et Stoppesteds unike navn - * + * * @return Stoppestedets navn */ string Stoppested::hentStoppestedNavn() { @@ -49,4 +53,7 @@ string Stoppested::hentStoppestedNavn() { */ void Stoppested::skrivData() { cout << setw(20) << navn; -} \ No newline at end of file +} + + + diff --git a/stoppested.h b/stoppested.h index 62797f1a25b2316105301938eca14452e0e1a9d9..1357821f94b7d2cb25d426612c5593131f29910f 100644 --- a/stoppested.h +++ b/stoppested.h @@ -26,6 +26,7 @@ class Stoppested { Stoppested(std::string nvn, std::ifstream & inn); Stoppested(const std::string nvn); std::string hentStoppestedNavn(); + int hentTTN(); void skrivData(); void lesData(); }; diff --git a/stoppesteder.cpp b/stoppesteder.cpp index 6ee5772bf601139699ea24aa55e1dc9bb3e2ada6..f95e5a207ea1f7e6dc0fa8c050786a0c493dd7c1 100644 --- a/stoppesteder.cpp +++ b/stoppesteder.cpp @@ -8,6 +8,7 @@ #include <iostream> #include <vector> #include <fstream> +#include <algorithm> #include "LesData3.h" #include "stoppested.h" #include "stoppesteder.h" @@ -148,4 +149,13 @@ void Stoppesteder::skrivMeny() { */ 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; + } \ No newline at end of file diff --git a/stoppesteder.h b/stoppesteder.h index fe132b87a3eb2bbdcec3825c9d5cac90060cf376..d0843dd7dbcd3164c68bc0d61b0d7e5850dd071f 100644 --- a/stoppesteder.h +++ b/stoppesteder.h @@ -20,6 +20,7 @@ class Stoppesteder { std::vector <Stoppested*> stopper; public: Stoppested* finnDuplikat(std::string nvn); + int finnIndex(const std::string nvn); void handling(); void nyStop(); void lesFraFil();