From 84cef7b60bd72010600b846038f72ea37c870bf1 Mon Sep 17 00:00:00 2001
From: sondsand <sondsand@stud.ntnu.no>
Date: Mon, 28 Mar 2022 16:17:45 +0200
Subject: [PATCH] litt lengre

---
 rute.cpp         |  5 ++++-
 rute.h           |  1 +
 ruter.cpp        | 25 +++++++++++++++++--------
 stoppested.cpp   |  4 +++-
 stoppested.h     |  2 +-
 stoppesteder.cpp | 37 +++++++++++++++++++++++++++++++------
 stoppesteder.h   |  5 ++++-
 7 files changed, 61 insertions(+), 18 deletions(-)

diff --git a/rute.cpp b/rute.cpp
index 133519a..68f7516 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 a65270b..1fbc3b3 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 4bf06f7..ec3f012 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 6f76597..585e7f3 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 1357821..4e53cd2 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 f95e5a2..16277a4 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 d0843dd..6896f30 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();
-- 
GitLab