Skip to content
Snippets Groups Projects
Commit 4917a343 authored by Frederik Simonsen's avatar Frederik Simonsen
Browse files

R A funksjonalitet

parent 07b45bdf
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
* @file bane.cpp
* @author Sondre Sand & Frederik Simonsen
*/
#include <iostream>
#include <fstream>
#include "bane.h"
using namespace std;
......@@ -13,6 +14,14 @@ Bane::Bane(ifstream & inn) : Rute (inn) {
inn >> antVogner >> lengde; inn.ignore();
}
/**
* skrivData
*/
void Bane::skrivData() const {
cout << "(bane): ";
Rute::skrivData();
}
/**
* skrivTilFil(...)
*/
......
......@@ -19,6 +19,7 @@ class Bane : public Rute {
public:
Bane(std::ifstream & inn);
virtual void skrivData() const;
virtual void skrivTilFil(std::ofstream & ut);
};
......
......@@ -4,6 +4,8 @@
* @file buss.cpp
* @author Sondre Sand & Frederik Simonsen
*/
#include <iostream>
#include <fstream>
#include "buss.h"
using namespace std;
......@@ -12,6 +14,13 @@ Buss::Buss(ifstream & inn) : Rute(inn) {
inn >> antSitt >> antStaa >> leddbuss; inn.ignore();
}
/**
* skrivData
*/
void Buss::skrivData() const {
cout << "(buss): ";
Rute::skrivData();
}
/**
* skrivtilfil(...)
......
......@@ -21,6 +21,7 @@ class Buss : public Rute {
public:
Buss(std::ifstream & inn);
virtual void skrivData() const;
virtual void skrivTilFil(std::ofstream & ut);
};
......
......@@ -4,11 +4,16 @@
* @file rute.cpp
* @author Sondre Sand & Frederik Simonsen
*/
#include <iostream>
#include <list>
#include <fstream>
#include "rute.h"
#include "stoppested.h"
#include "stoppesteder.h"
using namespace std;
extern Stoppesteder gStoppestederBase;
// TODO: Fyll på her etter som header-fila tar mer form
/**
* Rute::Rute(...)
......@@ -35,6 +40,30 @@ Stopp::Stopp(const int stoppNr, const int antMin) {
nr = stoppNr; minutter = antMin;
}
/**
* skrivData()
*/
void Rute::skrivData() const {
int startIndeks,
stoppIndeks;
string startNavn,
stoppNavn;
startIndeks = stoppene.front()->hentNr(); // Henter startsteds unike nr
stoppIndeks = stoppene.back()->hentNr(); // Henter stopsteds unike nr
startNavn = gStoppestederBase.hentNavnVhaIndeks(startIndeks);
stoppNavn = gStoppestederBase.hentNavnVhaIndeks(stoppIndeks);
cout << startNavn << " - " << stoppNavn;
// MÅ finne en eller annen måte å få ut navn i stoppested vha hjelp
// av nummeret som er i structen
}
/**
* skrivTilFil(...)
*
* @param ut
*/
void Stopp::skrivTilFil(ofstream & ut) {
ut << nr << ' ' << minutter << '\n';
}
......@@ -46,3 +75,12 @@ void Rute::skrivTilFil(ofstream & ut) {
for (auto it = stoppene.begin(); it != stoppene.end(); it++)
(*it)->skrivTilFil(ut);
}
/**
* Henter en stopps unike nr
*
* @return Et stoppesteds unike nr
*/
int Stopp::hentNr() {
return nr;
}
\ No newline at end of file
......@@ -19,6 +19,7 @@ struct Stopp {
// Eller om den skal under public eller private i Rute
Stopp(const int stoppNr, const int antMin);
void skrivTilFil(std::ofstream & ut);
int hentNr();
};
/**
......@@ -30,6 +31,7 @@ class Rute {
public:
Rute(std::ifstream & inn);
virtual void skrivData() const;
virtual void skrivTilFil(std::ofstream & ut);
};
......
......@@ -62,7 +62,7 @@ void Ruter::lesFraFil() {
innfil >> key;
}
innfil.close();
cout << rutene.size();
} else
cout << "\nFant ikke filen 'ruter.dta'...\n";
......@@ -93,7 +93,13 @@ void Ruter::ruteTabell() {
* skrivAlle()
*/
void Ruter::skrivAlle() {
cout << "\nFølgende ruter finnes:\n";
for (const auto & [ruteNr, rute] : rutene) {
cout << ruteNr << ' ';
rute->skrivData();
cout << '\n';
}
cout << '\n';
}
/**
......
......@@ -6,6 +6,7 @@
*/
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "LesData3.h"
......@@ -157,3 +158,13 @@ void Stoppesteder::skrivTilFil() {
}
utfil.close();
}
/**
* hentNavnVhaIndeks(...)
*/
string Stoppesteder::hentNavnVhaIndeks(const int nr) {
string navn;
navn = stopper.at(nr-1)->hentStoppestedNavn();
return navn;
}
\ No newline at end of file
......@@ -27,6 +27,7 @@ class Stoppesteder {
void skrivMeny();
void skrivStopp();
void skrivTilFil();
std::string hentNavnVhaIndeks(const int nr);
};
#endif
\ 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