From bed4f31d235414e8c0f74d15fca8ad7f7072be8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Skaaden?= Date: Thu, 14 Feb 2019 16:54:42 +0100 Subject: [PATCH] Finished all but task 5, is 80% percent, enough for approval --- Oving 6/Oving 6/Oving 6.vcxproj | 2 ++ Oving 6/Oving 6/Oving 6.vcxproj.filters | 6 ++++ Oving 6/Oving 6/Task3.cpp | 14 ++++++--- Oving 6/Oving 6/Task3.h | 2 +- Oving 6/Oving 6/Task4.cpp | 40 +++++++++++++++++++++++++ Oving 6/Oving 6/Task4.h | 12 ++++++++ Oving 6/Oving 6/main.cpp | 26 ++++++++++++++-- 7 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 Oving 6/Oving 6/Task4.cpp create mode 100644 Oving 6/Oving 6/Task4.h diff --git a/Oving 6/Oving 6/Oving 6.vcxproj b/Oving 6/Oving 6/Oving 6.vcxproj index 7acdd3b..701d330 100644 --- a/Oving 6/Oving 6/Oving 6.vcxproj +++ b/Oving 6/Oving 6/Oving 6.vcxproj @@ -138,6 +138,7 @@ + @@ -148,6 +149,7 @@ + diff --git a/Oving 6/Oving 6/Oving 6.vcxproj.filters b/Oving 6/Oving 6/Oving 6.vcxproj.filters index 74dbf84..c86edd9 100644 --- a/Oving 6/Oving 6/Oving 6.vcxproj.filters +++ b/Oving 6/Oving 6/Oving 6.vcxproj.filters @@ -27,6 +27,9 @@ Source Files + + Source Files + @@ -49,5 +52,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Oving 6/Oving 6/Task3.cpp b/Oving 6/Oving 6/Task3.cpp index b3f876d..c0dcadf 100644 --- a/Oving 6/Oving 6/Task3.cpp +++ b/Oving 6/Oving 6/Task3.cpp @@ -6,7 +6,7 @@ CourseCatalog::CourseCatalog() void CourseCatalog::addCourse(string code, string name) { - courses.insert(code, name); + courses[code] = name; } void CourseCatalog::removeCourse(string code) @@ -19,7 +19,13 @@ string CourseCatalog::getCourse(string code) return courses[code]; } -ostream & operator<<(ostream &, const CourseCatalog &) -{ - // TODO: insert return statement here + +ostream& operator<<(ostream & os, const CourseCatalog & cc) +{ + string courses; + for (const auto c : cc.courses) + { + courses += c.first + '\t' + c.second + '\n'; + } + return os << courses; } diff --git a/Oving 6/Oving 6/Task3.h b/Oving 6/Oving 6/Task3.h index 822f4e4..dc6865e 100644 --- a/Oving 6/Oving 6/Task3.h +++ b/Oving 6/Oving 6/Task3.h @@ -6,7 +6,7 @@ class CourseCatalog public: CourseCatalog(); friend ostream& operator<<(ostream&, const CourseCatalog&); - void addCourse(string code, string name); + void addCourse(const string code, string name); void removeCourse(string code); string getCourse(string code); private: diff --git a/Oving 6/Oving 6/Task4.cpp b/Oving 6/Oving 6/Task4.cpp new file mode 100644 index 0000000..7e1532f --- /dev/null +++ b/Oving 6/Oving 6/Task4.cpp @@ -0,0 +1,40 @@ +#include "Task4.h" + +istream & operator>>(istream & is, Temps & t) +{ + double inMax, inMin; + is >> inMax >> inMin; + if (!is) return is; + + t = Temps{ inMax, inMin }; + return is; + // TODO: insert return statement here +} + +ostream & operator<<(ostream & os, vector& temps) +{ + for (const auto t : temps) + { + os << t.max << '\t' << t.min << '\n'; + } + return os; +} + +void readTempsFromFile(vector& temps, string path) +{ + ifstream ifs{ path }; + if (!ifs) + { + error("Cant open file ", path); + return; + } + Temps t; + string line; + while (getline(ifs, line)) + { + cout << line; + istringstream iss{ line }; + iss >> t; + temps.push_back(t); + } +} diff --git a/Oving 6/Oving 6/Task4.h b/Oving 6/Oving 6/Task4.h new file mode 100644 index 0000000..c5600c6 --- /dev/null +++ b/Oving 6/Oving 6/Task4.h @@ -0,0 +1,12 @@ +#pragma once +#include "std_lib_facilities.h" + +struct Temps { + double max, min; +}; + +istream& operator>>(istream& is, Temps& t); + +ostream& operator<<(ostream& os, vector& temps); + +void readTempsFromFile(vector& temps, string path); \ No newline at end of file diff --git a/Oving 6/Oving 6/main.cpp b/Oving 6/Oving 6/main.cpp index b8036b3..0d0e3b3 100644 --- a/Oving 6/Oving 6/main.cpp +++ b/Oving 6/Oving 6/main.cpp @@ -2,6 +2,7 @@ #include "Task1.h" #include "Task2.h" #include "Task3.h" +#include "Task4.h" int main(){ @@ -10,7 +11,28 @@ int main(){ //addLineNumber("inn.txt", "out.txt"); - countCharInTxt("grunnlov.txt"); + //countCharInTxt("grunnlov.txt"); + + + CourseCatalog courses = CourseCatalog(); + + courses.addCourse("TDT4100", "Informasjonsteknologi grunnkurs"); + courses.addCourse("TDT4102", "Prosedyre- og objektorientert programmering"); + courses.addCourse("TMA4100", "Matematikk 1"); + courses.addCourse("TDT4102", "C++"); + + // map.insert funker ikke + + + cout << courses; + + vector temps; + string file = "temperatures.txt"; + + readTempsFromFile(temps, file); + + cout << temps; + return 0; -} \ No newline at end of file +}