-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWord.cpp
More file actions
173 lines (138 loc) · 3.97 KB
/
Word.cpp
File metadata and controls
173 lines (138 loc) · 3.97 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
#include <vector>
#include "Word.h"
using namespace std;
Word::Word() {
//cout << "Entering Word::Word() Constructor" << endl;
next = NULL;
//cout << " Exiting Word::Word() Constructor" << endl;
}
Word::Word(const string& aString){
//cout << "Entering Word::Word(string arg) Value Constructor" << endl;
//cout << "Passed Value Constructor:" << aString << endl;
dummyString = aString;
next = NULL;
//cout << " Exiting Word::Word(string arg) Value Constructor" << endl;
}
Word::~Word() {
//cout << "Entering Word::~Word() Deconstructor" << endl;
//cout << " Exiting Word::~Word() Deconstructor" << endl;
}
Word::Word(const Word& aWord) {
//cout << "Entering Word::Word(Word arg) Copy Constructor" << endl;
dummyString = aWord.dummyString;
next = NULL;
//cout << " Exiting Word::Word(Word arg) Copy Constructor" << endl;
}
void Word::show() {
//cout << "Entering Word::show" << endl;
cout << dummyString << endl;
//cout << " Exiting Word::show" << endl;
}
//If a is a Word
//make it all caps
Word Word::operator++(int) {
//cout << "Entering Word::operator++, postfix" << endl;
Word w(*this);
for(int i =0; i < this->dummyString.length(); i++){
w.dummyString[i] = toupper(w.dummyString[i]);
}
//cout << " Exiting Word::operator++, postfix" << endl;
return w;
}
//If a is a Word
//makes it all lowercase.
Word Word::operator--(int) {
//cout << "Entering Word::operator--, postfix" << endl;
Word w(*this);
for(int i =0; i < this->dummyString.length(); i++){
w.dummyString[i] = tolower(w.dummyString[i]);
}
//cout << " Exiting Word::operator--, postfix" << endl;
return w;
}
//If a is a Word
//capitalizes the first letter.
Word& Word::operator+(const int& i) {
//cout << "Entering Word::operator+" << endl;
if (i != 1) return *this;
this->dummyString[0] = toupper(this->dummyString[0]);
//cout << " Exiting Word::operator+" << endl;
return *this;
}
//If a is a Word
//converts it to Pig Latin.
Word& Word::operator++() {
//cout << "Entering Word::operator++, prefix" << endl;
char array[] = {'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'};
v.push_back(this->dummyString);
string temp;
string newWord;
int counter = 0;
int index = 0;
int len = this->dummyString.length();
for(int i =0; i < 10; i++){
if(this->dummyString[0] == array[i]){
this->dummyString += "way";
return *this;
}
}
//Like
for(int j = 0; j < len; j++){
if(this->dummyString[j] == 'a') break;
if(this->dummyString[j] == 'e') break;
if(this->dummyString[j] == 'i') break;
if(this->dummyString[j] == 'o') break;
if(this->dummyString[j] == 'u') break;
if(this->dummyString[j] != 'a')
{
if(this->dummyString[j] != 'e')
{
if(this->dummyString[j] != 'i')
{
if(this->dummyString[j] != 'o')
{
if(this->dummyString[j] != 'i')
{
counter++;
}
}
}
}
}
}
temp = this->dummyString.substr(counter, len);
newWord = this->dummyString.substr(0,counter);
newWord = (temp + newWord + "ay");
if(isupper(this->dummyString[0])){
for(int i=0; i < len; i++)
{
newWord[i] = tolower(newWord[i]);
}
newWord[0] = toupper(newWord[0]);
}
this->dummyString = newWord;
//cout << " Exiting Word::operator++, prefix" << endl;
return *this;
}
//If a is a Word in Pig Latin
//converts it from Pig Latin to plain English.
Word& Word::operator--() {
//cout << "Entering Word::operator--, prefix" << endl;
this->dummyString = v.at(0);
//cout << " Exiting Word::operator--, prefix" << endl;
return *this;
}
//A Word class should output only the words characters, in order.
ostream& operator<<(ostream& out, const Word& b) {
//cout << "Entering Word operator<<" << endl;
out << b.dummyString;
//cout << " Exiting Word operator<<" << endl;
return out;
}
Word& Word::operator=(const Word& aWord) {
//cout << "Entering Word::operator=(Word arg)" << endl;
this->dummyString = aWord.dummyString;
return *this;
//cout << " Exiting Word::operator=(Word arg)" << endl;
}