This project will help you show your mastery of branching, looping, strings, and even arrays (in parallel?).
Write a program to read in a line of text and output the number of words in the line as well as the number of occurrences of each letter [present]. A word is defined to be any sequence of letters that is delimited at each end by whitespace, terminal punctuation (which would be periods, commas, colons, etc. but not single quotes, hyphens, or such), or an end of the line (be it the beginning or actual end). You should make no assumptions about the content of the user's line — allow any legitimate input characters.
When outputting the number of letters that occur in a line, be sure to count upper- and lower- case versions of a letter as the same letter. Output the letters in alphabetical order. As implied above, only list letters that occur in the input line.
For example, if the user entered 'I say Hi.', your program should produce something like:
Your line contained 3 words. The following letters occurred the indicated number of times: a 1 h 1 i 2 s 1 y 1
But if the user entered 'How do you do? Our Home and Office production line of products does just about anything you'd expect an ordinary one to do -- but there's more!', you'd report:
Your line contained 26 words. The following letters occurred the indicated number of times: a 5 b 2 c 4 d 9 e 10 f 3 g 1 h 4 i 5 j 1 l 1 m 2 n 8 o 19 p 3 r 7 s 4 t 9 u 8 w 1 x 1 y 4
You must input the entire line at once (as implied above). You cannot read their input word-by-word!
This assignment is (Level 6).
Add (Level 2) to find the mode (most frequently occurring letter) of the user's input. Be careful: what if there were 5 letters each of which occur 3 times?! "My beige cat takes tons of acorns."
(Hint: This option requires the use of arrays.
Add (Level 2) to make the printout as neat as above. Notice how the counts are right justified just wide enough so that the largest of them is a space away from its letter. Hmm... Larger numbers have more digits... And the space is set wide enough for that many characters plus one... Hmm...
There are two ways to implement this program using arrays (that's the array class from chapter 6 — not any other type of array!). You may choose one or both. To do both, you must script (including show-code, cat, CPP, and testing) both versions of your program!
Add (Level 2) to use a pair of parallel arrays with the counts in one and the letters in the other.
Add (Level 4) to use a single array and some typecasting while you count.
Add (Level 1) to do pairs of phrases and tell the user additionally whether their two phrases are anagrams of one another. (Note that a phrase may be a single word and that punctuation and spacing and case are all automatically ignored — just like for our program!)
(Tip: This option is made ridiculously easy if you used arrays as described in the second variation above.)
Bonus points if you can explain where the title of this project came from...
Note: This project is adapted from ones given in textbooks by Walter Savitch.
If you did all above options, this project could be worth as much as (Level 16).