Chapter 7 Exercise Set 0: Chapter Review¶
Write the code from the Containers for strings section in a file named
hello_strings.cpp, compile it, and run it.Write a function that takes a
stringas an argument and that outputs the letters backwards, all on one line.Encapsualte the code from the Looping and counting section in a function named
count_letters, and generalize it so that it accepts both the string and the letter as arguments.
Rewrite the
count_lettersfunction from the previous exercise so that instead of traversing the string, it uses thefindfunction.Fix the code in String concatenation so that “Ouack” and “Quack” are spelled correctly.
Use the
cctypelibrary write functionsstring_to_upperandstring_to_lowerthat take a singlestringas an argument and return a string consisting of all upper or lower case letters.
ASCII values and the compare member function¶
Look up the decimal value of the character
'A'in the ASCII table. Now do the same for the character'x'.Explain in your own words how the
ourstoifunction presented in String of digits to int works. Start with a five digit string and write out the trace of the execution of callingourstoiwith your string.In Character classification you were introduced to two functions,
toupperandtolower. Write your own versions of those functions. To make them portable across character encodings, rely on all the upper case and lower case characters being in linear sequences. Then use the distance between the two sequences as a constant in the logic of your algorithm.