Question: In this program you will be outputting the characters in C++ that will map to the ASCII codes 32 through 126. You will need a
In this program you will be outputting the characters in C++ that will map to the ASCII codes 32 through 126. You will need a loop to iterate through the input values and output the corresponding character. This mapping is shown in appendix A in your Gaddis text book.
Your program will be reading in two unsigned integer values. You will then display the characters that map to the range of integer values. You will have a total of three functions. One will be your main function. The other two will 1) read the range of values, and 2) display the values as characters.
The read function
The read function will take two unsigned int values, both passed by reference. The return type for the read function will be void.
Your read function will prompt for the two values. If the values are valid, your function will update the two values passed by reference. If the values are invalid you need to display an error message, issue the prompt, and read the values again. You will do this in a loop in your function. The function will not return to the called until two valid values have been entered by the user.
The prompt for read will be:
Enter lower and upper values
You need to check that both values are in the range of 32 to 126. If the values are less than 32 or greater than 126 you need to display the message:
Values must be in range 32 to 126 inclusive
You will also display the above message if the first value read in is larger than the second value.
If the values are invalid you need to reread the values with the prompt.
Enter lower and upper values
You need to keep reading in values, checking if they are valid and displaying an error message until the values read in are valid. You can use a while or do while loop to do this.
display function
The display function will be passed the two values read in by the read function. See the details on main to make sure you are doing this from the right function.
You need to display the range of values as characters with 16 characters per line of output. To output an integer value as a character you must either store the integer value in a char,or unsigned char; or you need to cast the integer value to a char, or unsigned char.
The first line of output will be a message:
Characters for ASCII values between xx and yy
Where xx is the lower value and yy is the upper value.
The second and last lines of output need to be:
----+----+----+-
Note that each of the + characters represents a column that is a multiple of 5.
So for parameter values of:
32 126
The display function will output:
Characters for ASCII values between 32 and 126 ----+----+----+- !"#$%&'()*+,-./ 0123456789:;<=>? @ABCDEFGHIJKLMNO PQRSTUVWXYZ[\]^_ `abcdefghijklmno pqrstuvwxyz{|}~ ----+----+----+- In the above output the value of 32 maps to the character ' ', 33 prints out as '!', and so on until we get to 126 that maps to '~'. Also see Appendix A in the Gaddis text book for the ASCII character mappings.
main function
The main function will:
Call the read function to get the two input values (lower and upper range).
Pass the lower and upper values to the display function.
Here is a sample run
Input to cin:
32 126
Output to cout:
Enter lower and upper values Characters for ASCII values between 32 and 126 ----+----+----+- !"#$%&'()*+,-./ 0123456789:;<=>? @ABCDEFGHIJKLMNO PQRSTUVWXYZ[\]^_ `abcdefghijklmno pqrstuvwxyz{|}~ ----+----+----+- Here is a second run with some invalid input values for cin:
127 31 33 46
We get the following output:
Enter lower and upper values Values must be in range 32 to 126 inclusive Enter lower and upper values Characters for ASCII values between 33 and 46 ----+----+----+- !"#$%&'()*+,-. ----+----+----+-
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
