Question

In: Computer Science

We have talked a bit about how chars are really just ASCII integers. Let's see this...

We have talked a bit about how chars are really just ASCII integers. Let's see this in action. We will show the characters starting at ASCII 33 and end with a user-supplied number. Use a for loop to output the characters with two spaces between each.

Prompt:

This program will output the ASCII characters starting at 33
Enter the integer for the last ASCII character you wish to see: [user types: 43]

Output:

! " # $ % & ' ( ) * +  

Notes and Hints:

1) You MUST use a FOR LOOP

2) Hint: Which operator from Chp 3 allows us to convert from one data type to another?

3) FYI only: http://www.asciitable.com/

// CONSTANTS AND VARIABLES
Starter Code:

// INPUT
std::cout << "This program will output the ASCII characters starting at " << YOUR_CODE << std::endl;
std::cout << "Enter the integer for the last ASCII character you wish to see: ";
  
std::cout << std::endl; // For Mimir

// LOOP and OUTPUT

std::cout << YOUR_CODE << " ";
  

Solutions

Expert Solution

Hello!

Here for this problem we have to use type conversion or type casting.

Type casting: Conversion of data type to another data type.

There are 2 types of type casting.or type conversion

1.Implicit type casting.

2. Explicit type casting.

Implicit conversion:

In this conersion the complier automatically converts the data type to another type

Example:

int i = 33;

char c = i;

cout << c; // so it prints the equivalent ascii for 33 which is !

Another example when we want to add double and int the int data is converted to double automatically, so that there will no loss of data. Complier converts smaller data type to larger data type.

Explicit conversion:

Here we force the complier to convert one data type to another data type.

This we can achive in 2 types:

1.

int i = 66

cout << (char) << endl; // so it prints the equivalent ascii for 66 which is B

2.

int i = 69

cout << (char) << endl; // so it prints the equivalent ascii for 69 which is E

SO based on the above concept we can achive the output you have given

Please try to understand the code and it will be very easy after reading the concept. if you have any doubts please feel free to comment , I will help you in 15 min.

METHOD 1:

CODE:

#include <iostream>

int main() {
    int initial,final;
    initial = 33;
    int YOUR_CODE = initial;
    // INPUT
    std::cout << "This program will output the ASCII characters starting at " << YOUR_CODE << std::endl;
    std::cout << "Enter the integer for the last ASCII character you wish to see: ";
    
    std::cin >> final;
    std::cout << std::endl; // For Mimir
    
    // LOOP and OUTPUT
    for(YOUR_CODE=initial;YOUR_CODE<=final;YOUR_CODE++)
    std::cout << (char)YOUR_CODE << " ";


    return 0;
}

OUTPUT:

Method 2:

CODE:

#include <iostream>

int main() {
    int initial,final;
    initial = 33;
    int YOUR_CODE = initial;
    // INPUT
    std::cout << "This program will output the ASCII characters starting at " << YOUR_CODE << std::endl;
    std::cout << "Enter the integer for the last ASCII character you wish to see: ";
    
    std::cin >> final;
    std::cout << std::endl; // For Mimir
    
    // LOOP and OUTPUT
    for(YOUR_CODE=initial;YOUR_CODE<=final;YOUR_CODE++)
    std::cout << static_cast<char>(YOUR_CODE) << " ";


    return 0;
}

OUTPUT:

THE SAME OUTPUT AS IN METHOD 1

Hope this helps and clear.

I strive to provide the best of my knowledge so pleamse upvote if you like the content.

Thank you!


Related Solutions

In this course, we have talked about four uses of empowerment and participation. We said they...
In this course, we have talked about four uses of empowerment and participation. We said they are part of delegation, used to overcome resistance to change, used to overcome resistance to control, and used for motivation. Now, explain why empowerment and participation work in all of these areas.
Q- We have discussed the topic “Rationale of Regulations “ in which we talked about the...
Q- We have discussed the topic “Rationale of Regulations “ in which we talked about the reasons for having regulations in a given country. Rationale of Regulations including issues of monopoly, windfall profits, externalities, social policy, information inadequacies, continuity and availability of services, anti-competitive behavior and predatory pricing, public goods and moral hazard, unequal bargaining power, scarcity and distribution of wealth, rationalization and coordination, and planning. Examine only one of the above Rationale of Regulations by providing a definition, an...
In the discussion for fatigue up to this point we have talked about the damaging effect...
In the discussion for fatigue up to this point we have talked about the damaging effect of the number of cycles of loading but we have not discussed about frequency (i.e. how often these loading cycles occur). Which class of materials do you think might be sensitive to the frequency of loading? Provide two physical mechanisms that may affect fatigue life (at least indirectly).
At the start of the chapter, we talked about how risky and volatile airlines’ operations are....
At the start of the chapter, we talked about how risky and volatile airlines’ operations are. Let us examine this further. Go to finance.yahoo.com . Enter “UAL” for United Continental Holdings in the “Quote Lookup” box. Scroll down to “United Continental Holdings” and click. Click on “Profile” under the stock price and to the right of “Summary.” Write a one-paragraph description of the company. Now click on “Financials.” Look at the Income Statement and describe the pattern of change for...
we talked earlier about measuring demand curves. how might we proceed if we want to measure...
we talked earlier about measuring demand curves. how might we proceed if we want to measure congestion Externalities associated with various outdoor recreation activities?
Describe the difference between discounting and interest, referring to the way we have talked about it...
Describe the difference between discounting and interest, referring to the way we have talked about it in class. Specifically use this example: A company is looking to purchase an item worth 10k today. The same item can be purchased 3 years later for 10k. Why is the second option more desirable, and how much more desirable is it if your cost of capital is 5%?
To what extent can we really see the world as it really is? 2.To what extent...
To what extent can we really see the world as it really is? 2.To what extent is truth a function of power? 3.To what extent to texts have stable meanings? 4.What are the best Christian “take-aways” from postmodernism?
1. At the start of the chapter, we talked about how risky and volatile airlines’ operations...
1. At the start of the chapter, we talked about how risky and volatile airlines’ operations were. Let’s examine this further. Go to finance.yahoo.com. Enter UAL for United Continental Holdings in the “Get Quotes” box. Go to “Company” along the left-hand margin. 2. Click on “Profile” in the left-hand column and write a one-paragraph description of the company. (https://finance.yahoo.com/quote/UAL/profile?p=UAL) 3. Scroll down and click on the “Income Statement.” Describe the pattern of change for “Total Revenue” and “Income from Continuing...
We talked in class about how some textbooks tell us that the way to conduct a...
We talked in class about how some textbooks tell us that the way to conduct a cost benefit analysisassociated with a policy is to look atthe costs and benefits beforea policy was put in place and compare them to the cost and benefits after the policy is in place. Is this correct? If so, explain why. If not, explain why not. NOTE: I realize that you should say "with" or "without" the policy, NOT "before" and "after" but I don't...
1. At the start of the chapter, we talked about how risky and volatile airlines’ operations...
1. At the start of the chapter, we talked about how risky and volatile airlines’ operations were. Let’s examine this further. Go to finance.yahoo.com. Enter UAL for United Continental Holdings in the “Get Quotes” box. Go to “Company” along the left-hand margin. 2. Click on “Competitors.” How does UAL compare (https://finance.yahoo.com/quote/UAL/profile?p=UAL) Revenue 12/31/2016 12/31/2015 12/31/2014 Total Revenue 36,556,000 37,864,000 38,901,000 Income from Continuing Operations Total Other Income/Expenses Net 23,000 -327,000 -562,000 Earnings Before Interest and Taxes 4,361,000 4,839,000 1,811,000 Interest...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT