Deck 4: Control Structures I Selection

Full screen (f)
exit full mode
Question
Which of the following expressions correctly determines that x is greater than 10 and less than 20?

A) 10 < x < 20
B) (10 < x < 20)
C) 10 < x && x < 20
D) 10 < x || x < 20
Use Space or
up arrow
down arrow
to flip the card.
Question
In C++, both ! and != are relational operators.
Question
Suppose that x is an int variable. Which of the following expressions always evaluates to true?

A) (x > 0) || ( x <= 0)
B) (x >= 0) || (x == 0)
C) (x > 0) && ( x <= 0)
D) (x > 0) && (x == 0)
Question
Which of the following operators has the highest precedence?

A) !
B) *
C) %
D) =
Question
The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable.
Question
The operators !, &&, and || are called relational operators.
Question
Which of the following is a relational operator?

A) =
B) ==
C) !
D) &&
Question
Which of the following is the "not equal to" relational operator?

A) !
B) |
C) !=
D) &
Question
In C++, the operators != and == have the same order of precedence.
Question
A control structure alters the normal sequential flow of execution in a program.
Question
What does <= mean?

A) less than
B) greater than
C) less than or equal to
D) greater than or equal to
Question
The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100.
Question
Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y)

A) false
B) true
C) 0
D) null
Question
In a ____ control structure, the computer executes particular statements depending on some condition(s).

A) looping
B) repetition
C) selection
D) sequence
Question
If the expression in an assert statement evaluates to true, the program terminates.
Question
Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true.
Question
A compound statement functions as if it was a single statement.
Question
In C++, && has a higher precedence than ||.
Question
You can use either a(n) ____ or a ____ to store the value of a logical expression.

A) float, double
B) char, string
C) int, bool
D) float, string
Question
Which of the following operators has the lowest precedence?

A) !
B) ||
C) &&
D) =
Question
For a program to use the assert function, it must include which of the following?

A) #include
B) #include
C) #include
D) #include NDEBUG
Question
The term ____________________ describes a process in which the computer evaluates a logical expression from left to right and stops as soon as the value of the expression is known.
Question
What is the value of x after the following statements execute? int x;
X = (5 <= 3 && 'A' < 'F') ? 3 : 4

A) 2
B) 3
C) 4
D) 5
Question
Which of the following will cause a logical error if you are attempting to compare x to 5?

A) if (x == 5)
B) if (x = 5)
C) if (x <= 5)
D) if (x >= 5)
Question
Putting a semicolon after the parentheses following the expression in an if statement (that is, before the statement) is a(n) ____________________ error.
Question
Once an input stream enters a(n) ____________________ state, all subsequent input statements associated with that input stream are ignored, and the computer continues to execute the program, which produces erroneous results.
Question
The value of the expression 7 + 8 <= 15 is ____________________.
Question
What is the output of the following C++ code? int x = 35;
Int y = 45;
Int z;
If (x > y)
Z = x + y;
Else
Z = y - x;
Cout << x << " " << y << " " << z << endl;

A) 35 45 80
B) 35 45 10
C) 35 45 -10
D) 35 45 0
Question
Consider the following statements.
int score;
string grade;
if (score >= 65)
grade = "pass";
else
grade = "fail";
If score is equal to 75, the value of grade is "____________________".
Question
When one control statement is located within another, it is said to be ____.

A) blocked
B) compound
C) nested
D) closed
Question
Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;.

A) 2
B) 3
C) 4
D) 6
Question
The ____________________ of relational and logical operators is said to be from left to right.
Question
What is the output of the following C++ code? <strong>What is the output of the following C++ code?  </strong> A) 2 B) 5 C) 8 D) 10 <div style=padding-top: 35px>

A) 2
B) 5
C) 8
D) 10
Question
You can disable assert statements by using which of the following?

A) #include
B) #define
C) #clear NDEBUG
D) #define NDEBUG
Question
Which of the following will cause a logical error if you are attempting to compare x to 5?

A) if (x == 5)
B) if (x = 5)
C) if (x <= 5)
D) if (x >= 5)
Question
What is the output of the following code? char lastInitial = 'S';
Switch (lastInitial)
{
Case 'A':
Cout << "section 1" <Break;
Case 'B':
Cout << "section 2" <Break;
Case 'C':
Cout << "section 3" <Break;
Case 'D':
Cout << "section 4" <Break;
Default:
Cout << "section 5" <}

A) section 2
B) section 3
C) section 4
D) section 5
Question
Suppose found = true and num = 6. The value of the expression (!found) || (num > 6) is ____________________.
Question
In a switch statement, if the value of the expression does not match any of the case values, the statements following the ____________________ label execute.
Question
The value of the expression 6 < 5 || 'g' > 'a' && 7 < 4
is ____________________.
Question
Putting ____________________ in front of a logical expression reverses the value of that logical expression.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: Control Structures I Selection
1
Which of the following expressions correctly determines that x is greater than 10 and less than 20?

A) 10 < x < 20
B) (10 < x < 20)
C) 10 < x && x < 20
D) 10 < x || x < 20
C
2
In C++, both ! and != are relational operators.
False
3
Suppose that x is an int variable. Which of the following expressions always evaluates to true?

A) (x > 0) || ( x <= 0)
B) (x >= 0) || (x == 0)
C) (x > 0) && ( x <= 0)
D) (x > 0) && (x == 0)
A
4
Which of the following operators has the highest precedence?

A) !
B) *
C) %
D) =
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
The operators !, &&, and || are called relational operators.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following is a relational operator?

A) =
B) ==
C) !
D) &&
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following is the "not equal to" relational operator?

A) !
B) |
C) !=
D) &
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
In C++, the operators != and == have the same order of precedence.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
A control structure alters the normal sequential flow of execution in a program.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
What does <= mean?

A) less than
B) greater than
C) less than or equal to
D) greater than or equal to
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y)

A) false
B) true
C) 0
D) null
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
In a ____ control structure, the computer executes particular statements depending on some condition(s).

A) looping
B) repetition
C) selection
D) sequence
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
If the expression in an assert statement evaluates to true, the program terminates.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
A compound statement functions as if it was a single statement.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
In C++, && has a higher precedence than ||.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
You can use either a(n) ____ or a ____ to store the value of a logical expression.

A) float, double
B) char, string
C) int, bool
D) float, string
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following operators has the lowest precedence?

A) !
B) ||
C) &&
D) =
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
For a program to use the assert function, it must include which of the following?

A) #include
B) #include
C) #include
D) #include NDEBUG
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
The term ____________________ describes a process in which the computer evaluates a logical expression from left to right and stops as soon as the value of the expression is known.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
What is the value of x after the following statements execute? int x;
X = (5 <= 3 && 'A' < 'F') ? 3 : 4

A) 2
B) 3
C) 4
D) 5
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following will cause a logical error if you are attempting to compare x to 5?

A) if (x == 5)
B) if (x = 5)
C) if (x <= 5)
D) if (x >= 5)
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
Putting a semicolon after the parentheses following the expression in an if statement (that is, before the statement) is a(n) ____________________ error.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
Once an input stream enters a(n) ____________________ state, all subsequent input statements associated with that input stream are ignored, and the computer continues to execute the program, which produces erroneous results.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
The value of the expression 7 + 8 <= 15 is ____________________.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
What is the output of the following C++ code? int x = 35;
Int y = 45;
Int z;
If (x > y)
Z = x + y;
Else
Z = y - x;
Cout << x << " " << y << " " << z << endl;

A) 35 45 80
B) 35 45 10
C) 35 45 -10
D) 35 45 0
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
Consider the following statements.
int score;
string grade;
if (score >= 65)
grade = "pass";
else
grade = "fail";
If score is equal to 75, the value of grade is "____________________".
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
When one control statement is located within another, it is said to be ____.

A) blocked
B) compound
C) nested
D) closed
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;.

A) 2
B) 3
C) 4
D) 6
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
The ____________________ of relational and logical operators is said to be from left to right.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
What is the output of the following C++ code? <strong>What is the output of the following C++ code?  </strong> A) 2 B) 5 C) 8 D) 10

A) 2
B) 5
C) 8
D) 10
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
You can disable assert statements by using which of the following?

A) #include
B) #define
C) #clear NDEBUG
D) #define NDEBUG
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following will cause a logical error if you are attempting to compare x to 5?

A) if (x == 5)
B) if (x = 5)
C) if (x <= 5)
D) if (x >= 5)
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
What is the output of the following code? char lastInitial = 'S';
Switch (lastInitial)
{
Case 'A':
Cout << "section 1" <Break;
Case 'B':
Cout << "section 2" <Break;
Case 'C':
Cout << "section 3" <Break;
Case 'D':
Cout << "section 4" <Break;
Default:
Cout << "section 5" <}

A) section 2
B) section 3
C) section 4
D) section 5
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
Suppose found = true and num = 6. The value of the expression (!found) || (num > 6) is ____________________.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
In a switch statement, if the value of the expression does not match any of the case values, the statements following the ____________________ label execute.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
The value of the expression 6 < 5 || 'g' > 'a' && 7 < 4
is ____________________.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
Putting ____________________ in front of a logical expression reverses the value of that logical expression.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 40 flashcards in this deck.