< previous page page_586 next page >

Page 586
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
enum Perfumes {POISON, DIOR_ESSENCE, CHANEL_NO_5, COTY};
Perfumes sample;

indicate whether each statement below is valid or invalid.
a. sample = POISON;
b. sample = 3;
c. sample++;
d. sample = Perfumes (sample +1);
10. Using the declarations
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
enum SeasonType {WINTER, SPRING, SUMMER, FALL};
SeasonType season;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
indicate whether each statement below is valid or invalid.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. cin >> season;
b. if (season >= SPRING)
       .
       .
       .
c. for (season = WINTER; season <= SUMMER; season =
                                        SeasonType(season + 1))
       .
       .
       .
11. Consider the following program fragment:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
enum Colors {RED, GREEN, BLUE};

Colors myColor;
enum {RED, GREEN, BLUE} yourColor;

yourColor = GREEN;
myColor = yourColor;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. The data type of myColor is a named type, and the data type of yourColor is an anonymous type. (True or False?)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. The last assignment statement is valid because both enumeration types have the same domain. (True or False?)
12. If you have written your own header file named mytypes.h, then the preprocessor directive
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
#include <mytypes.h>
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
is the correct way to insert the contents of the header file into a program. (True or False?)
13. In each of the following situations, indicate whether promotion or demotion occurs. (The names of the variables are meant to suggest their data types.)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Execution of the assignment operation someInt = someFloat
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Evaluation of the expression someFloat + someLong
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. Passing the actual parameter someDouble to the formal parameter someFloat
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. Execution of the statement

 
< previous page page_586 next page >