Finished all but task 5, is 80% percent, enough for approval

master
Øyvind Skaaden 2019-02-14 16:54:42 +01:00
parent 23251dbf64
commit bed4f31d23
7 changed files with 95 additions and 7 deletions

View File

@ -138,6 +138,7 @@
<ClCompile Include="Task1.cpp" />
<ClCompile Include="Task2.cpp" />
<ClCompile Include="Task3.cpp" />
<ClCompile Include="Task4.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="grunnlov.txt" />
@ -148,6 +149,7 @@
<ClInclude Include="Task1.h" />
<ClInclude Include="Task2.h" />
<ClInclude Include="Task3.h" />
<ClInclude Include="Task4.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -27,6 +27,9 @@
<ClCompile Include="Task3.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Task4.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="grunnlov_iso-latin-1.txt">
@ -49,5 +52,8 @@
<ClInclude Include="Task3.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Task4.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -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;
}

View File

@ -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:

40
Oving 6/Oving 6/Task4.cpp Normal file
View File

@ -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>& temps)
{
for (const auto t : temps)
{
os << t.max << '\t' << t.min << '\n';
}
return os;
}
void readTempsFromFile(vector<Temps>& 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);
}
}

12
Oving 6/Oving 6/Task4.h Normal file
View File

@ -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>& temps);
void readTempsFromFile(vector<Temps>& temps, string path);

View File

@ -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> temps;
string file = "temperatures.txt";
readTempsFromFile(temps, file);
cout << temps;
return 0;
}
}