CS-1143 Chapter 4
Given the following code segment, what is output after "result = "? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result = " << (x < y ? y : x) << endl;
3
What is the outcome of the following expression? Your choices are true, false, 0, 1, or ERROR. ( 6 < 5 ) && ( 2 * 3 )
False
x >= y is the same as x > y && x = y
False
If the sub-expression on the left side of an && operator is false, the expression on the right side will not be evaluated. Select one:
True
What will the following segment of code output? You can assume the user enters a grade of 90 from the keyboard. cout << "Enter a test score: "; cin >> test_score;if (test_score < 60); cout << "You failed the test!" << endl; if (test_score > 60) cout << "You passed the test!" << endl; else cout << "You need to study for the next test!";
You failed the test! You passed the test!
The expression following a case statement must have a __ or __ value. Choose two from the list below.
int char
Type the operator that performs the logical NOT operation.
!
Type the operator that performs the "is not equal to" comparison.
!=
What is the outcome of the following expression? Your choices are true, false, 0, 1, or ERROR. ( 5 % 3 == 2 )? 0 : 1
0
What will the following program display? # include <iostream> using namespace std; int main( ) { int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " "; cout << (a != b) << " "; cout << (b <=x) << " "; cout << (y > a) << endl; return 0; }
0 1 1 0
What will be the value of result after the following code has been executed? int a = 60; int b = 15; int result = 10; if (a == b) result *= 2;
10
What is the value of donuts after the following code executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2;
12
After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15;
15
What will be the value of result after the following code has been executed? int a = 60; int b = 15; int result = 10; if (a = b) result *= 2;
20
Type the operator that performs the "less than or equal to" comparison.
<=
Type the operator that performs the assignment operation.
=
What will the following segment of code output if 11 is entered at the keyboard? int number; cin >> number; if (number > 0) cout << "C++"; else cout << "C++"; cout << " is "; cout << "fun!" << endl;
C++ is fun!
What is the outcome of the following expression? Your choices are true, false, 0, 1, or ERROR. !( 5 % 3 = 2 )
ERROR
What is the outcome of the following expression? Your choices are true, false, 0, 1, or ERROR. !( 5 % 3 == 2 )
False
What errors did the programmer commit? Select all that apply.
The programmer should include break statements at the end of each case
What will following segment of code output? int x = 5; if (x = 2) cout << "This is true!" << endl; else cout << "This is false!" << endl;
This is false!
What will following segment of code output? int x = 5; if (x == 2) cout << "This is true!" << endl; else cout << "This is false!" << endl;
This is false!
!(y < x) is the same as x >= y
True
An expression that has any value other than 0 is considered true by an if statement.
True
As a rule of style, when writing an if statement you should indent the conditionally-executed statements, and enclose those statement in curly braces.
True
Both of the following if statements perform the same operation. if (sales > 10000) commissionRate = 0.15; if (sales > 10000) commissionRate = 0.15;
True
Consider the following code: int x = 5; int y = 6; int z = 8; Is the following expression true or false? 2 != y && z != 4
True
Consider the following code: int x = 5; int y = 6; int z = 8; Is the following expression true or false? x == 5 || y > 3
True
What is the outcome of the following expression? Your choices are true, false, 0, 1, or ERROR. ( 6 > 5 ) || ( 2 / 0 )
True
What is the outcome of the following expression? Your choices are true, false, 0, 1, or ERROR. -5 + -1 == -(2 * 3)
True
What is the value of the following expression? false || true
True
What is the value of the following expression? true && ( false || true )
True
What is the value of the following expression? true || true
True
x != y is the same as ( x > y || x < y )
True
Relational operators allow you to ________ operands.
compare
If you intend to place a block of statements within an if statement, you must place these around the block.
curly braces { }
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" and then advance to a new line?
if (code == 'C') cout << "This is a check\n";
When a program lets the user know that an invalid choice has been made, this is known as:
input validation