Question: Print the first 100 words unique words found in a file, sorted, along with the number of occurences of each word. Write a program that

Print the first 100 words unique words found in a file, sorted, along with the number of occurences of each word.

Write a program that initally prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program inputs each token in the file, storing up to the first 100 unique ones found, and prints the tokens, sorted, each accompanied by the number of times it appeared, in a well formatted manner. To accomplish this, the user must

1. open the file (the user must be prompted and a file name input. Do not hardcore a file name)

, 2. Read the words in the file-placing them in alphabetical order in an array of struct with capacity 100

3. report results.

We must also write functions for the following:

Open a file- Pass an ifstream(must be a reference argument, the function prompts the user and it if the file is found, it returns true and if the ifstream will be a handle for that text file.otherwise the text file returns false.

Populate the array of struct with the words in the file-Pass in three reference arguments, th eifstream, the 100 element array of word count structs, and the count of elements in use in the array. When the function completes, the array will hold the words in the file, ordered

Search for a token: Pass in the array of struct (automatic by reference) its in use count (value) and a token (also by value). Return the index where the token was found or if not found, the index where failure could be established.

output results: Pass in the variables that hold the file name(for printing purposes), the array, and its in use count. Use this data to produce desired output which should be formatted

Increment the counter member of a struct that holds a word and its multiplicity

increment the count member of a struct that holds a words and its multiplicity:Pass ina single stuct; it will be an import/export parameter. Simply increment its counter memeber

For each token input the populate function will call the search function to obtain the index where the token is to be palced. The cases for this aretaht the index returned by the search

1.equals the value of the array in use counter

2.is of a struct holding a token equivalent to the token searched for (search successful)

3. is of a struct holding a token greater to the token searched for (search succesful)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!