Question
#include #include #include #include #include using namespace std; struct wordItem { string word; int count; }; void doubleArraySize(wordItem* &arrayPtr, int* length); void getStopWords(char *ignoreWordFileName, string
void doubleArraySize(wordItem* &arrayPtr, int* length);
void getStopWords(char *ignoreWordFileName, string ignoreWords[]);
bool isStopWord(string word, string ignoreWords[]);
int getTotalNumberNonStopWords(wordItem list[], int length);
void arraySort(wordItem* &list, int length);
void printTopN(wordItem wordItemList[], int topN,int totalNumWords);
int totalNumWords=0;
int main(int argc, char* argv[]) { string ignoreWords[100];
getStopWords(argv[3], ignoreWords);
std::ifstream documentStream(argv[2], std::ios::in);
if (documentStream.fail()) { return -1; }
int length = 100; int index = 0; int numDoublings = 0; wordItem* documentArray = new wordItem[length]; string currentWord; while (documentStream >> currentWord) { bool repeatWord = false; if (!isStopWord(currentWord, ignoreWords)) { for (int i = 0; i
arraySort(documentArray, index);
printTopN(documentArray, std::stoi(argv[1]),totalNumWords); std::cout
void doubleArraySize(wordItem* &arrayPtr, int* length) { int newLength = *length * 2; wordItem* newArray = new wordItem[newLength]; for (int i = 0; i
void getStopWords(char *ignoreWordFileName, string ignoreWords[]) { std::ifstream ignoreStream(ignoreWordFileName, std::ios::in);
if (ignoreStream.fail()) { return; }
string tempLine; int index = 0; while (getline(ignoreStream, tempLine)) { ignoreWords[index] = tempLine; index++; } ignoreStream.close(); }
bool isStopWord(string word, string ignoreWords[]) { for (int i = 0; i
int getTotalNumberNonStopWords(wordItem list[], int length) { int total = 0; for (int i = 0; i
void arraySort(wordItem* &list, int length) { for (int j = 1; j
while (i >= 0 && list[i].count
void printTopN (wordItem wordItemList[], int num,int totalNumWords) { for (int x = 0; x
#include
Test Expected Got x/program 10 HarryPotter.txt ignorewords.txt Array doubled: 6 inf harry inf - was inf said inf had inf - him inf- ron Unique non-common words: 5985 Total non-common words 50331 Probabilities of top 10 most frequent words inf were inf hagrid inf - them inf- back Array doubled: 6 0.0241 harry 0.0236 was 0.0158 said 0.0139 had 0.0100 -him 0.0081ron 0.0068 were 0.0067 hagrid 0.0065 them 0.0052 back Unique non-common words: 5985 Total non-common words: 50331 Probabilities of top 10 most freq Array doubled: 6 inf harry infwas X/program 5 HarryPotter.txt ignorewords.txt Unique non-common words: 5985 inf - said inf had inf him Total non-common words: 50331 Array doubled: 6 Probabilities of top 5 most frequent words Unique non-common words: 5985 0.0241 harry .0236was 0.0158 said 0.0139 had 0.0100 him Total non-common words: 50331 Probabilities of top 10 most frequ /program 10 HungerGames_edit.txt ignorewords.txt Array doubled: 7 inf is int peeta inf its inf im inf - can inf says Unique non-common words 7682 Total non-common words: 59157 probabilities of ton le most frequent wo rds | nfStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started