EXERCISE 2 In this exercise, you must write a program that analyses a large text file....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
Here is a possible implementation of the program cpp include include include include include include using namespace std class ReadWords private vecto... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Find the nth, or general, term. a. 1, 3, 9,...... b. 25, 5, 1,....... c. 1, -1, 1, -1, .....
-
What happens to the internal pressure in a fluid flowing in a horizontal pipe when its speed decreases?
-
Investment Allowance Reserve is a A. Capital reserve B. Statutory reserve C. None of A or B.
-
(a) Complete a steady-state simulation of the vinyl-chloride process in Figure 2.6. First, create a simulation flowsheet. Assume that: Cooling water is heated from 30 to \(50^{\circ} \mathrm{C}\)...
-
Set up T accounts for Cash, Unearned Ticket Revenue, and Ticket Revenue. Post the following two transactions to the appropriate accounts, indicating each transaction by letter: (a) Sold 1,500 season...
-
"How can an organization leverage automated backup verification processes to ensure the reliability and recoverability of backup data? Discuss the potential role of machine learning and artificial...
-
On December 1, 2020, Papadopoulos Seasonings had the following account balances. During December, the company completed the following transactions. Dec. 7 Received 3,600 cash from customers in...
-
Han zolo wants to invest in a bank certificate of deposit that will pay him 9 percent interest, compounded daily. If he is investing $6,110 today, how many years later will he reach his goal of...
-
A successful law firm recruits junior solicitors just after law school, as well as senior solicitors who are usually in their early thirties. Senior solicitors are required to work long hours and...
-
Three individuals consume a public good, and their demands are expressed as: P1 = 1.5 - 0.005Q (for Q < 300); P = 4.5 0.007Q (for Q < 643); P3 3.0 = 0.002Q (for Q <1500), where P represents price in...
-
Discuss the fundamental distinctions between the civil law legal tradition and the common law legal tradition. As part of your answer, briefly explore their historical origins, key features, and...
-
Nickel and cobalt are used in electric vehicle (EV) batteries. The production function is below: q = 5N +4C The price of nickel is PN = 100 and the price of cobalt is PC = 60. The EV battery firm...
-
https://hbswk.hbs.edu/item/rethinking-business-strategy-in-the-age-of-ai Provide an overview of the case. Analyze at least two concepts from the chapters that pertain to the case. Explain what should...
-
The Starlight, Inc., financial statements for the fiscal year ended June 30, 2011, are presented below. The firms sales are projected to grow at a rate of 20 percent next year, and all financial...
-
2. Assume a person bends forward to lift a load "with his back" as shown in Figure P12.42a. The person's spine piv- ots mainly at the fifth lumbar vertebra, with the principal supporting force...
-
What was the business impact of Sony hack? Explain your answer.
-
How much was Home Depot's management responsible for its problems? What about the role of technology and organizational factors?
-
How should information systems projects be selected and managed? 1. Explain the difference between tangible and intangible benefits. 2. List six tangible benefits and six intangible benefits. 3. List...
-
List differences between the temptation pattern described here and the traditional pattern.
-
What are the capabilities required to achieve temptation? Describe each of them.
-
Draw and describe the class diagram for stable temptation pattern?
Study smarter with the SolutionInn App