diff --git a/Oving 6/Oving 6/Oving 6.vcxproj b/Oving 6/Oving 6/Oving 6.vcxproj index 0a08603..7acdd3b 100644 --- a/Oving 6/Oving 6/Oving 6.vcxproj +++ b/Oving 6/Oving 6/Oving 6.vcxproj @@ -136,6 +136,8 @@ + + @@ -144,6 +146,8 @@ + + diff --git a/Oving 6/Oving 6/Oving 6.vcxproj.filters b/Oving 6/Oving 6/Oving 6.vcxproj.filters index 42cc99f..74dbf84 100644 --- a/Oving 6/Oving 6/Oving 6.vcxproj.filters +++ b/Oving 6/Oving 6/Oving 6.vcxproj.filters @@ -21,21 +21,33 @@ Source Files + + Source Files + + + Source Files + - Source Files - - - Source Files + Resource Files - Source Files + Resource Files + + + Resource Files - Source Files + Header Files + + + Header Files + + + Header Files \ No newline at end of file diff --git a/Oving 6/Oving 6/Task1.cpp b/Oving 6/Oving 6/Task1.cpp index 5df21d8..c06fbf0 100644 --- a/Oving 6/Oving 6/Task1.cpp +++ b/Oving 6/Oving 6/Task1.cpp @@ -1,4 +1,5 @@ #include "Task1.h" +#include "std_lib_facilities.h" void cinToFile(string path) { @@ -22,27 +23,28 @@ void cinToFile(string path) void addLineNumber(string inputPath, string outputPath) { string line; - ifstream ifs{ inputPath }; + ifstream ifs{ inputPath }; // Try opening file if (!ifs) error("Cant open file ", inputPath); else { - vector lines; - while (ifs.eof()) + vector lines; //Create vector of lines + while (!ifs.eof()) // Read all the lines { + line.clear(); getline(ifs, line); cout << line << endl; lines.push_back(line); } ifs.close(); - ofstream ofs{ outputPath }; - if (!ifs || !ofs) + ofstream ofs{ outputPath }; // Prepeare to output to file + if (!ofs) error("Cant open file ", outputPath); else { for (int i = 0; i < lines.size(); ++i) { - ofs << setw(lines.size()) << i + 1 << " " << lines[i] << endl; + ofs << setw(to_string(lines.size()).size()) << i + 1 << " " << lines[i] << endl; // Write all lines with linenumer with a specific width } } diff --git a/Oving 6/Oving 6/Task2.cpp b/Oving 6/Oving 6/Task2.cpp new file mode 100644 index 0000000..dd04e6b --- /dev/null +++ b/Oving 6/Oving 6/Task2.cpp @@ -0,0 +1,37 @@ +#include "Task2.h" +#include "std_lib_facilities.h" + +void countCharInTxt(string path) +{ + ifstream ifs{ path }; + if (!ifs) + { + error("Cant open file ", path); + return; + } + string text, line; + while (!ifs.eof()) // Read all the lines + { + line.clear(); + getline(ifs, line); + text += line; + } + + vector chars(26); + + for (const auto c : text) + { + if ((c <= 255 && c > -1) && isalpha(c)) + chars[tolower(c) - 'a'] += 1; + } + + for (int i = 0; i < chars.size(); i += 3) + { + for (int j = i; j < i + 3 && j < chars.size(); ++j) + { + cout << (char)((j)+(int)'a') << ":\t" << chars[j] << "\t\t"; + } + cout << endl; + } + +} diff --git a/Oving 6/Oving 6/Task2.h b/Oving 6/Oving 6/Task2.h new file mode 100644 index 0000000..813671c --- /dev/null +++ b/Oving 6/Oving 6/Task2.h @@ -0,0 +1,4 @@ +#pragma once +#include "std_lib_facilities.h" + +void countCharInTxt(string path); diff --git a/Oving 6/Oving 6/Task3.cpp b/Oving 6/Oving 6/Task3.cpp new file mode 100644 index 0000000..b3f876d --- /dev/null +++ b/Oving 6/Oving 6/Task3.cpp @@ -0,0 +1,25 @@ +#include "Task3.h" + +CourseCatalog::CourseCatalog() +{ +} + +void CourseCatalog::addCourse(string code, string name) +{ + courses.insert(code, name); +} + +void CourseCatalog::removeCourse(string code) +{ + courses.erase(code); +} + +string CourseCatalog::getCourse(string code) +{ + return courses[code]; +} + +ostream & operator<<(ostream &, const CourseCatalog &) +{ + // TODO: insert return statement here +} diff --git a/Oving 6/Oving 6/Task3.h b/Oving 6/Oving 6/Task3.h new file mode 100644 index 0000000..822f4e4 --- /dev/null +++ b/Oving 6/Oving 6/Task3.h @@ -0,0 +1,14 @@ +#pragma once +#include "std_lib_facilities.h" + +class CourseCatalog +{ +public: + CourseCatalog(); + friend ostream& operator<<(ostream&, const CourseCatalog&); + void addCourse(string code, string name); + void removeCourse(string code); + string getCourse(string code); +private: + map courses; +}; diff --git a/Oving 6/Oving 6/inn.txt b/Oving 6/Oving 6/inn.txt index 0edb856..fcd217f 100644 --- a/Oving 6/Oving 6/inn.txt +++ b/Oving 6/Oving 6/inn.txt @@ -23,4 +23,4 @@ v w x y -z +z \ No newline at end of file diff --git a/Oving 6/Oving 6/main.cpp b/Oving 6/Oving 6/main.cpp index f9d2390..b8036b3 100644 --- a/Oving 6/Oving 6/main.cpp +++ b/Oving 6/Oving 6/main.cpp @@ -1,11 +1,16 @@ #include "std_lib_facilities.h" #include "Task1.h" +#include "Task2.h" +#include "Task3.h" int main(){ // Your code here //cinToFile("inn.txt"); - addLineNumber("inn.txt", "out.txt"); + //addLineNumber("inn.txt", "out.txt"); + + countCharInTxt("grunnlov.txt"); + return 0; } \ No newline at end of file diff --git a/Oving 6/Oving 6/out.txt b/Oving 6/Oving 6/out.txt index e69de29..591f0d0 100644 --- a/Oving 6/Oving 6/out.txt +++ b/Oving 6/Oving 6/out.txt @@ -0,0 +1,26 @@ + 1 a + 2 b + 3 c + 4 d + 5 e + 6 f + 7 g + 8 h + 9 i +10 j +11 k +12 l +13 m +14 n +15 o +16 p +17 q +18 r +19 s +20 t +21 u +22 v +23 w +24 x +25 y +26 z