Question: can you help me with this code and add comments please thank you! C++ Create a program that counts the length of each word in

can you help me with this code and add comments please thank you!

C++

Create a program that counts the length of each word in a phrase and then displays the number of 1, 2, 3, 4, and 5-letter words it contains. Name your source file WordLength.cpp To solve this problem, create the following functions.

  1. isWhitespace that accepts a character and returns a Boolean value. Return true if the character is a space, tab, newline ("n'), and carriage return ('r'). Otherwise, return false. Use a switch statement.
  2. countWordsByLength: This is a void function that has five integer parameters. When the function finishes the actual parameters will hold the number of occurrences of each word length on one line of input from cin. For example, the first parameter will hold the number of 1-letter words. This function should do the following.
  1. Create and initialize a variable that will be used to count the number of letters in a word.
  2. Before anything else, set all the parameter values to zero (because we have not counted any words yet).
  3. Then use cin. get to read in each character of the user's input until reaching a newline character ("n'). For each character read in as input, check to see if it is a letter, whitespace, or something else.
  • If it is a letter, add 1 to a counter letter count variable. Do not count non-letter characters.
  • If the character is whitespace (use your is Whitespace function to check), update the parameter value associated with the letter counter variable. Then, reset the letter count to zero for the next word.

This function should not print anything to the screen. Hint: Do the parameters need to be pass-by-value or pass-by-reference?

  1. printCount: This void function accepts two integer parameters that represent a single word length to receive a value of 1, 2, 3 . 5 and the number of words with that number of letters. It then outputs "x-letter words: y", except x is the letter count and y is the word count. The number should be in a right-aligned column with a width of 3 characters. You will call this function 5 times (once for each word length).
  2. main should display, "Enter some text:". Then, call count WordsByLength to retrieve the text and count the words. Finally, main should display the counts by calling printCount 5 times, 1 time per word length.

Sample Output (user input is in yellow)

Enter some text: Hey Y'all! ... It's 1 test, typed by me. ;-)

1-letter words: 0

2-letter words: 2

3-letter words: 2

4-letter words: 2

5-letter words: 1

_

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!