CS 150 Chapter 4

24 July 2022
4.7 (114 reviews)
50 test answers

Unlock all answers in this set

Unlock answers (46)
question
True
answer
A control structure alters the normal sequential flow of execution in a program.
question
False
answer
The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable.
question
False
answer
In C++, both ! and != are relational operators.
question
False
answer
In C++, !, &&, and || are called relational operators.
question
False
answer
The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100.
question
True
answer
Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true.
question
True
answer
In C++, && has a higher precedence than ||.
question
True
answer
The operators != and == have the same order of precedence.
question
True
answer
A compound statement functions as if it was a single statement.
question
False
answer
If the expression in an assert statement evaluates to true, the program terminates.
question
selection
answer
In a ____ control structure, the computer executes particular statements depending on some condition(s).
question
less than or equal to
answer
What does <= mean?
question
==
answer
Which of the following is a relational operator?
question
!=
answer
Which of the following is the "not equal to" relational operator?
question
true
answer
Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y)
question
(x > 0) || ( x <= 0)
answer
Suppose that x is an int variable. Which of the following expressions always evaluates to true?
question
!
answer
Which of the following operators has the highest precedence?
question
=
answer
Which of the following operators has the lowest precedence?
question
10 < x && x < 20
answer
Which of the following expressions correctly determines that x is greater than 10 and less than 20?
question
decision maker
answer
The expression in an if statement is sometimes called a(n) ____.
question
35 45 10
answer
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;
question
nested
answer
When one control statement is located within another, it is said to be ____.
question
*
answer
What is the output of the following code? if (6 > 8) { cout << " ** " << endl ; cout << "****" << endl; } else if (9 == 4) cout << "***" << endl; else cout << "*" << endl;
question
if (x = 5)
answer
Which of the following will cause a logical error if you are attempting to compare x to 5?
question
silent killer
answer
The appearance of = in place of == resembles a(n) ____.
question
2
answer
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;.
question
three
answer
The conditional operator ?: takes ____ arguments.
question
4
answer
What is the value of x after the following statements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4
question
pseudocode
answer
To develop a program, you can use an informal mixture of C++ and ordinary language, called ____.
question
section 5
answer
What is the output of the following code? char lastInitial = 'S'; switch (lastInitial) { case 'A': cout << "section 1" <
question
section 1
answer
What is the output of the following code? char lastInitial = 'A'; switch (lastInitial) { case 'A': cout << "section 1" <
question
13
answer
What is the output of the following code fragment if the input value is 4? int num; int alpha = 10; cin >> num; switch (num) { case 3: alpha++; break; case 4: case 6: alpha = alpha + 3; case 8: alpha = alpha + 4; break; default: alpha = alpha + 5; } cout << alpha << endl;
question
2
answer
What is the output of the following C++ code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y - 3; } cout << y << endl;
question
#include
answer
For a program to use the assert function, it must include which of the following?
question
#define NDEBUG
answer
You can disable assert statements by using which of the following?
question
&&
answer
In C++, the logical operator AND is represented by ____________________.
question
true
answer
The value of the expression 7 + 8 <= 15 is ____________________.
question
relational
answer
The symbol > is a(n) ____________________ operator.
question
relational
answer
A ____________________ operator allows you to make comparisions in a program.
question
!
answer
Putting ____________________ in front of a logical expression reverses the value of that logical expression.
question
false
answer
The value of the expression 6 < 5 || 'g' > 'a' && 7 < 4 is ____________________.
question
false
answer
Suppose found = true and num = 6. The value of the expression (!found) || (num > 6) is ____________________.
question
associativity
answer
The ____________________ of relational and logical operators is said to be from left to right.
question
semantic
answer
Putting a semicolon after the parentheses following the expression in an if statement (that is, before the statement) is a(n) ____________________ error.
question
pass
answer
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
if
answer
Every else must be paired with a(n) ____________________.
question
short circuit evaluation
answer
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
fail
answer
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
switch
answer
A(n) ____________________ structure does not require the evaluation of a logical expression.
question
break
answer
To output results correctly, the switch structure must include a(n) ____________________ statement after each cout statement, except the last cout statement.