C++ Programming Multiple Choice Final
Questions With Answers
Question 1.
x = 10, y = 7, and z, a, and b are all int variables. a = x >= y;
Correct Answer: 1
Question 2.
When a relational expression is false, it has the value
Correct Answer: Zero
Question 3.
What will following segment of code output?
Correct Answer: This is true! This is all folks!
Question 4.
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!";
Correct Answer: You failed the test You Passed the test!
Question 5.
This Operator represents the logical AND
Correct Answer: &&
Question 6.
This operator takes an operand and reverses its truth or falsehood.
Correct Answer: !
,Question 7.
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;
Correct Answer: 13
Question 8.
. What will the following segment of code output? score = 40;
if (score > 95)
cout << "Congratulations!\n";
cout << "That's a high score!\n";
cout << "This is a test question!" << endl;
Correct Answer: That's a high score This is a Test Question!
Question 9.
Operator is used in C++ to represent equality.
Correct Answer: ==
Question 10.
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)
Correct Answer: 3 & 4 are false
Questions With Answers
Question 1.
x = 10, y = 7, and z, a, and b are all int variables. a = x >= y;
Correct Answer: 1
Question 2.
When a relational expression is false, it has the value
Correct Answer: Zero
Question 3.
What will following segment of code output?
Correct Answer: This is true! This is all folks!
Question 4.
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!";
Correct Answer: You failed the test You Passed the test!
Question 5.
This Operator represents the logical AND
Correct Answer: &&
Question 6.
This operator takes an operand and reverses its truth or falsehood.
Correct Answer: !
,Question 7.
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;
Correct Answer: 13
Question 8.
. What will the following segment of code output? score = 40;
if (score > 95)
cout << "Congratulations!\n";
cout << "That's a high score!\n";
cout << "This is a test question!" << endl;
Correct Answer: That's a high score This is a Test Question!
Question 9.
Operator is used in C++ to represent equality.
Correct Answer: ==
Question 10.
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)
Correct Answer: 3 & 4 are false