You are to write a program that will read a text file, echo it to the screen, and create an array of the words in the file. When the program terminates, it should produce a list of the words encountered. and the number of times each word occurred (this information is to be stored in the array). The ordering of that list should be based on the order in which the words first occurred in the original text file, with one word per line. Format the output line as: Word Count See 14 Spot 4 Run 25 You may assume the following simplifying characteristics concerning the text file. The punctuation in the file consists only of periods, question marks, exclamation marks, and commas. There are 2 blanks following each period, exclamation mark, or question mark, followed by the first letter of the next sentence. The two blanks will be omitted if the delimiter terminates a line.
You are to write a
Word Count
See 14
Spot 4
Run 25
You may assume the following simplifying characteristics concerning the text file.
The punctuation in the file consists only of periods, question marks, exclamation marks, and commas.
There are 2 blanks following each period, exclamation mark, or question mark, followed by the first letter of the next sentence.
The two blanks will be omitted if the delimiter terminates a line.
There will be exactly one blank or the eoln marker following each comma.
Each line will terminate with ‘/n’.
A ‘/n’ will never be preceded by a blank.
Paragraphs will be separated by a blank line but will not be indented.
Words that begin on a line in the text file will always end on that same line. Thus, no hyphenated words will occur.
The list itself should be handled with an array of string [20]. That means you are to use c-strings, not string class objects in this program. You can assume that no word is longer than 19 letters. Recall that if you compare two strings of different lengths, the system will see them as two different strings. That is, a string [10] that contains Hello followed by 4 blanks, is not equivalent to a string [20] that contains Hello followed by 14 blanks. So (HINT), as you build a new word, blank out a string [20], and construct the word a letter at a time in the string [20]. You will know you have come to the end of a word when you encounter one of the word delimiters (period, comma, question mark, exclamation mark, and, of course, a blank space). Be sure to place the null terminator character (‘\0’) at the first unused space in the array to mark the end of the string.
Turn In: Source Code (well documented) by the due date, and a copy of your output from the data file I will provide later. This file will be made available in the folder containing this program assignment on Blackboard by 8 PM on Monday, 3-1, 2021. Assume the data file will be called countem.txt. You will need to test the program extensively prior to seeing my data file. That is, test the program as you develop it with your own data files.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps