### Chapter Review

1. Why does C++ have more than one integer type?2. Declare variables matching the following descriptions:

a. A short integer with the value 80

b. An unsigned int integer with the value 42,110

c. An integer with the value 3,000,000,000

3. What safeguards does C++ provide to keep you from exceeding the limits of an integer type?

4. What is the distinction between 33L and 33?

5. Consider the two C++ statements that follow:

char grade = 65;

char grade = 'A';

Are they equivalent?

6. How could you use C++ to find out which character the code 88 represents?Come up with at least two ways.

7. Assigning a long value to a float can result in a rounding error.What about assigning long to double? long long to double?

8. Evaluate the following expressions as C++ would:

a. 8 * 9 + 2

b. 6 * 3 / 4

c. 3 / 4 * 6

d. 6.0 * 3 / 4

e. 15 % 4

9. Suppose x1 and x2 are two type double variables that you want to add as integers and assign to an integer variable. Construct a C++ statement for doing so.What if you want to add them as type double and then convert to int?

10. What is the variable type for each of the following declarations?

a. auto cars = 15;

b. auto iou = 150.37f;

c. auto level = 'B';

d. auto crat = U'/U00002155';

e. auto fract = 8.25f/2.5;

### Programming Exercises

1. Write a short program that asks for your height in integer inches and then converts your height to feet and inches. Have the program use the underscore character to indicate where to type the response. Also use a const symbolic constant to represent the conversion factor.2. Write a short program that asks for your height in feet and inches and your weight in pounds. (Use three variables to store the information.) Have the program report your body mass index (BMI). To calculate the BMI, first convert your height in feet and inches to your height in inches (1 foot = 12 inches).Then convert your height in inches to your height in meters by multiplying by 0.0254.Then convert your weight in pounds into your mass in kilograms by dividing by 2.2. Finally, compute

your BMI by dividing your mass in kilograms by the square of your height in meters. Use symbolic constants to represent the various conversion factors.

3. Write a program that asks the user to enter a latitude in degrees, minutes, and seconds

and that then displays the latitude in decimal format.There are 60 seconds of arc to a minute and 60 minutes of arc to a degree; represent these values with symbolic constants.You should use a separate variable for each input value.

A sample

run should look like this:

Enter a latitude in degrees, minutes, and seconds:

First, enter the degrees: 37

Next, enter the minutes of arc: 51

Finally, enter the seconds of arc: 19

37 degrees, 51 minutes, 19 seconds = 37.8553 degrees

4. Write a program that asks the user to enter the number of seconds as an integer value (use type long, or, if available, long long) and that then displays the equivalent time in days, hours, minutes, and seconds. Use symbolic constants to represent the number of hours in the day, the number of minutes in an hour, and the number of seconds in a minute.The output should look like this:

Enter the number of seconds: 31600000

31600000 seconds = 365 days, 17 hours, 46 minutes, 40 seconds

5. Write a program that requests the user to enter the current world population and the current population of the U.S. (or of some other nation of your choice). Store the information in variables of type long long. Have the program display the percent that the U.S. (or other nation’s) population is of the world’s population.The output should look something like this:

Enter the world's population: 6898758899

Enter the population of the US: 310783781

The population of the US is 4.50492% of the world population.

Yo u c a n u s e t h e I n t e r n e t t o g e t mo r e r e c e n t f i g u r e s .