Question 1
pts
(TCO 4) What is the result of 57 % 8?
Correct Answer
1
7
You Answered
7.125
The equation 57/8.0 would give us this answer, because it asks for the result of the floating point
division.
8
The % symbol indicates a modulo operation. The modulo operator is used to find the remainder
in an integer division. For example, 10 divided by 3 results in the integer 3 with a remainder of 1,
so 10 % 3 would be 1. See Malik, pages 30–44.
Question 2
pts
(TCO 4) Which file must be #include to use cout?
Correct!
iostream
The iostream header is used to access functions to perform input and output operations.
iomanip
isprint
cmath
Many of the functions and symbols used in a C++ program are provided in libraries. In order to
use these functions and/or symbols, the program must specify the appropriate library. This is
accomplished with a preprocessor directive. All preprocessor directives begin with the symbol #.
, The cout command is contained in the library accessed with the header iostream. See Malik,
pages 75–76.
Question 3
pts
(TCO 4) Which statement correctly tests int variable var to be less than 0 or more than 50?
if(var < 0 && var > 50)
if(var <= 0 || var >= 50)
if(var < 0 else var > 50)
Correct!
if(var < 0 || var > 50)
This is correct. The expression uses the logical OR ‘||’ operator to connect the correct relative
expressions that test for var less than 0 or var greater than 50.
This requires that we write an expression that tests to see if the variable var meets one of two
different conditions. We need to use the less than operator to test for var < 0, and we need to use
the greater than operator to test for var > 50. The logical OR operator can be used to specify that
only one of these conditions needs to be true. See Malik, pages 39–44.
Question 4
pts
(TCO 4) How many times does the following loop execute?
unsigned int count = 365;
for(int i = 0; i <= 100; i+=2)
cout << count - i;
Indefinite; it is an infinite loop.
365
Correct Answer
51