In C++ For this problem you must create a program that accepts a line of English text as input. The string may contain spaces, so make sure you read the entire line of input. Next your program should count the occurrences of each letter of the English alphabet and determine which letter occurs most frequently in the string. Print this letter to the screen. If two letters tie for the most frequent count, break the tie by choosing the letter that occurs first in the alphabet. For example if the input string was "aabb", then your program should identify 'a' as the most frequently occurring letter. Finally, remove all occurrences of this most frequently occurring letter by replacing them with the '-' character, and print the final string to the screen. HINT: Since ascii characters are stored as 8 bit ints "under the hood", and they are also represented in order (i.e. 'a' comes before 'b'); we can use them both as characters as well as for counting. Thus if we wanted to loop through all of the lowercase letters of the alphabet we could do something like this: for(char currentLetter = 'a'; currentLetter <= 'z'; currentLetter++){ //interesting code goes here... } USE THIS IN CODE sample input aaaab a ----b You may assume that all letters are lowercase You only need to count the letters of the alphabet (i.e. don't worry about counting special characters like punctuation, digits, etc.) If two letters tie for the most frequent count, break the tie by choosing the letter that occurs first in the alphabet.
In C++
For this problem you must create a
Finally, remove all occurrences of this most frequently occurring letter by replacing them with the '-' character, and print the final string to the screen.
HINT:
Since ascii characters are stored as 8 bit ints "under the hood", and they are also represented in order (i.e. 'a' comes before 'b'); we can use them both as characters as well as for counting. Thus if we wanted to loop through all of the lowercase letters of the alphabet we could do something like this:
for(char currentLetter = 'a'; currentLetter <= 'z'; currentLetter++){ //interesting code goes here... }
USE THIS IN CODE
sample input
aaaab
a ----b
- You may assume that all letters are lowercase
- You only need to count the letters of the alphabet (i.e. don't worry about counting special characters like punctuation, digits, etc.)
- If two letters tie for the most frequent count, break the tie by choosing the letter that occurs first in the alphabet.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images