Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Programming can anyone help me with this program. Description: Print the first 100 unique words found in a file, sorted, along with the number

C++ Programming
can anyone help me with this program. image text in transcribed
Description: Print the first 100 unique words found in a file, sorted, along with the number of occurrences of each word. if statement For your first project, you will write a program that initially 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 all this, do the following: Open the file - the user must be prompted and a file name input. DO NOT hardcode a file name. Read the words in the file, placing them in alphabetical order in an array of struct with capacity 100, where each struct has a string (the word) and an int (number of occurrences). Report the results You must write appropriate functions for each task. At minimum, you must write a function for each of the following: Open the file: Function o Pass in an ifstream (must be passed by reference [what type of parameter is it?]). The function prompts the user and, if the file is found, it returns true and the ifstream will be a handle for that text file. Otherwise the function returns false, and the argument is assumed to be undefined. Populate the array of struct with the words in the file: Function O Pass in three reference arguments, the ifstream, 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: function O Pass in the array of struct (automatically by reference), its in-use count (by 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 (see below). Output results: function Pass in the variables that hold the file name (for printing purposes), the array, and its in-use count. Use this data to produce the desired output, which should be appropriately formatted. Increment the counter member of a struct that holds a word and its multiplicity: L o Pass in a single struct; it will be an import/export parameter. Simply increment its counter member. Opening the file and printing the tokens with multiplicity are both straight-forward. Populating the array is bit more complex, as the list is to be maintained in order at all times. For each token input, the populate function will call the search function to obtain the index where that is to be placed. The cases for this are that the index returned by the search: 1. Equals the value of the array's in-use counter 2. Is of a struct holding a token equivalent to the token searched for 3. Is of a struct holding a token greater than the token searched for

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

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

List the advantages and disadvantages of the pay programs. page 505

Answered: 1 week ago