-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntry.cpp
More file actions
111 lines (95 loc) · 2.44 KB
/
Copy pathEntry.cpp
File metadata and controls
111 lines (95 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// Created by Sammy Timmins on 9/23/20.
//
#include "Entry.h"
Entry::Entry(const DSString &word)
{
this->word = word;
}
Entry::Entry(const Entry ©)
{
this->word = copy.word;
this->pages = copy.pages;
this->children = copy.children;
}
Entry& Entry::operator=(const Entry ©)
{
this->word = copy.word;
this->pages = copy.pages;
this->children = copy.children;
}
Entry& Entry::operator=(const DSString &string) //assigns the string to the entry's word
{
int size = string.getLength();
int charsToExclude = 0;
for(int i = size - 1; i >= 0; i--) //removes trailing punctuation from the string being added
{
if(!isalpha(string[i]))
{
++charsToExclude;
} else{
break;
}
}
word = string.substr(0, size - charsToExclude);
}
bool Entry::operator<(const Entry &toCompare) const //compares the words of the entry
{
return word < toCompare.word;
}
bool Entry::operator==(const Entry &compare) //comapres the words of the entry
{
return this->word == compare.word;
}
ostream& operator<<(ostream& os, const Entry& entry) //outputs and formats the output.txt
{
int outputLength = entry.word.getLength(); //used to control wrapping at 50 chars
os << entry.word << ": ";
set<int>::iterator itr;
for(itr = entry.pages.begin(); itr != entry.pages.end(); ++itr)
{
if(next(itr) != entry.pages.end())
{
os << *itr << ", ";
outputLength += to_string(*itr).length() + 1;
if((outputLength += to_string(*next(itr)).length()) >= 50) //if the ouput for the line has reached 50 chars
{
os << endl << " ";
outputLength = 0;
}
} else
{
os << *itr; //outputs the final page number without a comma
}
}
for(int i = 0; i < entry.children.getSize(); i++) //recursively calls outstream function for the children
{
os << endl;
os << " " << entry.children.at(i);
}
return os;
}
DSString Entry::getEntry()
{
return word;
}
set<int> Entry::getPages()
{
return pages;
}
void Entry::addPage(const int &toAdd)
{
pages.insert(toAdd);
}
DSVector<Entry> Entry::getChildren()
{
return children;
}
void Entry::addChild(const Entry &toAdd)
{
children.push_back(toAdd);
}
char Entry::getWordAt(const int i) const //accesses the entry at a certain character
{
return word[i];
}