In this program you will be outputting the characters that map to the ASCIl code
ID: 3594823 • Letter: I
Question
In this program you will be outputting the characters that map to the ASCIl 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. 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. Once you have valid input values you need to display the 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, unsigned char, or you need to cast the integer value to a char, or unsigned char The first and last lines of output need to ber Note that each of the + characters represents a column that is a multiple of 5. So for input values of: 32 126 We would get the output: Enter lower and upper values Characters for ASCII values between 32 and 126 !"#5%6'()*+,-./ 0123456789:;? CABCDEFGHI JKLMNO PORSTUVWxYz l abcdefghijkimno pqrstuvwxyztl In the above output the value of 32 maps to the character,33 prints out as T, 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. Here is a second run with some invalid input values: 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 !"#$%6' ()*+,-Explanation / Answer
Below is your code:-
#include<iostream>
using namespace std;
int main()
{
int l,h;
bool done = false;
while(!done) {
cout<<"Enter lower and upper values: ";
cin>>l>>h;
if((l < 32 || l > 126) || (h < 32 || h > 126) || l > h) {
cout<<"Values must be in the range 32 to 126 inclusive. ";
done = false;
} else {
cout<<"Characters for ASCII values between "<<l<<" and "<<h<<endl;
cout<<"----+----+----+- ";
int count = 0;
for(int i = l;i <= h;i ++) {
count++;
cout<<(unsigned char)i;
if(count % 16 == 0) {
cout<<endl;
}
}
cout<<" ----+----+----+-";
done = true;
}
}
return 0;
}
Sample Run: -
Enter lower and upper values: 124 119
Values must be in the range 32 to 126 inclusive.
Enter lower and upper values: 31 125
Values must be in the range 32 to 126 inclusive.
Enter lower and upper values: 38 128
Values must be in the range 32 to 126 inclusive.
Enter lower and upper values: 32 126
Characters for ASCII values between 32 and 126
----+----+----+-
!"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[]^_
`abcdefghijklmno
pqrstuvwxyz{|}~
----+----+----+-
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.