Skip to content
Snippets Groups Projects
Commit 52bce8b4 authored by Andreas Blakli's avatar Andreas Blakli
Browse files

La til:

lesFraFil() funk.
skrivTilFil() funk.
i stoppested.cpp og stoppested.h.
parent f5c0445b
No related branches found
No related tags found
No related merge requests found
...@@ -45,14 +45,16 @@ void Stoppested::skrivData() { ...@@ -45,14 +45,16 @@ void Stoppested::skrivData() {
void Stoppested::skrivDataMedNaboer(vector<Stoppested*> alleStoppesteder) { void Stoppested::skrivDataMedNaboer(vector<Stoppested*> alleStoppesteder) {
skrivData(); skrivData();
int i = 0; int i, pos;
i = pos = 0;
bool naboEksisterer = false; bool naboEksisterer = false;
cout << "\nHar forbindelser til:"; // << '\n'; cout << "\nHar forbindelser til:"; // << '\n';
for (const auto& val : indexNaboStoppene) { for (const auto& val : indexNaboStoppene) {
cout << "\nSize indexes naboer: " << indexNaboStoppene.size(); cout << "\nSize indexes naboer: " << indexNaboStoppene.size();
cout << "\nSize tid: " << antallMinutterTilNaboStopp.size(); cout << "\nSize tid: " << antallMinutterTilNaboStopp.size();
if (val < alleStoppesteder.size()) { if (val < alleStoppesteder.size()) {
cout << "\n\t" << i + 1 << " - Navn: " << alleStoppesteder[val]->hentNavn() pos++;
cout << "\n\t" << i + pos << " - Navn: " << alleStoppesteder[val]->hentNavn()
<< '\t' << '\t'
<< "Tid i minutter mellom stopp: " << antallMinutterTilNaboStopp[i]; << "Tid i minutter mellom stopp: " << antallMinutterTilNaboStopp[i];
//<< '\n'; //<< '\n';
...@@ -162,3 +164,46 @@ int Stoppested::hentTidForsteNabo() { ...@@ -162,3 +164,46 @@ int Stoppested::hentTidForsteNabo() {
return antallMinutterTilNaboStopp.front(); return antallMinutterTilNaboStopp.front();
return -1; return -1;
} }
void Stoppested::lesFraFil(ifstream& inn) {
string heleLinjen = "";
getline(inn, heleLinjen);
int pos = 0;
vector<string> linjenSplittet = hjelp.splittStreng('*', heleLinjen);
int storrelse = linjenSplittet.size();
cout << "\nStorrelse splittet: " << storrelse << "\n\n";
for (int i = 0; i < storrelse - 1; i++) {
switch (i) {
case 0:
navn = linjenSplittet[0];
break;
case 1:
indexNaboStoppene.push_back(stoi(linjenSplittet[1]));
break;
case 2: {
if (storrelse > 5)
indexNaboStoppene.push_back(stoi(linjenSplittet[2]));
else
antallMinutterTilNaboStopp.push_back(stoi(linjenSplittet[2]));
break;
}
case 3:
antallMinutterTilNaboStopp.push_back(stoi(linjenSplittet[3]));
break;
case 4:
antallMinutterTilNaboStopp.push_back(stoi(linjenSplittet[4]));
break;
}
}
}
void Stoppested::skrivTilFil(ofstream& ut) {
ut << navn << '*';
for (const auto& val : indexNaboStoppene) {
ut << val << '*';
}
for (const auto& val : antallMinutterTilNaboStopp) {
ut << val << '*';
}
ut << '\n';
}
\ No newline at end of file
#ifndef __STOPPESTED_H #ifndef __STOPPESTED_H
#define __STOPPESTED_H #define __STOPPESTED_H
#include <fstream>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -42,5 +43,7 @@ class Stoppested { ...@@ -42,5 +43,7 @@ class Stoppested {
void leggTilNaboBakerst(const int & index, const int & tid); void leggTilNaboBakerst(const int & index, const int & tid);
int hentAntallStoppestedVector(); int hentAntallStoppestedVector();
int hentTidForsteNabo(); int hentTidForsteNabo();
void lesFraFil(std::ifstream& inn);
void skrivTilFil(std::ofstream & ut);
}; };
#endif //__STOPPESTED_H #endif //__STOPPESTED_H
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment