Skip to content
Snippets Groups Projects
Commit c340ff6b authored by Sondre Sand's avatar Sondre Sand
Browse files

fortsetter å jobbe med RN

parent 41c74e81
No related branches found
No related tags found
No related merge requests found
/**
* 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
......@@ -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
}
}
/**
......
/**
* 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
}
......@@ -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();
};
......
......@@ -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
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment