C++ Test 2

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

If the sub-expression on the left of the ___ logical operator is false, the right sub-expression is not checked.

&&

The ___ logical operator works best when testing a number to determine if it's within a range.

&&

A variable with a ___ scope is only visible when the program is executing in the bock containing the variables definition.

Block

(T/F) The cout statement in the following program will display 5: int x=5; cout<<++x;

False (Displays 6)

(T/F) x >= y is the same as (x>y && x=y)

False (x is '>' OR '=' y)

The ___ statement causes a loop to skip the remaining statements in the current iteration.

Continue

A ___ is a variable that "counts" the number of times a loop repeats.

Counter

The trailing else in an if else if statement has a similar purpose as the ___ section of a switch statement.

Default

The ___ loop always iterates at least once.

Do-while

(T/F) A variable defined in an inner block may not have the same name as a variable defined in the outer block.

False

(T/F) In a nested loop, the outer loop executes faster than the inner loop.

False

(T/F) It's safe to assume that all uninitialized variables automatically start with a '0' as their value.

False

(T/F) It's unnecessary to initialize counter variables.

False

(T/F) One limitation of the for loop is that only one variable may be initialized in the initialization expression.

False

(T/F) The = operator and the == operator perform the same operation when used in a Boolean expression.

False

(T/F) The break statement causes a loop to stop the current iteration and begin the next one.

False

(T/F) The continue statement causes a terminated loop to resume.

False

(T/F) The do-while loop is a preset loop.

False

(T/F) The for loop is a posttest loop.

False

(T/F) The operand of the increment and decrement operators can be any valid mathematical expression.

False

(T/F) To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops.

False

(T/F) When an 'if' statement is nested in the 'ELSE' part of another statement, the only time the inner 'if' is executed is when the expression of the outer 'if' is true.

False

The if statement regards an expression with the value 0 as ___.

False

The value of a relational expression is 0 if the expression is ___ or 1 if the expression is ___.

False; true

The ___ loop is ideal for situations that require a counter.

For

Describe the difference between the 'if/else if' statement and a series of 'if' statements.

If/else if: conditions are tested until one is found to be true. The conditionally executed statement(s) are executed and the program exits. If statements: all of the if statements execute and test their conditions because they are not connected.

(T/F) A variable may be defined in the initialization expression of the for loop.

True

(T/F) All lines in a block should be indented one level.

True

(T/F) All three of the for loops expressions may be omitted.

True

(T/F) In a nested loop the break statement only interrupts the loop it's placed in.

True

(T/F) In a nested loop, the inner loop goes through all of its iterations for every single iteration of the outer loop.

True

(T/F) The cout statement in the following program will display 5: int x = 5; cout<<x++;

True

(T/F) The scope of a variable is limited to the block in which it is defined.

True

(T/F) The while loop is a preset loop.

True

(T/F) Variables may be defined inside the body of a loop.

True

(T/F) When an 'if' statement is nested in the 'IF' part of another statement, the only time the inner 'if' is executed is when the expression of the outer 'if' is true.

True

(T/F) When you call an ofstream objects open member function, the specified file will be erased if it already exists.

True

(T/F) You can use the relational operators to compare string objects.

True

(T/F) a conditionally executed statement should be indented one level from the if statement.

True

(T/F) x != y is the same as (x>y || x<y)

True

The if statement regards an expression with a nonzero value as ___.

True

A program will "fall through" a case section if it is missing the ___ statement.

break;

An expression using the conditional operator is called a ___ expression.

Conditional

The ___ logical operator has higher precedence than the other logical operators.

!

(T/F) y<x is the same as x >= y.

False

You use the ___ operator to determine whether one string object is greater then another string object.

>

An ___ is a variable that's initialized to some starting value, usually zero, and then has numbers added to it in each iteration of a loop.

Accumulator

The statement or block that is repeated is known as the ___ of a loop.

Body

What is a flag and how does it work?

Boolean variable signaling that some condition exists in a program. When the flag is set to false it indicated the condition doesn't yet exist. When set to true it indicates that the condition exists.

For an if statement to conditionally execute a group of statements, the statements must be enclosed in a set of ___.

Brackets

The ___ statement causes a loop to terminate immediately.

Break

To ___ a value means to increase it by one, and to ___ a value means to decrease it by one.

Increment; decrement

A loop that does not have a way of stopping is an ___ loop.

Infinite

Inside the for loops parentheses, the first expression is the ___, the second expression is the ___, and the third expression is the ___.

Initialization, test, update

The expression that is tested by a switch statement must have an ___ value

Integer

The expression following a switch case must be an ___ ___.

Integer constant

If an 'if/else if' statement, what is the purpose of a trailing 'else'?

It provides code that's executed when none of the conditions are true.

Describe how the && operator works.

It takes two expressions as operands and creates a single expression that is true only when BOTH subexpressions are true.

Describe how the || operator works.

It takes two expressions as operands and creates a single expression that is true only when EITHER subexpressions are true.

Why do most programmers indent the conditionally executed statements in a decision structure?

It visually sets the conditionally executed statements apart from the surrounding code; to easily identify the conditionally executed code.

Each repetition of a loop is known as an ___.

Iteration

The logical operators have ___ associativity.

Left to right

The if else statement is actually a form of the ___ if statement

Nested

A loop inside another loop is called a ___.

Nested loop

A loop that evaluates its test expression AFTER each repetition is a ___ loop.

Posttest

When the increment or decrement operator is placed BEFORE the operand (or to the operands right) the operator is being used in ___ mode

Prefix

A loop that evaluates its test expression BEFORE each repetition is a ___ loop.

Pretest

An expression using the greater than, less than, etc. operator is called a ____ expression.

Relational

A ___ is a sum of numbers that accumulates with each iteration of a loop.

Running total

A ___ is a special value that marks the end of a series of values.

Sentinel

Why are the relational operators called relational?

They test for specific relationships between items. (Ex. <,>,<=,>=,!=)

A relational expression is either ___ or ___.

True; false

In an if/else statement, the if part executes its statement or block if the expression is ___, and the and the else part executes its statement or block if the expression is ___.

True; false

The ___ and ___ loops will not iterate at all if their expressions are false to start with.

While; for

Can an 'if' statement test expressions other than relational expressions?

Yes; it can test any value yielding Boolean values or a numeric value. When testing a numeric expression, nonzero values are true and 0 is false.

When the increment or decrement operator is placed AFTER the operand (or to the operands right) the operator is being used in ___ mode

postfix

If the sub-expression on the left of the ___ logical operator is true, the right sub-expression is not checked.

||

The ___ logical operator works best when testing a number to determine if it's outside a range.

||


Kaugnay na mga set ng pag-aaral

30 review questions on experience of loss, death, and grief

View Set

Chapter 31/Obstetrics and Neonatal Care/EMTB

View Set

Chapter 12, 15, 11, 13, 14 and 16

View Set

Chapter 9: Inventories: Additional Issues

View Set

Chemistry, Groups of the Periodic Table, Chapter 4

View Set