The assignment is to write a C++ program that counts the occurrences of each letter in a line of input. The program will prompt the user to type in a string of characters. After the user presses the return key, the program looks at each character, keeping count of how many of each letter were input. The program needs to deal only with the letters A through Z. Also, the program will not distinguish between uppercase letters and lowercase letters. This means that the letter 'A' and the letter 'a' are considered to be the same letter.
After the program calculates the counts, it will print a table listing each character, the number of times it occurred, and the relative frequency within the string. A final line will be printed after the table indicating the total number of letters that were in the string. Note that all spaces and punctuation are ignored, and therefore, are NOT considered to be letters. Here is an example of how the program prompts the user and displays the output:
Enter a string of characters, then press return:
The quick brown fox jumped over the lazy dogs.
Character Occurrences Frequency
---------------------------------------
A 1 2.70%
B 1 2.70%
C 1 2.70%
D 2 5.41%
E 4 10.81%
(fill in the rest of the table)
Y 1 2.70%
Z 1 2.70%
Total letters: 37
You must follow this format exactly. I will be using an automated script to input up to 1000 characters into your programs.
Details
- The program must handle up to 1000 characters. Trying to handle more than 1000 may cause problems under Turbo C++. If you try to deal with more than 1000, you do so at the risk of it failing when I test it.
- You must use an array to keep track of how many occurrences there are of each letter. DO NOT create 26 different named variables to use as counters.
- When displaying the Frequency, you must align the decimals and show 2 decimal places always.
- Don't add any other prompts or loops asking for additional input. I test your programs with scripts, so everyone's program must do the exact same thing.
- Follow the programming paradigm that we have been using in most programs: get the data from the user, perform the calculations, print out the results. NOTE: For this assignment you should NOT print out the input. Normally, that is what you do when you display the results. However, the input will be quite verbose, so you shouldn't re-display it. This is an exception for this assignment only.
- Each function you write (including main) should have a pseudo code comment above its definition. This is NOT the same thing as the function header comments that you also need to include. All function header comments must accompany the function declarations at the beginning of your program. This way, I can distinguish between your header comments and your pseudo code.