Computer Programming: Chapter 4

25 July 2022
4.7 (114 reviews)
28 test answers

Unlock all answers in this set

Unlock answers (24)
question
What will the following program display? #include 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; }
answer
0 1 1 0
question
This is a variable, usually a boolean or an integer, that signals when a condition exists.
answer
flag
question
When a program lets the user know that an invalid choice has been made, this is known as:
answer
input validation
question
You should be careful when using the equality operator to compare floating point values because of potential round-off errors.
answer
True
question
As a rule of style, when writing an if statement you should indent the conditionally-executed statements.
answer
True
question
Assuming x is 5, y is 6, and z is 8, which of the following is false? 1. x == 5; 2. 7 <= (x + 2); 3. z < = 4; 4. (1 + x) != y; 5. z >= 8; 6. x >= 0; 7. x <= (y * 2)
answer
3 and 4 are False
question
Relational operators allow you to ____________ numbers.
answer
compare
question
The default section is required in a switch statement.
answer
False
question
If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked.
answer
True
question
What will be the output of the following code segment after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl;
answer
False
question
Which line in the following program will cause a compiler error? 1 #include 2 using namespace std; 3 4 int main() 5 { 6 int number = 5; 7 8 if (number >= 0 && <= 100) 9 cout << "passed.n"; 10 else 11 cout << "failed.n"; 12 return 0; 13 }
answer
8
question
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 << "Soccer"; cout << " is "; cout << "fun" << endl;
answer
C++ is fun
question
As a rule of style, when writing an if statement you should indent the conditionally-executed statements.
answer
True
question
This operator represents the logical AND.
answer
&&
question
If you place a semicolon after the statement if (x < y)
answer
The compiler will interpret the semicolon as a null statement.
question
If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked.
answer
True
question
In C++ the = operator indicates
answer
assignment
question
What is the output of the following segment of code if 4 is input by the user when asked to enter a number? 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;
answer
13
question
What is the value of the following expression? true || true
answer
true
question
This statement lets the value of a variable or expression determine where the program will branch to.
answer
switch
question
Whereas < is called a relational operator, x < y is called a(n)________________
answer
Relational expression
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" and then advance to a new line?
answer
if (code == 'C') cout << "This is a checkn";
question
Given that x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl;
answer
answer = 1
question
What will be the output of the following code segment after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl;
answer
false
question
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;
answer
20
question
This operator performs a logical NOT operation.
answer
!
question
What is the value of donuts after the following code executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2;
answer
12
question
What is the value of the following expression? true && false
answer
false