Programming C++ Chapter 4 Quiz

25 July 2022
4.7 (114 reviews)
15 test answers

Unlock all answers in this set

Unlock answers (11)
question
Input values should always be checked for:
answer
Appropriate range, reasonableness, and division by zero, if division is taking place.
question
What is the value of the following expression? true && false
answer
false
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
Relational operators allow you to ________ numbers.
answer
compare
question
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;
answer
3
question
If you place a semicolon after the statement: if (x < y)
answer
The compiler will interpret the semicolon as a null statement.
question
What will the following program segment display? 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;
answer
1 1
question
What will the following segment of code output? 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!";
answer
You failed the test! You passed the test!
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
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;
answer
15
question
When a relational expression is false, it has the value ________.
answer
zero
question
What will the following segment of code output if the value 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
What is the value of the following expression? true || true
answer
true
question
This is a variable, usually a bool or an int, that signals when a condition exists.
answer
flag
question
What is the output of the following segment of code if the value 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