-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyImpDictionary.cpp
156 lines (131 loc) · 3.49 KB
/
MyImpDictionary.cpp
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
#include "MyImpDictionary.h"
/*******************************************************************************
class myDictionary
{
public:
myDictionary(void);
~myDictionary(void);
myDictionary(int wordCount);
std::vector<std::string> myGreatBook;
bool searchAgain;
//GETTERS
void getWord(std::string wordsearch, int counterPos); //WILL SEARCH FOR A WORD IN THE VECTOR ARRAY OF WORDS
std::vector<std::string> getDictionary();
//PUBLIC INTS
int numOfWordsCounter;
//SETTERS
void setDictionary(std::string filePath); //THIS WILL CREATE OUR VIRTUAL DICTIONARY
};
********************************************************************************/
/*****************************
NAME: myDiciontary
FUNCTION: CREATES AN EMPTY DICTIONARY
TYPE: CONSTRUCTOR
ARGUEMENTS: NONE
RETURNS: NONE
******************************/
myDictionary::myDictionary()
:numOfWordsCounter(0),
myGreatBook(0),
searchAgain(true)
{}
/*****************************
NAME: myDiciontary
FUNCTION: CREATES AN EMPTY DICTIONARY, SETS WORDCOUNT TO SPECIFIC POSITION
TYPE: CONSTRUCTOR
ARGUEMENTS: NONE
RETURNS: NONE
******************************/
myDictionary::myDictionary(int wordcount)
:numOfWordsCounter(wordcount),
myGreatBook(0),
searchAgain(true)
{}
myDictionary::~myDictionary()
{}
void myDictionary::setDictionary(std::string filePath)
{
std::string words;
std::fstream myFile;
myFile.open(filePath);
if (!myFile.is_open())
{
std::cout << "ERROR: Could not open or find file." << std::endl;
system("pause");
exit(0);
}
std::cout << "Looking Good. File found\n\n" << std::endl;
while (!myFile.eof())
{
myFile >> words;
myGreatBook.push_back(words);
if (numOfWordsCounter % 15 == 0)
{
std::cout << std::endl << std::endl;
}
std::cout << " " << myGreatBook[numOfWordsCounter];
numOfWordsCounter++;
}
std::cout << "There is a total of " << numOfWordsCounter << " in your dictionary." << std::endl;
myFile.close();
}
std::vector<std::string> myDictionary::getDictionary()
{
return myGreatBook;
}
void myDictionary::getWord(std::string wordsearch, int counterPos)
{
std::vector<std::string> temp_Dictionary = getDictionary();
int word_counter{ 0 }, letter_counter{ 0 }, match_counter{ 0 };
bool isMatch = false;
std::size_t temp_Word;
for (std::string hold_Temp_Word : temp_Dictionary)
{
isMatch = false;
letter_counter = 0;
for (char character_of_target_word : wordsearch)
{
if (character_of_target_word == hold_Temp_Word.at(letter_counter))
{
isMatch = true;
}
else
{
isMatch = false;
break;
}
letter_counter++;
}
if (isMatch)
{
if (match_counter % 10 == 0)
{
std::cout << std::endl;
}
std::cout << match_counter+1 << ": " << hold_Temp_Word << " ";
match_counter++;
}
word_counter++;
}
std::cout << std::endl << "There was a total of " << match_counter << " matches. " << std::endl;
std::cout << std::endl << std::endl;
}
int main()
{
std::string myWord;
myDictionary d(0);
d.setDictionary("C:/Users/Rex_Kidd/Desktop/myManyWordsFile.txt");
while (d.searchAgain) {
std::cout << "What letter does your word start with? " << std::endl;
std::cin >> myWord;
d.getWord(myWord, 5);
std::cout << "\nWant to search another word? Enter N for no: ";
std::cin >> myWord;
if (myWord.at(0) == 'n')
{
d.searchAgain = false;
}
}
system("pause");
return 0;
}