Ch.3 Flashcards
Which boolean operation is described by the following table?
A B Operation
True True True
True False True
False True True
False False False
or
Which of the following data types may be used in a switch statement?
A) long
B) char
C) enum
D) int
E) all of the above
all of the above
What is the value of the following expression?
(true && (4/3 || !(6)))
true
When testing a program with a loop, which of the following tests should be done?
A) one less than the maximum number of iterations
B) no iterations of the loops
C) the maximum number of iterations
D) one more than the maximum number of iterations
E) A, B, and C
one less than the maximum number of iterations
no iterations of the loops
the maximum number of iterations
Which of the following is not a good reason for choosing a certain loop control?
A) What the loop does
B) If the loop is in a function
C) The condition for ending the loop
D) The minimum number of iterations of the loop
If the loop is in a function
Which of the following data types can be used in a switch controlling expression?
A) char
B) enum
C) float
D) int
E) A, B, and D
char
enum
int
Which boolean operation is described by the following table?
A B Operation
True True True
True False False
False True False
False False False
and
Given the following enumerated data type definition, what is the value of SAT?
enum myType{SUN=3,MON=1,TUE=3,WED,THUR,FRI,SAT,NumDays};
7
What is the output of the following code fragment?
int i = 5;
switch(i)
{
case 0:i = 15;break;
case 1:i = 25;break;
case 2:i = 35;break;
case 3:i = 40;
default:i = 0;
}
0
If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test?
(x >= 10 || y <= 3)
Given the following enumerated data type definition, what is the value of SAT?
enum myType{SUN,MON,TUE,WED,THUR,FRI,SAT,NumDays};
6
What is the value of x after the following code executes?
int x = 10;
if( ++ x > 10)
{
x = 13;
}
13
What is the value of x after the following code executes?
int x = 10;
if(x ++ > 10)
{
x = 13;
}
11
Which of the following are equivalent to (!(x < 15 && y >= 3))?
(x >= 15 || y < 3)
If you need to write a do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the user enters a correct number, what is the loop condition?
(2 > number || number > 5)
If a programming language does not use short-circuit evaluation, what is the output of the following code fragment if the value of myInt is 0?
int other = 3, myInt;
if(myInt != 0 && other % myInt != 0)
cout ≤≤ “other is odd\n”;
else
cout << “other is even\n”;
run-time error, no output
What is wrong with the following for loop?
for(int i = 0;i < 10;i – )
{
cout << “Hello\n”;
}
infinite loop
Which of the following are allowed in the third section of the for loop statement?
A) i ++
B) cout << “Hello\n”
C) i –
D) i += 2
E) all of the above
all of the above
What is the output of the following code fragment?
int x = 0;
{
int x = 13;
cout ≤≤ x ≤≤ “,”;
}
cout ≤≤ x ≤≤ endl;
13,0
Which of the following symbols has the highest precedence?
++
A ________ expression is an expression that can be thought of as being true or false.
boolean
A loop that iterates one too many or one too few times is said to be
off-by-one
is a type whose values are defined by a list of constants of type int
enum
Variables defined inside a set of braces are said to be ________ to that block of code
local
A switch statement variable must be
an int char enum
Each repetition of a loop body is called
iteration
The compiler always pairs an else with
e nearest unpaired if
In a compound logical and (&&) expression, the evaluation of the expression stops once one of the terms of the expression is false. This is known as ________ evaluation
short circuit
A semicolon by itself is a valid C++ statement
True
A break statement in a switch stops your program
False
The break statement causes all loops to exit
False
All switch statements can be converted into nested if-else statements
True
A function may return a boolean value
True