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

litt lengre

parent c340ff6b
Branches Sondre
No related tags found
No related merge requests found
/**
* 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(){
//}
......@@ -26,6 +26,7 @@ class Rute {
std::list <Stopp*> stoppene;
public:
Rute();
};
......
/**
* 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() {
}
......@@ -55,5 +55,7 @@ void Stoppested::skrivData() {
cout << setw(20) << navn;
}
std::vector <int> Stoppested::hentTTN() {
return tidtilnabo;
}
......@@ -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();
};
......
......@@ -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
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment