Question: Write program called word_lengths.mwhich reads a text file, splits the lines into the individual words and stores the word lengths in an array. You may

Write program called word_lengths.mwhich reads a text file, splits the lines into the individual words and stores the word lengths in an array. You may assume that words are only separated by space characters or line separators. Ensure you test your program in the case where two words are separated by more than one space character. Report the total number of words, the number of characters within the words (excluding spaces but including punctuation marks) and the lengths of the individual words.

Examine your program with the sample file mentioned above. The output should look like this:

The file has 22, word(s) containing 89 character(s).

* Word 1 has 4 character(s)

* Word 2 has 3 character(s)

* Word 3 has 1 character(s)

* Word 4 has 6 character(s)

* Word 5 has 5 character(s)

* Word 6 has 4 character(s)

* Word 7 has 6 character(s)

* Word 8 has 3 character(s)

* Word 9 has 5 character(s)

* Word 10 has 2 character(s)

* Word 11 has 5 character(s)

* Word 12 has 3 character(s)

* Word 13 has 10 character(s)

* Word 14 has 4 character(s)

* Word 15 has 4 character(s)

* Word 16 has 5 character(s)

* Word 17 has 3 character(s)

* Word 18 has 4 character(s)

* Word 19 has 3 character(s)

* Word 20 has 4 character(s)

* Word 21 has 2 character(s)

* Word 22 has 3 character(s)

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 Mathematics Questions!