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.
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.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images
I need to not using "namespace std" in the code. Could you use an alternative to it
I need an extra line to display the total number of words in the input file and beginning and ending statements