Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

plase write a C++ program that will read a text file, echo it to the screen, and create an array of the words in the

plase write a C++ 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.

Your program should be case insensitive. Thus, the words Follow, FOLLOW, and follow would all be treated as the same word. When the word is stored in the list, save it as all lower case. Each word should be stored in the list only once, no matter how many times it occurs in the file.

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.

file will be he data file will be called countem.txt

Roses are Red. Violets are blue? Sugar is sweet. And so are you. Two roads diverged in a yellow wood, and Sorry I could not travel both, and be one traveler. Long I stood and looked down one as far as I could to where it bent in the undergrowth! Then took the other as just as fair, though having perhaps the better claim, for it was grassy and wanted wear. Though as for that the passing there had really worn them about the same. Both that morning equally lay, in leaves no step had trodden black. I saved the first for another day. Yet knowing how way leads on to way I doubted if I would ever come back. Some day ages and ages hence I shall be telling this with a sigh. Two roads diverged in a yellow wood, and I I took the one less traveled by. And that has made all the difference.

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

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions