< previous page page_584 next page >

Page 584
4. Why is it inappropriate to use a variable of a floating point type as a loop control variable? (pp. 526533)
5. If a computer has four digits of precision, what would be the result of the following addition operation? (pp. 526533)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
400400.000+199.9
6. When choosing a data type for a variable that stores whole numbers only, why should int be your first choice? (p. 533)
7. Declare an enumeration type named AutoMakes, consisting of the names of five of your favorite car manufacturers. (pp. 536544)
8. Given the type declaration
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
enum VisibleColors
{
    RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET
};
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
write the first line of a For statement that counts from RED through VIOLET. Use a loop control variable named rainbow that is of type VisibleColors. (pp.536544)
9. Why is it better to use a named type than an anonymous type? (pp. 544545)
10. Suppose that many of your programs need an enumeration type named Days and another named Months. If you place the type declarations into a file named calendar.h, what would an #include directive look like that inserts these declarations into a program? (pp. 545547)
11. In arithmetic and relational expressions, which of the following could occur:
type promotion, type demotion, or both? (pp. 547551)f:
Answers 1. The integral types are char, short, int, long, and enum. The floating point types are float, double, and long double. 2. An expression becomes an expression statement when it is terminated by a semicolon. 3. The external representation is the letter X; the internal representation is the integer 88. 4. Because representational errors can cause the loop termination condition to be evaluated with unpredictable results. 5. 400500.000 (Actually, 4.005E+5)
6. Floating point arithmetic is subject to numerical inaccuracies and is slower than integer arithmetic on most machines. Use of the smaller integral types, char and short, can more easily lead to overflow errors. The long type usually requires more memory than int, and the arithmetic is usually slower.
7. enum AutoMakes {SAAB, JAGUAR, CITROEN, CHEVROLET, FORD};
8. for (rainbow = RED; rainbow 
 VIOLET; rainbow = VisibleColors (rainbow +1))
9. Named types make a program more readable, more understandable, and easier to modify. Also, a variable of an anonymous enumeration type cannot be assigned to a variable of a named enumeration type, even if the domains of the types are the same. 10. #include calendar.h 11. Type promotion
Exam Preparation Exercises
1. Every C++ compiler guarantees that sizeof(int) < sizeof(long). (True or False?)
2. Classify each of the following as either an expression or an expression statement.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. sum = 0
b. sqrt(x)

 
< previous page page_584 next page >