-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
256 lines (211 loc) · 7.41 KB
/
Copy pathmain.cpp
File metadata and controls
256 lines (211 loc) · 7.41 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
* File: main.cpp
* Author: kim
*
* Created on November 15, 2014, 7:49 PM
*/
#include <cstdlib>
#include "HashClass.h"
#include "Reader.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void addData(HashClass hc);
void removeData(HashClass hc);
void findAndDisplayData(HashClass hc);
void listHashTableSequence(HashClass hc);
void listSortedData(HashClass hc);
void printIndentedTree(HashClass hc);
void printEfficiency(HashClass hc);
void spellCheck(HashClass hc, HashClass hc2);
void writeToFile(HashClass hc);
int main() {
// Load dictionary file into hash table
HashClass hashDictionary;
hashDictionary.loadFile("dict.txt");
hashDictionary.loadToHash();
// Load input file into hash table
HashClass hashInput;
hashInput.loadFile("inputErrors.txt");
hashInput.loadToHash();
enum MenuChoice {
MENU_ADD_NEW_DATA = 1,
MENU_REMOVE_DATA = 2,
MENU_FIND_AND_DISPLAY_DATA = 3,
MENU_LIST_IN_HASH_TABLE_SEQUENCE = 4,
MENU_LIST_SORTED_DATA = 5,
MENU_PRINT_INDENTED_TREE = 6,
MENU_PRINT_EFFICIENCY = 7,
MENU_SPELLCHECK = 8,
MENU_WRITE_TO_FILE = 9,
MENU_EXIT = 10
};
const string strOperationSuccess = "\nFinished task, Repeating menu:\n";
const string strMenuDisplay = "What operation would you like to perform?: \n\n"
"1. Add new data to input file\n"
"2. Remove data from input file\n"
"3. Find and display one data from the input file using the primary key\n"
"4. List data in the dictionary hash table\n"
"5. List data in the input file in key sequence (sorted)\n"
"6. Print data in the input file as an indented binary tree\n"
"7. Print efficiency of the dictionary hash table\n"
"8. Spell check input file\n"
"9. Write the dictionary file back to a file in hash table sequence\n"
"10. Exit\n";
int menuOption;
cout << strMenuDisplay << endl;
do {
cin >> menuOption; // get menu choice
cout << endl;
// check for valid menu choice then call it
switch (menuOption) {
case MENU_ADD_NEW_DATA:
cin.clear();
cin.ignore();
addData(hashInput);
cout << strOperationSuccess << endl;
cout << "\n\n\n\n\n";
cout << strMenuDisplay << endl;
break;
case MENU_REMOVE_DATA:
cin.clear();
cin.ignore();
removeData(hashInput);
cout << strOperationSuccess << endl;
cout << "\n\n\n\n\n";
cout << strMenuDisplay << endl;
break;
case MENU_FIND_AND_DISPLAY_DATA:
cin.clear();
cin.ignore();
findAndDisplayData(hashInput);
cout << strOperationSuccess << endl;
cout << "\n\n\n\n\n";
cout << strMenuDisplay << endl;
break;
case MENU_LIST_IN_HASH_TABLE_SEQUENCE:
cin.clear();
cin.ignore();
listHashTableSequence(hashDictionary);
cout << strOperationSuccess << endl;
cout << "\n\n\n\n\n";
cout << strMenuDisplay << endl;
break;
case MENU_LIST_SORTED_DATA:
cin.clear();
cin.ignore();
listSortedData(hashInput);
cout << strOperationSuccess << endl;
cout << "\n\n\n\n\n";
cout << strMenuDisplay << endl;
break;
case MENU_PRINT_INDENTED_TREE:
cin.clear();
cin.ignore();
printIndentedTree(hashInput);
cout << strOperationSuccess << endl;
cout << "\n\n\n\n\n";
cout << strMenuDisplay << endl;
break;
case MENU_PRINT_EFFICIENCY:
cin.clear();
cin.ignore();
printEfficiency(hashDictionary);
cout << strOperationSuccess << endl;
cout << "\n\n\n\n\n";
cout << strMenuDisplay << endl;
break;
case MENU_SPELLCHECK:
cin.clear();
cin.ignore();
spellCheck(hashDictionary, hashInput);
cout << strOperationSuccess << endl;
cout << "\n\n\n\n\n";
cout << strMenuDisplay << endl;
break;
case MENU_WRITE_TO_FILE:
cin.clear();
cin.ignore();
writeToFile(hashDictionary);
cout << strOperationSuccess << endl;
cout << "\n\n\n\n\n";
cout << strMenuDisplay << endl;
break;
case MENU_EXIT:
cin.clear();
cin.ignore();
cout << "You have exited the program." << endl;
exit(0);
break;
default:
cin.clear();
cin.ignore();
cout << menuOption << " is not a valid menu choice. Enter again.\n" << endl;
cout << strMenuDisplay << endl;
break;
}
} while (true);
return 0;
}
// Functions
void addData(HashClass hc) {
cout << "Enter the word you would like to add to the input file:" << endl;
string inputWord;
getline(cin, inputWord);
cout << endl;
cout << endl;
hc.addToHash(inputWord);
cout << "You have added the word " << inputWord << " to the input file." << endl;
};
void removeData(HashClass hc) {
cout << "Enter the word you would like to remove from the input file:" << endl;
string inputWord;
getline(cin, inputWord);
hc.removeItem(inputWord);
};
void findAndDisplayData(HashClass hc) {
cout << "Enter the word you would like to display: " << endl;
string inputWord;
getline(cin, inputWord);
hc.printWord(inputWord);
};
void listHashTableSequence(HashClass hc) {
int choice;
int bucketNumber;
hc.printTable();
do {
cout << "Enter the bucket you would like to display: " << endl;
cin >> bucketNumber;
hc.printItemsInIndex(bucketNumber);
cout << "Would you like to continue? Enter 1 for yes and 0 for no:" << endl;
cin >> choice;
} while (choice);
};
void listSortedData(HashClass hc) {
// hc.createHashTableVector();
hc.createWordVector();
hc.createBST();
};
void printIndentedTree(HashClass hc) {
// hc.createHashTableVector();
hc.createWordVector();
hc.createIndentedBST();
};
void printEfficiency(HashClass hc) {
hc.printLoadFactor();
hc.avgNodesInLists();
hc.printLongestLinkedList();
};
void spellCheck(HashClass dictionary, HashClass input) {
input.createWordVector(); // Create a vector of all the words in the
// input file from the hash table
// so it includes new data added
// Demonstrate spell checking
// Check the input vector of words against the dictionary hash table
dictionary.spellCheck(input.getWords());
};
void writeToFile(HashClass hc) {
hc.writeToFile();
cout << "Contents of the dictionary hash table has been written to an output file." << endl;
};