(Solved) : Write C Program Prompts User Input File Name Opens Input File Reading Count Number Words F Q35549191
Write a C++ program that
- Prompts the user for an input file name and opens the inputfile for reading.
- Count the number of words in the file. If the file has morethan 1000 words then display a message indicating the number ofwords in the file, close the file, and end the program. In otherwords, do not proceed unless the file contains 1000 or fewerwords.
- Create an array of C++ string objects with a size of 1000.Initialize each element of the array to a null string (“”).
- Read each word in the input file. If the word is already storedin the array then do not store it again, but if the word is notalready stored in the array then add it to the array. In otherwords, the array should contain a list of the unique, distinctwords in the input file, and each word should appear only one timein the array.
- Display the count of the total number of words stored in thearray, and then display each word in the array.
Your program must implement and use the following functions withthe function signatures as shown:
- void openFile(ifstream &); – This function accepts an inputfile stream variable passed by reference. The function prompts theuser for a file name, and then opens the file for input. If thefile does not exist then the function re-prompts the user. Thefunction must not return until a valid file name has been entered,and the input file is open. This function must be used to open theinput file in your program.
- int find(string *, string); – This function accepts your stringarray (string *) as the first parameter, and a string as the secondparameter. The function searches the array for the string, andreturns the position (subscript number) of the array element thatmatches the string. If the string is not found the function shouldreturn a -1. This function must be used for your arraysearches.
- int append(string *, string); – This function accepts yourstring array (string *) as the first parameter, and a string as thesecond parameter. The function “appends” the string to the array,i.e. set the value of the first free element of the array to thevalue of the string given in the second parameter. This functionmust be used to add a new string to your word list array.
Your program may use additional functions if desired (such as anarray print function), but no additional functions arerequired.