|
|
 |
|
|
|
|
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 |
|
|
|
 |
|
|
|
|
enum SeasonType {WINTER, SPRING, SUMMER, FALL};
SeasonType season; |
|
|
|
 |
|
|
|
|
indicate whether each statement below is valid or invalid. |
|
|
|
 |
|
|
|
|
a. cin >> season;
b. if (season >= SPRING)
.
.
.
c. for (season = WINTER; season <= SUMMER; season =
SeasonType(season + 1))
.
.
. |
|
|
|
|
|
|
|
|
11. Consider the following program fragment: |
|
|
|
 |
|
|
|
|
enum Colors {RED, GREEN, BLUE};
Colors myColor;
enum {RED, GREEN, BLUE} yourColor;
yourColor = GREEN;
myColor = yourColor; |
|
|
|
 |
|
|
|
|
a. The data type of myColor is a named type, and the data type of yourColor is an anonymous type. (True or False?) |
|
|
|
 |
|
|
|
|
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 |
|
|
|
 |
|
|
|
|
#include <mytypes.h> |
|
|
|
 |
|
|
|
|
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.) |
|
|
|
 |
|
|
|
|
a. Execution of the assignment operation someInt = someFloat |
|
|
|
 |
|
|
|
|
b. Evaluation of the expression someFloat + someLong |
|
|
|
 |
|
|
|
|
c. Passing the actual parameter someDouble to the formal parameter someFloat |
|
|
|
 |
|
|
|
|
d. Execution of the statement |
|
|
|
|
|