CS 150 Chapter 4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

less than or equal to

What does <= mean?

2

Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;.

three

The conditional operator ?: takes ____ arguments.

False

The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100.

decision maker

The expression in an if statement is sometimes called a(n) ____.

True

The operators != and == have the same order of precedence.

False

The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable.

relational

The symbol > is a(n) ____________________ operator.

short circuit evaluation

The term ____________________ describes a process in which the computer evaluates a logical expression from left to right and stops as soon as the value of the expression is known.

false

The value of the expression 6 < 5 || 'g' > 'a' && 7 < 4 is ____________________.

true

The value of the expression 7 + 8 <= 15 is ____________________.

pseudocode

To develop a program, you can use an informal mixture of C++ and ordinary language, called ____.

break

To output results correctly, the switch structure must include a(n) ____________________ statement after each cout statement, except the last cout statement.

35 45 10

What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout << x << " " << y << " " << z << endl;

2

What is the output of the following C++ code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y - 3; } cout << y << endl;

13

What is the output of the following code fragment if the input value is 4? int num; int alpha = 10; cin >> num; switch (num) { case 3: alpha++; break; case 4: case 6: alpha = alpha + 3; case 8: alpha = alpha + 4; break; default: alpha = alpha + 5; } cout << alpha << endl;

section 1

What is the output of the following code? char lastInitial = 'A'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; }

section 5

What is the output of the following code? char lastInitial = 'S'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; }

*

What is the output of the following code? if (6 > 8) { cout << " ** " << endl ; cout << "****" << endl; } else if (9 == 4) cout << "***" << endl; else cout << "*" << endl;

4

What is the value of x after the following statements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4

selection

In a ____ control structure, the computer executes particular statements depending on some condition(s).

fail

Once an input stream enters a(n) ____________________ state, all subsequent input statements associated with that input stream are ignored, and the computer continues to execute the program, which produces erroneous results.

!

Putting ____________________ in front of a logical expression reverses the value of that logical expression.

semantic

Putting a semicolon after the parentheses following the expression in an if statement (that is, before the statement) is a(n) ____________________ error.

True

Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true.

false

Suppose found = true and num = 6. The value of the expression (!found) || (num > 6) is ____________________.

(x > 0) || ( x <= 0)

Suppose that x is an int variable. Which of the following expressions always evaluates to true?

true

Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y)

relational

A ____________________ operator allows you to make comparisions in a program.

True

A compound statement functions as if it was a single statement.

True

A control structure alters the normal sequential flow of execution in a program.

switch

A(n) ____________________ structure does not require the evaluation of a logical expression.

associativity

The ____________________ of relational and logical operators is said to be from left to right.

silent killer

The appearance of = in place of == resembles a(n) ____.

pass

Consider the following statements. int score; string grade; if (score >= 65) grade = "pass"; else grade = "fail"; If score is equal to 75, the value of grade is "____________________".

if

Every else must be paired with a(n) ____________________.

#include <cassert>

For a program to use the assert function, it must include which of the following?

False

If the expression in an assert statement evaluates to true, the program terminates.

False

In C++, !, &&, and || are called relational operators.

True

In C++, && has a higher precedence than ||.

False

In C++, both ! and != are relational operators.

&&

In C++, the logical operator AND is represented by ____________________.

nested

When one control statement is located within another, it is said to be ____.

10 < x && x < 20

Which of the following expressions correctly determines that x is greater than 10 and less than 20?

==

Which of the following is a relational operator?

!=

Which of the following is the "not equal to" relational operator?

!

Which of the following operators has the highest precedence?

=

Which of the following operators has the lowest precedence?

if (x = 5)

Which of the following will cause a logical error if you are attempting to compare x to 5?

#define NDEBUG

You can disable assert statements by using which of the following?


Kaugnay na mga set ng pag-aaral

Chapter 14: Personal Selling and Customer Service

View Set

Ch. 5: Sensation and Perception (Questions)

View Set

Chapter 7-11 Vocab (Their Eyes were watching God)

View Set