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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

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.

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.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT