Answered step by step
Verified Expert Solution
Question
1 Approved Answer
EXERCISE 2 In this exercise, you must write a program that analyses a large text file. The main objectives are: 1) Search for five
EXERCISE 2 In this exercise, you must write a program that analyses a large text file. The main objectives are: 1) Search for five words in a text file. These words are given by a user. 2) Store the produced output in another text file. Plus, display the occurrence of these words and characters in a bar graph. The output should be formatted as follows (for the application output only): Searched words: Me, like, vacation, and, icecream. (The percentage here is arbitrary) Word Occurrence: Me ====== 6 (10%) Like ==== 4 (296) Vacation == 2 (196) And ====5 (6%) Icecream ==2 (196) Instructions The program should ask the user for the names of the text file to be analysed, the file containing the search words and the output file. The program should terminate cleanly with an appropriate error message if any of the files cannot be opened. For this exercise a "word" should be regarded as being a sequence of non-white-space characters containing more than one letter. Any punctuation at the beginning or end of a word should be removed (note that there may be more than once such punctuation symbol); punctuation symbols in the middle of a word and any digits are to be regarded as part of the word. You must use the function ispunct, defined in the header file cctype, to check if a character is punctuation. All input should be converted to lower case, so "IT", "It", and "it" should all be converted to "it". your program must contain a class called Readwords and a function for generation of the bar graph (which should send its output to both cout and the output file). The header file for the Readwords class and a partial implementation are provided in the ex2 folder in the zip file. A sample text file and word list will be provided to allow you to test your program. A separate (unseen) word list will be used to test your submitted work; this list will not contain more than 12 words and it will have a newline character at the end like the word list file provided. All words in the list will be in lower case so case conversion is not required. It is recommended that you input the list of words into an array of strings before processing the text file. (If s is a string variable, a statement such as file >>s; inputs the next word from the file into s skipping any white space.) Bar charts Bar charts show visually the frequencies of certain items, the widths or heights of the bars being proportional to the frequency of word appearance. The percentage, next to the number of word occurrences, is given by the number of word occurrences divided by the total of words in the text file. Challenge Overload the < < operator of the class Readwords to automatically provide the output just by attempting to print a readwords type object.
Step by Step Solution
★★★★★
3.42 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
Here is a possible implementation of the program cpp include include include include include include using namespace std class ReadWords private vecto...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started