Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Programming help: Only need help with bool isStopWord function Your program will be able to calculate the following information on any text file: The

C++ Programming help:

Only need help with bool isStopWord function

Your program will be able to calculate the following information on any text file:

The top n words (excluding stopwords; n is also a command-line argument) and the number of times each word was found

The total number of unique words in the file (excluding stopwords)

The total number of words in the file (excluding stopwords)

Total number of collisions in a hash table.

Write a function named getStopWords that takes the name of the stopwords file and a hash table to store the stopwords, fills the hash table with the stopwords, and returns void. Read in the file for a list of the top 50 most common words to ignore.

Stopwords should be saved into stopWordsTable (one of two hash tables you should create in your driver).

The file will have one word per line. We will test with files having different words in it!

*****Write a function called isStopWord that checks the stopWordsTable hash table, and returns True if the word is in the table or False if it isnt.

Header file:

#ifndef HW_7_HASH_TABLE #define HW_7_HASH_TABLE

#include

// struct to store word + count combinations struct wordItem { std::string word; int count; wordItem* next; };

/* class HashTable for storing words. * You will create two hash tables in your driver: * - one for storing stop words * - one for storing unique non-stop words * Why? We can load all the stopwords into the first table. * Then, we can quickly check that first hash table to see if * a word is a stopword before adding it to the second. */ class HashTable { public: HashTable(int hashTableSize); //constructor ~HashTable(); //destructor

void addWord(std::string word); //insert word into hash table bool isInTable(std::string word); //checks if word is already in void incrementCount(std::string word); //adds +1 to count of non stop words void printTopN(int n); //gets top "n" most common words int getNumCollisions(); //counts number of collisions int getNumItems(); //number of items in list int getTotalNumWords();

private: /* member functions */ unsigned int getHash(std::string word); wordItem* searchTable(std::string word);

/* instance variables */ wordItem** hashTable; int hashTableSize; int numItems; int numCollisions; };

/* size to make your stopwords hash table */ const int STOPWORD_TABLE_SIZE = 50;

/* Required functions for use in main. * you are free to also define your own helper functions * for your driver in your .cpp files if you wish. * These are the same functions from hw2, but use a * hashtable instead of a vector. */

/* load stopwords into the stopwords hash table */ void getStopWords(char *ignoreWordFileName, HashTable &stopWordsTable); /* check table to see if a word is a stopword or not */ bool isStopWord(std::string word, HashTable &stopWordsTable);

#endif

/* check table to see if a word is a stopword or not */

bool isStopWord(std::string word, HashTable &stopWordsTable) { *******THIS IS WHERE I NEED HELP

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions