Assignment #3
Pencil & paper
From the Text, Exercises 3.1, 3.7, 3.8,
3.11, 3.16.
Additional exercises. Select most correct answer in each case.
You need only write the letter for the correct answer, e.g., 3 (d) Hint:
(d) may not be the correct answer for problem 3 below!
-
The semicolon is used (a) to mark the end of a line in C and C++, (b) to
mark the end of a statement in C and C++, (c) only to mark the end of a
statement in C and C++, (d) between the increment and initialize portions
in the for-loop, (e) None of the previous.
-
A variable declared in the main function is (a) accessible in all functions,
(b) is accessible in all functions called from main, (c) is accessible
only in main, (d) is always static unless otherwise declared, (e) cannot
be declared as a static variable.
-
Regarding for- and while-loops (a) the while-loop is preferred when you
don’t know how many time the loop will be executed, (b) the for-loop is
preferred when you don’t know how many time the loop will be executed,
(c) both constructs are essential in any programming language, as there
are certain kinds of looping needs that cannot be met with the while-loop
by itself, (d) the loop control variable in a for-loop cannot be altered
in the body of the loop. (e) both constructs must always complete by criteria
set forth in the header statement of the construct because there is no
other legal way of exiting.
-
In the statements enum weatherType{CLOUDY, RAIN, SHINE}; weatherType
TodayWeather; (a) weatherType is of type int and therefore
can be assigned a value of 1 (b) CLOUDY, RAIN, SHINE are enumerated
as 1, 2, and 3 respectively (c) an error has been made (d) a weatherType
can be used as a loop control variable in a for-loop (e) TodayWeather
can be assigned a value of RAIN.
Programming:
A. Do exercise 3.30 from the text.
B. Do exercise 3.56 from the text.