-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlunt_kase_assn4.cpp
79 lines (56 loc) · 2.24 KB
/
lunt_kase_assn4.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
/*
Author: Kase Lunt
Date: 7/7/21
Description: This is the main file for a word frequency analyzer. It creates a wordfrequencyAnalyzer object which parses the text file
and splits input into words, and saves those into a BST. The BST can then be searched, as well as saved to a file, sorted by frequency.
*/
#include "templatedBST.h"
#include "wf_analyzer.h"
int main(int argc, char** argv)
{
// create a new analyzer instance, calling default constructor
WordFreqAnalyzer analyzer;
// wordP will point to a vector of WordEntry pointers
std::vector< WordEntry* >* wordP;
// call analyzer's toFreqArray to create a vector of words sorted by frequency (wordCount)
wordP = analyzer.toFreqArray( analyzer.tree->getRoot(), analyzer.freqArray );
// summarize the analysis and display to console
std::cout << "Total words: " << analyzer.totalWords() << std::endl;
std::cout << "Total unique words: " << analyzer.uniqueWords() << std::endl;
analyzer.displayLeastFreq(5);
analyzer.displayMostFreq(5);
// menu
bool continueMenu = true;
std::string tempString;
BSTNode<std::string>* tempPtr;
int input;
while( continueMenu )
{
std::cout << "Please enter a word to search and show frequency: \n<<";
std::cin >> tempString;
if( analyzer.tree->elementExists(tempString) )
{
tempPtr = analyzer.tree->find( tempString );
std::cout << tempPtr->word->getWord() << "\t" << tempPtr->word->getCount() << std::endl;
}
std::cout << "What would you like to do now? \n";
std::cout << "1. Save to file \n" <<
"2. Search for another word \n"
"3. Exit ";
std::cin >> input;
switch(input)
{
case 1: analyzer.saveToFile(); break;
case 2: break;
case 3: continueMenu = false;
}
}
for( int i = 0; i < wordP->size(); i ++)
{
// std::cout << std::endl << wordP->at( i )->getCount() << " " << wordP->at( i )->getWord() << std::endl;
}
for( int i = 0; i < wordP->size(); i++)
{
//std::cout << std::endl << wordP->at(i)->getWord() << " " << wordP->at(i)->getCount() << std::endl;
}
}