Done Task 3 ish
parent
d24d0f7a1d
commit
23251dbf64
|
@ -136,6 +136,8 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="Task1.cpp" />
|
<ClCompile Include="Task1.cpp" />
|
||||||
|
<ClCompile Include="Task2.cpp" />
|
||||||
|
<ClCompile Include="Task3.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="grunnlov.txt" />
|
<Text Include="grunnlov.txt" />
|
||||||
|
@ -144,6 +146,8 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Task1.h" />
|
<ClInclude Include="Task1.h" />
|
||||||
|
<ClInclude Include="Task2.h" />
|
||||||
|
<ClInclude Include="Task3.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
|
|
@ -21,21 +21,33 @@
|
||||||
<ClCompile Include="Task1.cpp">
|
<ClCompile Include="Task1.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Task2.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Task3.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="grunnlov_iso-latin-1.txt">
|
<Text Include="grunnlov_iso-latin-1.txt">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Text>
|
|
||||||
<Text Include="temperatures.txt">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</Text>
|
</Text>
|
||||||
<Text Include="grunnlov.txt">
|
<Text Include="grunnlov.txt">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
|
</Text>
|
||||||
|
<Text Include="temperatures.txt">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
</Text>
|
</Text>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Task1.h">
|
<ClInclude Include="Task1.h">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Task2.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Task3.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -1,4 +1,5 @@
|
||||||
#include "Task1.h"
|
#include "Task1.h"
|
||||||
|
#include "std_lib_facilities.h"
|
||||||
|
|
||||||
void cinToFile(string path)
|
void cinToFile(string path)
|
||||||
{
|
{
|
||||||
|
@ -22,27 +23,28 @@ void cinToFile(string path)
|
||||||
void addLineNumber(string inputPath, string outputPath)
|
void addLineNumber(string inputPath, string outputPath)
|
||||||
{
|
{
|
||||||
string line;
|
string line;
|
||||||
ifstream ifs{ inputPath };
|
ifstream ifs{ inputPath }; // Try opening file
|
||||||
if (!ifs)
|
if (!ifs)
|
||||||
error("Cant open file ", inputPath);
|
error("Cant open file ", inputPath);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vector<string> lines;
|
vector<string> lines; //Create vector of lines
|
||||||
while (ifs.eof())
|
while (!ifs.eof()) // Read all the lines
|
||||||
{
|
{
|
||||||
|
line.clear();
|
||||||
getline(ifs, line);
|
getline(ifs, line);
|
||||||
cout << line << endl;
|
cout << line << endl;
|
||||||
lines.push_back(line);
|
lines.push_back(line);
|
||||||
}
|
}
|
||||||
ifs.close();
|
ifs.close();
|
||||||
ofstream ofs{ outputPath };
|
ofstream ofs{ outputPath }; // Prepeare to output to file
|
||||||
if (!ifs || !ofs)
|
if (!ofs)
|
||||||
error("Cant open file ", outputPath);
|
error("Cant open file ", outputPath);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = 0; i < lines.size(); ++i)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<int> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
#pragma once
|
||||||
|
#include "std_lib_facilities.h"
|
||||||
|
|
||||||
|
void countCharInTxt(string path);
|
|
@ -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
|
||||||
|
}
|
|
@ -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<string, string> courses;
|
||||||
|
};
|
|
@ -23,4 +23,4 @@ v
|
||||||
w
|
w
|
||||||
x
|
x
|
||||||
y
|
y
|
||||||
z
|
z
|
|
@ -1,11 +1,16 @@
|
||||||
#include "std_lib_facilities.h"
|
#include "std_lib_facilities.h"
|
||||||
#include "Task1.h"
|
#include "Task1.h"
|
||||||
|
#include "Task2.h"
|
||||||
|
#include "Task3.h"
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
// Your code here
|
// Your code here
|
||||||
//cinToFile("inn.txt");
|
//cinToFile("inn.txt");
|
||||||
|
|
||||||
addLineNumber("inn.txt", "out.txt");
|
//addLineNumber("inn.txt", "out.txt");
|
||||||
|
|
||||||
|
countCharInTxt("grunnlov.txt");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -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
|
Loading…
Reference in New Issue