Deck 4: Making Decisions

Full screen (f)
exit full mode
Question
As a rule of style, when writing an if statement you should indent the conditionally-executed statements.
Use Space or
up arrow
down arrow
to flip the card.
Question
If the expression on the left side of the following is true, the expression on the right side will not be checked.
(a > = b) || (c == d)
Question
Whereas < is called a relational operator, x < y is called a(n)

A) arithmetic operator
B) relative operator
C) relational expression
D) arithmetic expression
E) None of these
Question
The following code correctly determines whether x contains a value in the range of 0 through 100, inclusive.
if (x > 0 && <= 100)
Question
Relational operators allow you to __________ numbers.

A) add
B) multiply
C) compare
D) average
E) None of these
Question
The value of result in the following expression will be 0 if x has the value of 12.
result = x > 100 ?
0 :
1;
Question
What is assigned to the variable result given the statement below with the following assumptions:
X = 10, y = 7, and x, result, and y are all int variables.
Result = x >= y;

A) 10
B) 7
C) x >= y
D) 1
E) 0
Question
After the following code executes, what is the output if user enters 0?
Int x = -1;
Cout << "Enter a 0 or 1:
";
Cin >> x;
If (c)
Cout << "true" << endl;
Else
Cout << "False" << endl;

A) nothing will be displayed
B) False
C) x
D) true
E) 0
Question
You should be careful when using the equality operator to compare floating point values because of potential round-off errors.
Question
Both of the following if statements perform the same operation.
Question
When a relational expression is False, it has the value

A) 1
B) 0
C) 0, 1, or -1
D) -1
E) None of these
Question
An expression that has any value other than 0 is considered true by an if statement.
Question
The __________ is an equality (or comparison) operator.

A) ==
B) >=
C) !=
D) =
E) None of these
Question
The default section is required in a switch statement.
Question
The conditional operator takes two operands.
Question
What is the output of the following code segment if the user enters 90 for the score?
Cout << "Enter your test score:
";
Cin >> test_score;
If (test_score < 60)
Cout << "You failed the test." << endl;
If (test_score > 60)
Cout << "You passed the test."
Else
Cout << "You need to study harder next time." << endl;

A) You failed the test.
B) You passed the test.
C) You need to study harder next time.
D) You failed the test.
You need to study harder next time.
E) You passed the test.
You need to study harder next time.
Question
If the expression on the left side of the following is False, the expression on the right side will not be checked.
(a > = b) && (c == d)
Question
After the following code executes, what is the value of my_value if the user enters 0?
Cin >> my_value;
If (my_value > 5)
My_value = my_value + 5;
Else if (my_value > 2)
My_value = my_value + 10;
Else
My_value = my_value + 15;

A) 15
B) 10
C) 25
D) 0
E) 5
Question
If you place a semicolon after the statement:
If (x < y)

A) the code will not compile
B) the compiler will interpret the semicolon as a null statement
C) the if statement will always evaluate to False
D) All of these are true
E) None of these
Question
What is the output of the following code segment?
Int x = 5;
If (x = 2)
Cout << "This is true!" << endl;
Else
Cout << "This is False!" << endl;
Cout << "That's all, folks!" << endl;

A) This is true!
B) This is False!
C) This is False!
That's all, folks
D) This is true!
That's all folks
E) This is true!
This is False!
That's all, folks!
Question
What is the output of the following code?
Int w = 98;
Int x = 99;
Int y = 0;
Int z = 1;
If (x >= 99)
{
If (x < 99)
Cout << y << endl;
Else
Cout << z << endl;
}
Else
{
If (x == 99)
Cout << x << endl;
Else
Cout << w << endl;
}

A) 98
B) 99
C) 0
D) 1
E) None of these
Question
Which of the following is evaluated first, given the expression:
A && B || C && !D

A) A && B
B) B || C
C) C && !D
D) !D
Question
What will be displayed after the following statements execute?
Int funny = 7, serious = 15;
Funny = serious % 2;
If (funny != 1)
{
Funny = 0;
Serious = 0;
}
Else if (funny == 2)
{
Funny = 10;
Serious = 10;
}
Else
{
Funny = 1;
Serious = 1;
}
Cout << funny << " " << serious << endl;

A) 7 15
B) 0 0
C) 10 10
D) 1 1
E) None of these
Question
What is the value of the following expression?
True && False

A) true
B) False
C) -1
D) +1
E) None of these
Question
A variable, usually a bool or an int, that signals when a condition exists is known as a(n)

A) relational operator
B) arithmetic operator
C) logical operator
D) flag
E) None of these
Question
What is the output of the following code segment if the user enters 23?
Int number;
Cout << "Enter a number:
";
Cin >> number;
If (number > 0)
Cout << "Hi, there!" << endl;
Else
Cout << "Good-bye." << endl;

A) Hi, there! Good-bye.
B) Hi, there!
C) Good-bye.
D) "Hi, there!"
E) nothing will output
Question
These operators connect two or more relational expressions into one, or reverse the logic of an expression.

A) relational
B) logical
C) irrational
D) negation
E) None of these
Question
If you intend to place a block of statements within an if statement, you must place __________ around the block:

A) parentheses ( )
B) square brackets [ ]
C) angle brackets < >
D) curly braces { }
E) None of these
Question
What is the value of donuts after the following statement executes?
Int donuts = 10;
If (donuts != 10)
Donuts = 0;
Else
Donuts += 2;

A) 12
B) 10
C) 0
D) 1
E) None of these
Question
Which value can be entered to cause the following code segment to display the message "That number is acceptable"?
Int number;
Cin >> number;
If (number > 10 && number < 100)
Cout << "That number is acceptable.\n";
Else
Cout << "That number is not acceptable.\n";

A) 100
B) 10
C) 99
D) 0
E) all of these
Question
What is the value of the following expression?
True && !False

A) true
B) False
C) -1
D) +1
E) None of these
Question
When an if statement is placed within the conditionally-executed code of another if statement, this is known as

A) complexity
B) overloading
C) nesting
D) validation
E) None of these
Question
This operator represents the logical OR:

A) --
B) ||
C) &&
D) #
E) None of these
Question
This operator represents the logical AND:

A) ++
B) ||
C) &&
D) @
E) None of these
Question
What is the value of the following expression?
True && true

A) true
B) False
C) -1
D) +1
E) None of these
Question
This operator takes an operand and reverses its truth or Falsehood:

A) !&
B) ||
C) =!
D) !
E) None of these
Question
What is the value of result after the following code executes?
Int a = 60;
Int b = 15;
Int result = 10;
If (a = b)
Result *= 2;

A) 10
B) 120
C) 20
D) 12
E) code will not execute
Question
What is the value of the following expression?
True || False

A) true
B) False
C) -1
D) +1
E) None of these
Question
What is the value of donuts after the following statement executes?
Int donuts = 10;
If (donuts = 1)
Donuts = 0;
Else
Donuts += 2;

A) 12
B) 10
C) 0
D) 1
E) None of these
Question
Which of the following expressions will determine whether x is less than or equal to y?

A) x > y
B) x =< y
C) x >= y
D) x <= y
E) x == y and x < y
Question
What is the output of the following segment of code if the value 4 is input by the user?
Int num;
Int total = 0;
Cout << "Enter a number from 1 to 10:
";
Cin >> num;
Switch (num)
{
Case 1:
Case 2:
Total = 5;
Case 3:
Total = 10;
Case 4:
Total = total + 3;
Case 8:
Total = total + 6;
Default:
Total = total + 4;
}
Cout << total << endl;

A) 0
B) 3
C) 13
D) 23
E) None of these
Question
When a program lets the user know that an invalid choice has been made, this is known as:

A) input validation
B) output correction
C) compiler criticism
D) output validation
E) None of these
Question
This statement uses the value of a variable or expression to determine where the program will branch to.

A) switch
B) select
C) association
D) scope
E) None of these
Question
The default section of a switch statement performs a similar task similar to the __________ portion of an if/else if statement.

A) conditional
B) break
C) trailing else
D) All of these
E) None of these
Question
Given the if/else statement:
If (a < 5)
B = 12;
Else
D = 30;
Which of the following performs the same operation?

A) a < 5 ? b = 12 : d = 30;
B) b < 5 ? b = 12 : d = 30;
C) a >= 5 ? d = 30 : b = 12;
D) d = 30 ? b = 12 : a = 5;
E) None of these
Question
Input values should always be checked for

A) an appropriate range
B) reasonableness
C) division by zero, if division is taking place
D) All of these
E) None of these
Question
Which line in the following program will cause a compiler error?
1 #include
2 using namespace std;
3 int main()
4 {
5 int number = 5;
6 if (number >= 0 && <= 100)
7 cout << "passed.\n";
8 else
9 cout << "failed.\n";
10 return 0;
11 }

A) line 3
B) line 6
C) line 7
D) line 9
E) None will cause an error
Question
Given the following code segment, what is the output?
Int x = 1, y = 1, z = 1;
Y = y + z;
X = x + y;
Cout << "result = " << (x < y ?
Y :
X) << endl;

A) result = 0
B) result = 1
C) result = 2
D) result = 3
E) there will be no output
Question
Which statement allows you to properly check the char variable code to determine whether it is equal to a C and then output This is a check?

A) if code is equal to C
Cout << "This is a check\n";
B) if (code = "C")
Cout << "This is a check\n";
C) if (code == 'C')
Cout << "This is a check\n";
D) if (code == C)
Cout << "This is a check" << endl;
Question
Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.

A) break
B) exit
C) switch
D) scope
E) None of these
Question
Given that x = 2, y = 1, z = 0, what will the following cout statement display?
Cout << "answer = " << (x || !y && z) << endl;

A) answer = 0
B) answer = 1
C) answer = 2
D) None of these
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/51
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: Making Decisions
1
As a rule of style, when writing an if statement you should indent the conditionally-executed statements.
True
2
If the expression on the left side of the following is true, the expression on the right side will not be checked.
(a > = b) || (c == d)
True
3
Whereas < is called a relational operator, x < y is called a(n)

A) arithmetic operator
B) relative operator
C) relational expression
D) arithmetic expression
E) None of these
C
4
The following code correctly determines whether x contains a value in the range of 0 through 100, inclusive.
if (x > 0 && <= 100)
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
5
Relational operators allow you to __________ numbers.

A) add
B) multiply
C) compare
D) average
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
6
The value of result in the following expression will be 0 if x has the value of 12.
result = x > 100 ?
0 :
1;
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
7
What is assigned to the variable result given the statement below with the following assumptions:
X = 10, y = 7, and x, result, and y are all int variables.
Result = x >= y;

A) 10
B) 7
C) x >= y
D) 1
E) 0
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
8
After the following code executes, what is the output if user enters 0?
Int x = -1;
Cout << "Enter a 0 or 1:
";
Cin >> x;
If (c)
Cout << "true" << endl;
Else
Cout << "False" << endl;

A) nothing will be displayed
B) False
C) x
D) true
E) 0
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
9
You should be careful when using the equality operator to compare floating point values because of potential round-off errors.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
10
Both of the following if statements perform the same operation.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
11
When a relational expression is False, it has the value

A) 1
B) 0
C) 0, 1, or -1
D) -1
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
12
An expression that has any value other than 0 is considered true by an if statement.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
13
The __________ is an equality (or comparison) operator.

A) ==
B) >=
C) !=
D) =
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
14
The default section is required in a switch statement.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
15
The conditional operator takes two operands.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
16
What is the output of the following code segment if the user enters 90 for the score?
Cout << "Enter your test score:
";
Cin >> test_score;
If (test_score < 60)
Cout << "You failed the test." << endl;
If (test_score > 60)
Cout << "You passed the test."
Else
Cout << "You need to study harder next time." << endl;

A) You failed the test.
B) You passed the test.
C) You need to study harder next time.
D) You failed the test.
You need to study harder next time.
E) You passed the test.
You need to study harder next time.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
17
If the expression on the left side of the following is False, the expression on the right side will not be checked.
(a > = b) && (c == d)
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
18
After the following code executes, what is the value of my_value if the user enters 0?
Cin >> my_value;
If (my_value > 5)
My_value = my_value + 5;
Else if (my_value > 2)
My_value = my_value + 10;
Else
My_value = my_value + 15;

A) 15
B) 10
C) 25
D) 0
E) 5
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
19
If you place a semicolon after the statement:
If (x < y)

A) the code will not compile
B) the compiler will interpret the semicolon as a null statement
C) the if statement will always evaluate to False
D) All of these are true
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
20
What is the output of the following code segment?
Int x = 5;
If (x = 2)
Cout << "This is true!" << endl;
Else
Cout << "This is False!" << endl;
Cout << "That's all, folks!" << endl;

A) This is true!
B) This is False!
C) This is False!
That's all, folks
D) This is true!
That's all folks
E) This is true!
This is False!
That's all, folks!
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
21
What is the output of the following code?
Int w = 98;
Int x = 99;
Int y = 0;
Int z = 1;
If (x >= 99)
{
If (x < 99)
Cout << y << endl;
Else
Cout << z << endl;
}
Else
{
If (x == 99)
Cout << x << endl;
Else
Cout << w << endl;
}

A) 98
B) 99
C) 0
D) 1
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following is evaluated first, given the expression:
A && B || C && !D

A) A && B
B) B || C
C) C && !D
D) !D
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
23
What will be displayed after the following statements execute?
Int funny = 7, serious = 15;
Funny = serious % 2;
If (funny != 1)
{
Funny = 0;
Serious = 0;
}
Else if (funny == 2)
{
Funny = 10;
Serious = 10;
}
Else
{
Funny = 1;
Serious = 1;
}
Cout << funny << " " << serious << endl;

A) 7 15
B) 0 0
C) 10 10
D) 1 1
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
24
What is the value of the following expression?
True && False

A) true
B) False
C) -1
D) +1
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
25
A variable, usually a bool or an int, that signals when a condition exists is known as a(n)

A) relational operator
B) arithmetic operator
C) logical operator
D) flag
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
26
What is the output of the following code segment if the user enters 23?
Int number;
Cout << "Enter a number:
";
Cin >> number;
If (number > 0)
Cout << "Hi, there!" << endl;
Else
Cout << "Good-bye." << endl;

A) Hi, there! Good-bye.
B) Hi, there!
C) Good-bye.
D) "Hi, there!"
E) nothing will output
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
27
These operators connect two or more relational expressions into one, or reverse the logic of an expression.

A) relational
B) logical
C) irrational
D) negation
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
28
If you intend to place a block of statements within an if statement, you must place __________ around the block:

A) parentheses ( )
B) square brackets [ ]
C) angle brackets < >
D) curly braces { }
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
29
What is the value of donuts after the following statement executes?
Int donuts = 10;
If (donuts != 10)
Donuts = 0;
Else
Donuts += 2;

A) 12
B) 10
C) 0
D) 1
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
30
Which value can be entered to cause the following code segment to display the message "That number is acceptable"?
Int number;
Cin >> number;
If (number > 10 && number < 100)
Cout << "That number is acceptable.\n";
Else
Cout << "That number is not acceptable.\n";

A) 100
B) 10
C) 99
D) 0
E) all of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
31
What is the value of the following expression?
True && !False

A) true
B) False
C) -1
D) +1
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
32
When an if statement is placed within the conditionally-executed code of another if statement, this is known as

A) complexity
B) overloading
C) nesting
D) validation
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
33
This operator represents the logical OR:

A) --
B) ||
C) &&
D) #
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
34
This operator represents the logical AND:

A) ++
B) ||
C) &&
D) @
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
35
What is the value of the following expression?
True && true

A) true
B) False
C) -1
D) +1
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
36
This operator takes an operand and reverses its truth or Falsehood:

A) !&
B) ||
C) =!
D) !
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
37
What is the value of result after the following code executes?
Int a = 60;
Int b = 15;
Int result = 10;
If (a = b)
Result *= 2;

A) 10
B) 120
C) 20
D) 12
E) code will not execute
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
38
What is the value of the following expression?
True || False

A) true
B) False
C) -1
D) +1
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
39
What is the value of donuts after the following statement executes?
Int donuts = 10;
If (donuts = 1)
Donuts = 0;
Else
Donuts += 2;

A) 12
B) 10
C) 0
D) 1
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following expressions will determine whether x is less than or equal to y?

A) x > y
B) x =< y
C) x >= y
D) x <= y
E) x == y and x < y
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
41
What is the output of the following segment of code if the value 4 is input by the user?
Int num;
Int total = 0;
Cout << "Enter a number from 1 to 10:
";
Cin >> num;
Switch (num)
{
Case 1:
Case 2:
Total = 5;
Case 3:
Total = 10;
Case 4:
Total = total + 3;
Case 8:
Total = total + 6;
Default:
Total = total + 4;
}
Cout << total << endl;

A) 0
B) 3
C) 13
D) 23
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
42
When a program lets the user know that an invalid choice has been made, this is known as:

A) input validation
B) output correction
C) compiler criticism
D) output validation
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
43
This statement uses the value of a variable or expression to determine where the program will branch to.

A) switch
B) select
C) association
D) scope
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
44
The default section of a switch statement performs a similar task similar to the __________ portion of an if/else if statement.

A) conditional
B) break
C) trailing else
D) All of these
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
45
Given the if/else statement:
If (a < 5)
B = 12;
Else
D = 30;
Which of the following performs the same operation?

A) a < 5 ? b = 12 : d = 30;
B) b < 5 ? b = 12 : d = 30;
C) a >= 5 ? d = 30 : b = 12;
D) d = 30 ? b = 12 : a = 5;
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
46
Input values should always be checked for

A) an appropriate range
B) reasonableness
C) division by zero, if division is taking place
D) All of these
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
47
Which line in the following program will cause a compiler error?
1 #include
2 using namespace std;
3 int main()
4 {
5 int number = 5;
6 if (number >= 0 && <= 100)
7 cout << "passed.\n";
8 else
9 cout << "failed.\n";
10 return 0;
11 }

A) line 3
B) line 6
C) line 7
D) line 9
E) None will cause an error
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
48
Given the following code segment, what is the output?
Int x = 1, y = 1, z = 1;
Y = y + z;
X = x + y;
Cout << "result = " << (x < y ?
Y :
X) << endl;

A) result = 0
B) result = 1
C) result = 2
D) result = 3
E) there will be no output
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
49
Which statement allows you to properly check the char variable code to determine whether it is equal to a C and then output This is a check?

A) if code is equal to C
Cout << "This is a check\n";
B) if (code = "C")
Cout << "This is a check\n";
C) if (code == 'C')
Cout << "This is a check\n";
D) if (code == C)
Cout << "This is a check" << endl;
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
50
Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.

A) break
B) exit
C) switch
D) scope
E) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
51
Given that x = 2, y = 1, z = 0, what will the following cout statement display?
Cout << "answer = " << (x || !y && z) << endl;

A) answer = 0
B) answer = 1
C) answer = 2
D) None of these
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 51 flashcards in this deck.