solution
Input values should always be checked for:
Appropriate range, reasonableness, and division by zero, if division is taking place.
What is the value of the following expression?
true && false
false
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;
false
Relational operators allow you to ________ numbers.
compare
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
If you place a semicolon after the statement:
if (x < y)
The compiler will interpret the semicolon as a null statement.
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;
11
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!";
You failed the test!
You passed the test!
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
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
When a relational expression is false, it has the value ________.
, zero
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;
C++ is fun
What is the value of the following expression?
true || true
true
This is a variable, usually a bool or an int, that signals when a condition exists.
flag
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;
13
There are_____bytes in a bit
a. 64
b. 8
c. 4
d. None of the above
d. none of the above
______is the code you write
source code