Chapter 4

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

This is perhaps the most famous saying of the computer world.

"garbage in, garbage out"

This operator takes two expressions as operands and creates an expression that is true only when both sub-expressions are true.

&&

When determining whether a number is inside a numeric range, it's best to use this operator.

&&

When using the if statement, all values other than this are considered true.

0

Which of the following relational operators test for two relationships?

>= and <=

If you executed the following code, what would it display if the user enters 5? int number; cout << "Enter a number: "; cin >> number; if (number > 0) { cout << "A"; if (number > 10) { cout << "B"; if (number > 20) { cout << "C"; } } }

A

If you executed the following code, what would it display if the user enters 15? int number; cout << "Enter a number: "; cin >> number; if (number > 0) { cout << "A"; if (number > 10) { cout << "B"; if (number > 20) { cout << "C"; } } }

AB

If you executed the following code, what would it display if the user enters 30? int number; cout << "Enter a number: "; cin >> number; if (number > 0) { cout << "A"; if (number > 10) { cout << "B"; if (number > 20) { cout << "C"; } } }

ABC

Enclosing a group of statements inside a set of these creates a block of code.

Braces

This operator provides a shorthand method of expressing a simple if/else statement.

Conditional

In a flowchart, this symbol represents a yes/no question or a true/false condition.

Diamond

If you inadvertently put a semicolon after the if (expression) portion of an if statement, the statement following the if will never execute.

False

In C++, relational expressions represent true states with the number 0 and false states with the number 1.

False

The else part at the end of the if statement specifies a statement that is to be executed when the expression is true.

False

string objects cannot be compared with relational operators.

False

This is typically a bool variable that signals when some condition exists in the program.

Flag

You should be careful when using the equality operator (==) to compare these.

Floating-point numbers

All of the relational operators are binary, which means they use this many operands.

two

Assume the variable result is assigned the value 0. What will the following code display? if (result > 0) cout << "one\n"; cout << "two\n"; cout << "three\n";

two three

This operator takes two expressions as operands and creates an expression that is true when either of the sub-expressions are true.

| |

When determining whether a number is outside a range, this operator is best to use.

| |

This operator takes an operand and reverses its truth or falsehood.

!

All the relational operators have right-to-left associativity.

False

This is the process of inspecting data given to a program by the user and determining if it is valid.

Input validation

This is an empty statement that does nothing.

Null statement

Numeric data is compared in C++ by using these operators.

Relational

Code with this type of structure contains statements that are executed in sequence, without branching off in another direction.

Sequence

Indentation and spacing are for the human readers of a program, not the compiler.

True

It is often simpler to test a series of conditions with the if/else if statement than with a set of nested if/else statements.

True

Programs often need more than one path of execution.

True

Relational expressions have a higher precedence than the assignment operator.

True

Semicolons do not mark the end of a line, but the end of a complete C++ statement, and the if statement isn't complete without the conditionally executed statement that comes after it.

True

Since it takes three operands, the conditional operator is considered a ternary operator.

True

The ! operator has a higher precedence than than the && and || operators.

True

The == operator determines whether a variable is equal to another value, but the = operator assigns the value on the operator's right to the variable on its left.

True

The integrity of a program's output is only as good as its input.

True

The switch statement's default section (or the last case section, if there is no default) does not need a break statement.

True

Variables defined inside a set of braces may only be used in the part of the program between their definition and the block's closing brace.

True

When a block is nested inside another block, a variable defined in the inner block may have the same name as a variable defined in the outer block.

True

When the flag variable is set to false , it indicates that the condition does not exist, and when the flag variable is set to true , it means the condition does exist

True

Relational expressions are also known as Boolean expressions, which means their value can only be this.

True or False

Even though if statements usually span more than one line, they are technically one long statement.

True

Integer variables may also be used as flags.

True

When two characters are compared, it is actually their ASCII values that are being compared.

True

This statement tests the value of an integer expression and then uses that value to determine which set of statements to branch to.

switch

All expressions have a value.

True

All it takes for an OR expression to be true is for one of the sub-expressions to be true.

True

Anytime your program has a block of code, all the statements inside the braces should be indented.

True

Computers are good at performing calculations, but they are also quite adept at comparing values to determine if one is greater than, less than, or equal to the other.

True

For readability and easier debugging, it's important to use proper alignment and indentation in a set of nested if statements.

True

If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked.

True

In a decision structure's simplest form, a specific action is taken only when a specific condition exists, and if the condition does not exist, the action is not performed.

True

The last else clause in the if/else if statement, which is optional and does not have an if statement following it, is referred to as this.

Trailing else


Ensembles d'études connexes

Financial Transactions and Fraud Schemes

View Set

history quiz (pullman strike etc.)

View Set

Chapter 6 - Neutralizing the Threat of Acid Rain

View Set

NUR310 Chapter 8: Communication Mastery

View Set

Chapter 45: Digestive and Gastrointestinal Treatment Modalities

View Set