Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There is one test file in the dropbox link called HungerGames_edit.txt that contain the full text from Hunger Games Book 1(LINK: https://www.dropbox.com/sh/y07ivem7umm9e54/AAD7fRMU6SL9yYAfp_uP70u2a?dl=0). We have pre-processed

There is one test file in the dropbox link called HungerGames_edit.txt that contain the full text from Hunger Games Book 1(LINK: https://www.dropbox.com/sh/y07ivem7umm9e54/AAD7fRMU6SL9yYAfp_uP70u2a?dl=0). We have pre-processed the file to remove all punctuation and down-cased all words.

Your program needs to read in the .txt file, with the name of the file.Your program needs to store the unique words found in the file in a dynamically allocated array and calculate and output the following information:

- The top n words (n is also a user input) and the number of times each word was found

- The total number of unique words in the file

- The total number of words in the file

- The number of array doublings needed to store all unique words in the file

Your program needs to have two inputs the first input is the name of the file to open and read, and the second input is the number of most frequent words to output.

Inputs HungerGames_edit.txt and 10 would return the 10 most common words in the file HungerGames_edit.txt and should produce the following results:

682 - is

492 - peeta

479 - its

431 - im

427 - can

414 - says

379 - him

368 - when

367 - no

356 - are

#

Array doubled: 7 #

Unique non-common words: 7682

#

Total non-common words: 59157

Use an array of structs to store the words and their counts There are specific requirements for how your program needs to be implemented. For this assignment, you need to use an array of structs to store the words and their counts. The members of the struct are left to you, but keep it as simple as possible. Exclude these top 50 common words from your word counting The attached image shows the 50 most common words in the English language. In your code, exclude these words from the words you count in the .txt file. Your code should include a separate function to determine if the current word read from the .txt file is on this list and only process the word if it is not.

image text in transcribedUse the array-doubling algorithm to increase the size of your array. We dont know a head of time how many unique words either of these files has, so you dont know how big the array should be.Start with an array size of 100, and double the size as words are read in from the file and the array fills up with new words. Use dynamic memory allocation to create your array, copy the values from the current array into the new array, and then free the memory used for the current array. Note: some of you might wonder why were not using C++ Vectors for this assignment. A vector is an interface to a dynamically allocated array that uses array doubling to increase its size. In this assignment, youre doing what happens behind-the-scenes with a Vector.

Create a WordAnalysis class All of the functionality above should be included in methods in a Word Analysis class. The header file for the class, called WordAnalysis.h is also available at the end. You need to implement the methods defined in the header exactly as they are defined. You can test that your cpp code works by building the files and running the executable. g++ -std=c++11 WordAnalysis .cpp -o WordAnalysis The following methods and variables are defined in WordAnalysis.h.

//////// WordAnalysis.h /////////

struct word { int count; std::string w; };

class WordAnalysis{ private:

//stores the number of times the array has been doubled in the program int timesDoubled;

//stores the array of words. Memory will be dynamically allocated word *words;

/*current size of the array. When you double the array, wordCount = wordCount * 2 to double the size */ int wordCount;

//how many unique words found int index;

//call this method when you want to double the array and add the new word to the array. The new word is the input to the method. void doubleArrayAndAdd(std::string);

//call this method to check if a word is in the common word list bool checkIfCommonWord(std::string);

//call this method to sort the words array void sortData(); public:

//call this method to open a file and read in the data. The filename is the argument bool readDataFile(char*); //returns an error if file not opened

//returns index * count for each word int getWordCount();

//returns index variable int getUniqueWordCount();

//returns timesDoubled variable int getArrayDoubling();

//call this method to print the common words. The argument is the number of words to print void printCommonWords(int);

//call this method to print the final output of your program void printResult(int);

//constructor. The argument is the initial size of the array WordAnalysis(int); ~WordAnalysis(); };

Word Rank Word Rank an or 18 The 35 You One 2 19 Do All 36 To 20 At 37 Would 4 21 This There 38 5 And 22 But 39 Their 6 A 23 What His 40 7 In 24 By 41 8 That 25 From 42 Up 9 Have 26 They 43 Out 27 We 44 If 10 11 28 Say 45 About 12 For 29 Her 46 Who 13 Not 30 She 47 Get 14 31 48 Which 15 With 32 An 49 Go 16 He 33 Will 50 Me 34 My 17 As

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

Write to groups, gatekeepers and the universe

Answered: 1 week ago