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 ()*+,-C++ please!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.\n";

done = false;

} else {

cout<<"Characters for ASCII values between "<<l<<" and "<<h<<endl;

cout<<"----+----+----+-\n";

int count = 0;

for(int i = l;i <= h;i ++) {

count++;

cout<<(unsigned char)i;

if(count % 16 == 0) {

cout<<endl;

}

}

cout<<"\n----+----+----+-";

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{|}~
----+----+----+-

Add a comment
Know the answer?
Add Answer to:
C++ please! In this program you will be outputting the characters that map to the ASCIl...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • In C please : The tasks in this exam review exercise are structured in levels. You...

    In C please : The tasks in this exam review exercise are structured in levels. You can see the point distribution for the levels at the end. It is strongly recommended that you ensure you have passed all test cases of lower levels before moving up to a higher level. For example, ensure you have completed all Level 0 and 1 tasks before even looking at Level 2 Tasks. MESSAGE ENCODER LEVEL 0: (test cases - 50 points) Start by...

  • (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byt...

    (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byte unsigned int variable. Write a program that inputs four characters from the keyboard and passes them to function packCharacters. To pack four characters into an unsigned int variable, assign the first character to the unsigned intvariable, shift the unsigned int variable left by 8 bit positions and combine the unsigned variable with the second character using the bitwise inclusive OR operator....

  • In C programming please (b) You will write a program that will do the following: prompt...

    In C programming please (b) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter 'O' You will compule statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character 'Q' Example input mJ0*5/1+x1@3qcxQ The 'Q' should be included when computing the statistics properties of the input....

  • In basic c develop the code below: (a) You will write a program that will do...

    In basic c develop the code below: (a) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘X’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘X’. Example input mJ0*5/]+x1@3qcxX The ‘X’ should not be included when computing the statistics...

  • Using c++ ) You will write a program that will do the following: prompt the user...

    Using c++ ) You will write a program that will do the following: prompt the user enter characters from the keyboard you will read the characters until reading the letter O' You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ' Example inpu mJ0*5/tx1@3qcx0 The 'Q'should be included when computing the statistics properties of the input. Since characters are...

  • c program that counts the number of characters, words and lines from standard input until EOF....

    c program that counts the number of characters, words and lines from standard input until EOF. attached is what i Have so far but its not working ?. about shell redirection Requirements 1. Write a C program that counts the number of characters, words and lines read from standard Input until EOF Is reached. 2. Assume the Input is ASCII text of any length. 3. Every byte read from stdin counts as a character except EOF 4. Words are defined...

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

  • Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To...

    Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To compile, build, and execute an interactive program with a simple loop, conditions, user defined functions and library functions from stdio.h and ctype.h. You will write a program that will convert characters to integers and integers to characters General Requirements • In your program you will change each letter entered by the user to both uppercase AND lowercase– o Use the function toupper in #include...

  • Counting characters, words, and lines based on a text file

    I did the assigment but inside mainWrite a C program (called counting.c) that counts the number of characters, words and lines readfrom standard input (stdin) until EOF is reached. This means counting.c must contain a mainfunction along with other function.- Assume the input is ASCII text of any length.-Every byte read from stdin counts as a character except EOF.- Words are defined as contiguous sequences of letters (a through z, A through Z) and the apostrophe ( ' which has...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT