Question
-could you please solve this question in c++? 2. Initialize the letter array to be a 26 element array of zeroes. 3. Prompt for a
-could you please solve this question in c++?
2. Initialize the letter array to be a 26 element array of zeroes.
3. Prompt for a sentence. You should convert the sentence to lower case so that you only need one array of letters as shown.
The following example converts a string to lowercase:
string data = ABC;
transform(data.begin(), data.end(), data.begin(), tolower);
4. When stepping through the sentence you MUST consider the ASCII equivalence! Look at your ASCII table, what is the range of ASCII values from lowercase a to lowercase z?
5. If your character is a certain letter, you will want to increment the appropriate element in your letter array (as in, count its occurrences!). Look at the picture of the array in the problem statement. If my letter is a, its ASCII value is 97. A 97 means I want to increment index 0 of the letter array. So, use your ASCII value to determine the index (i.e., what is 97 97?) Does this work for all the letters?
6-. Add one to the correct letter element by using the index youve determined in step 5. Now you will step to the next character in your sentence and return to step 4 again. Once your array is populated (steps 4, 5 & 6), step through the letter array with a second for-loop, outputting the letter and its number of occurrences. In order to increment the letter, consider the ASCII equivalent again. If there is one occurrence of the letter, the output should state 1 time. All other occurrences should state x times, where x is the actual number.
Sample Output :
Enter your sentence: I am a student
a occurs 2 times
b occurs 0 times
c occurs 0 times
d occurs 1 time
e occurs 1 time
f occurs 0 times
g occurs 0 times
h occurs 0 times
i occurs 1 time
j occurs 0 times
k occurs 0 times
l occurs 0 times
m occurs 1 time
n occurs 1 time
o occurs 0 times
p occurs 0 times
q occurs 0 times
r occurs 0 times
s occurs 1 time
t occurs 2 times
u occurs 1 time
v occurs 0 times
w occurs 0 times
x occurs 0 times
y occurs 0 times
z occurs 0 times
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started