Cs135- Chapter 4 quiz

¡Supera tus tareas y exámenes ahora con Quizwiz!

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 << a << endl; return 0; }

0 1 1 0

What is the output of the following code? int w = 98; int x = 99; int y = 0; int z = 1; if (x >= 99) { if (x < 99) cout << y << endl; else cout << z << endl; } else { if (x == 99) cout << x << endl; else cout << w << endl; }

1

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;

1 1

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

This operator is used in C++ to represent equality.

==

Whereas < is called a relational operator, x < y is called a(n) ________.

Relational expression

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;

That's a high score! This is a test question!

What is the output of the following code segment? int x = 5; if (x = 2) cout << "This is true!" << endl; else cout << "This is false!" << endl; cout << "This is all folks!" << endl;

This is true! This is all folks! explanation: didn't read in the x

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! explanation: semi colon error

In C++ the = operator indicates:

assignment

Relational operators allow you to ________ numbers.

compare

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 explanation: didn't give a proper statement

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" << endl;

The ________ of a variable is limited to the block in which it is declared.

scope

When a relational expression is false, it has the value ________.

zero

This operator represents the logical AND.

&&

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

When an if statement is placed within the conditionally-executed code of another if statement, this is known as:

nesting

This operator performs a logical NOT operation.

!


Conjuntos de estudio relacionados

Physiology 1, Physiology 2, Physiology 3, Physiology 4, Physiology 5, Physiology 6 Cardio 1, Physiology 7 Cardio 2, Physiology 8 cardio 3, Physiology 9 Respiration 1, Physiology 10 respiration 2, Physiology 11, Physio 12, Physio 13, Physio 14 and 15...

View Set

Lesson 8: Listing Agreements: Pop Quiz

View Set

Air Methods Part 135 Study Guide

View Set

Reasoning in Algebra and Geometry

View Set

Oracle Study Guide Sections 1-10

View Set

Lewis Chapter 37 Vascular Disorders

View Set