Write a function named wordStatsPlus that accepts as its

Write a function named wordStatsPlus that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report: the total number of lines; total number of words; the number of unique letters used from A-Z, case-insensitively, and its percentage of the 26-letter alphabet; the average number of words per line (as an un-rounded real number); and the average word length (also un-rounded). For example, suppose the file tobe.txt contains the following text:

To be  or not  TO BE,   THAT  IS  really   the  question.

For the purposes of this problem, we will use whitespace to separate words. That means that some words include punctuation, as in “be,”. For the input above, the call of wordStatsPlus(“tobe.txt”); should produce exactly the following output. The number of “unique letters” is 14 because the file contains 14 distinct letters of the alphabet from A-Z: a, b, e, h, i, l, n, o, q, r, s, t, u, and y.

Total lines = 4Total words = 11Total unique letters = 14 (53% of alphabet)Average words/line = 2.75Average word length = 3.45455

If the input file does not exist or is not readable, your function should instead print the following output:

Error, bad input file.

Constraints: Your solution should read the file only once, not make multiple passes over the file data.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

GradeEssays.com
We are GradeEssays.com, the best college essay writing service. We offer educational and research assistance to assist our customers in managing their academic work. At GradeEssays.com, we promise quality and 100% original essays written from scratch.
Contact Us

Enjoy 24/7 customer support for any queries or concerns you have.

Phone: +1 213 3772458

Email: support@gradeessays.com

© 2020 -2025 GradeEssays.com. All rights reserved.

WE HAVE A GIFT FOR YOU!

15% OFF 🎁

Get 15% OFF on your order with us

Scroll to Top