Using OOP, write a C++ program that read an input file and keep an array of counters for the number of letters in each word in the input file. The input file name is Poem.txt and is located in the current directory. The program will define an array of 9 elements stored in the private member variable area of the class: the 0 element will hold the number of words that are 1 letter long the 1 element will hold the number of words that are 2 letters long the 2 element will hold the number of words that are 3 letters long the 3 element will hold the number of words that are 4 letters long ....and so on until the 8 element will hold the number of words that are 9 letters long. The program will read in the contents of the file word by word into a string variable.  The program will determine the length of the word - not counting punctuation - and add to the counter stored in the element array that holds that number of letters in length.  So, if the word "midnight" is read in, the number of letters in this word is 8.  The array element counting the number of 8 letter words is incremented by 1.  Be mindful that "midnight," (comma at the end) and "midnight -", (hyphen)  is still counted as 8 letters.  Do not count any punctuation as part of the word.  This includes commas, semi-colons, periods, hyphens, question marks, etc... Add a header and closing statement as shown in the example below. When the file is opened, add an output statement indicating the file is being opened. When the file is starting to be processed word by word, add an output statement indicating the file is being processed. When the end of file is reached, display the contents of the array as shown in the example below. When the file is being closed, add an output statement indicating the file is closed. The class should use appropriate private member variables and methods.  An Example: if the contents of the input file contained this line:  Once upon a midnight dreary, while I pondered, weak and weary.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Using OOP, write a C++ program that read an input file and keep an array of counters for the number of letters in each word in the input file.

The input file name is Poem.txt and is located in the current directory.

The program will define an array of 9 elements stored in the private member variable area of the class:

  • the 0 element will hold the number of words that are 1 letter long
  • the 1 element will hold the number of words that are 2 letters long
  • the 2 element will hold the number of words that are 3 letters long
  • the 3 element will hold the number of words that are 4 letters long
  • ....and so on until the 8 element will hold the number of words that are 9 letters long.


The program will read in the contents of the file word by word into a string variable.  The program will determine the length of the word - not counting punctuation - and add to the counter stored in the element array that holds that number of letters in length. 

So, if the word "midnight" is read in, the number of letters in this word is 8.  The array element counting the number of 8 letter words is incremented by 1.  Be mindful that "midnight," (comma at the end) and "midnight -", (hyphen)  is still counted as 8 letters.  Do not count any punctuation as part of the word.  This includes commas, semi-colons, periods, hyphens, question marks, etc...

Add a header and closing statement as shown in the example below.
When the file is opened, add an output statement indicating the file is being opened.
When the file is starting to be processed word by word, add an output statement indicating the file is being processed.
When the end of file is reached, display the contents of the array as shown in the example below.
When the file is being closed, add an output statement indicating the file is closed.

The class should use appropriate private member variables and methods. 

An Example:

if the contents of the input file contained this line:  Once upon a midnight dreary, while I pondered, weak and weary.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

I need to not using "namespace std" in the code. Could you use an alternative to it

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

I need an extra line to display the total number of words in the input file and beginning and ending statements

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Array
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education