forked from albertcampana/CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4936007
commit 852f4df
Showing
24 changed files
with
142 additions
and
24 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
In this question we are asked to create a program that prints a sorted list of all the different words appearing in the input. | ||
In this question, we are asked to create a program that prints a sorted list of all the different words appearing in the input. | ||
|
||
We used a set to solve this exercise. It automatically sorts the words, but it does not differentiate between the new ones or the ones that already appeared. | ||
To solve that issue we put all the words inside a map and print the map. | ||
We used a set to solve this exercise as it implements a sorted collection of unique values, so when we add a word if it is already in the set it is not inserted and if it wasn't there it is inserted in the right place. So when we print it we can see the words in order. | ||
|
||
Using the input: a a a b c abc acb acb ab ac | ||
We get the output on file out1.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ explain.txt | |
|
||
main.ih | ||
main.cc | ||
text.hh | ||
text.cc | ||
|
||
out1.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// OUT 1 // | ||
|
||
a | ||
ab | ||
abc | ||
ac | ||
acb | ||
b | ||
c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
In this exercise we are required to print the word and how many times has this word appeared in the input. | ||
|
||
To solve this exercise we decide to use a map, with the key as a string and the value as an int. We increment this int for every word that appears in the input. | ||
To solve this exercise we decide to use a map as it stores unique key in an ordered way. So using each string as the key and the value is an int representing how many times it has appeared. We increment this int for every word that appears in the input. | ||
|
||
The code is so simple because in a map every new key is auto-initialized to a default value. In our int case, it is initialized to 0. | ||
|
||
Using the input: a a a b c abc acb acb ab ac | ||
We get the output on file out1.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
explain.txt | ||
|
||
main.cc | ||
main.ih | ||
|
||
out1.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// OUT 1 // | ||
|
||
a 3 | ||
ab 1 | ||
abc 1 | ||
ac 1 | ||
acb 2 | ||
b 1 | ||
c 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
#include "vectorString/vectorString.hh" | ||
#include <iostream> | ||
#include <set> | ||
#include <fstream> | ||
#include <vector> | ||
|
||
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// OUT 2 // | ||
|
||
Size: 11 | ||
Capacity: 20 | ||
Size: 11 | ||
Capacity: 11 | ||
Size: 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#include "vectorString.hh" | ||
#include <iostream> | ||
#include <vector> | ||
#include <set> | ||
#include <fstream> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Because NoEntry does not meet the CopyInsertable requirements of push_back. | ||
|
||
One way of working around this limitation is not storing NoEntry objects in the vector, but pointers or std::unique_ptr<NoEntry> items. The latter requires only MoveConstructible and MoveAssignable, but not CopyInsertable. | ||
|
||
If all constructors of your class are private, then only member functions of your class (including static members) or friends of the class can create instances of it. To push or move instances of that class into a std::vector, then that vector class will need to be declared as a friend. std::push_back(), among other things, uses a constructor of your class to add an element, but may call other functions to do that job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "privilegedOne.ih" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef INCLUDED_NOENTRY_ | ||
#define INCLUDED_NOENTRY_ | ||
|
||
#include <string> | ||
|
||
class NoEntry | ||
{ | ||
friend class PrivilegedOne; | ||
friend class PrivilegedTwo; | ||
|
||
std::string d_name; | ||
size_t d_area = 0; | ||
size_t d_date = 0; | ||
|
||
public: | ||
std::string const &name() const; | ||
size_t area() const; | ||
size_t date() const; | ||
|
||
private: | ||
NoEntry(NoEntry const &other) = default; | ||
NoEntry() = default; | ||
NoEntry(std::string const &name, size_t area, size_t date); | ||
}; | ||
|
||
#endif |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//#define XERR | ||
#include "privilegedOne.ih" | ||
|
||
PrivilegedOne::PrivilegedOne(string const &fname) | ||
{ | ||
ifstream in{ fname }; | ||
|
||
while (true) | ||
{ | ||
NoEntry next = nextEntry(in); | ||
|
||
if (next.name().empty()) | ||
break; | ||
|
||
d_noEntry.push_back(&next); // oops... | ||
} | ||
} | ||
|
||
NoEntry PrivilegedOne::nextEntry(istream &in) | ||
{ | ||
NoEntry ret; | ||
|
||
in >> ret.d_name >> ret.d_area >> ret.d_date; | ||
|
||
if (not in) // no more NoEntries: ensure | ||
ret.d_name.clear(); // that d_name is empty | ||
|
||
return ret; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef INCLUDED_PRIVILEGEDONE_ | ||
#define INCLUDED_PRIVILEGEDONE_ | ||
|
||
#include <iosfwd> | ||
#include <vector> | ||
|
||
#include "noEntry.hh" | ||
|
||
class PrivilegedOne | ||
{ | ||
std::vector<NoEntry *> d_noEntry; | ||
|
||
public: | ||
PrivilegedOne(std::string const &fname); | ||
|
||
private: | ||
NoEntry nextEntry(std::istream &in); // empty name: all were read | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <fstream> | ||
#include "noEntry.hh" | ||
#include "privilegedOne.hh" | ||
|
||
using namespace std; |
Binary file not shown.