C++ 5-8

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

Which of the following comparison operators represents "not equal to" in C++?

!=

What is another way that the condition below could be written? ​ ( num <= 10 ) ​

( (num < 10) || (num = 10) )

Which of the following conditions tests to see if the variable number is equal to 29?

( number == 29 )

What is assigned to the answer variable after the following code is executed? ​ int answer = 0; int yNum = 0; do { for (int xNum = 1; xNum < 3; xNum +=1) answer = answer * xNum; yNum += 1; } while (yNum < 3);

0

How many times will the instruction in the loop body of the following code be processed? int x = 3; do { x++; } while (x <= 3);

1

What would be the result of the following C++ code (assuming all necessary directives)? ​ double number = 1234.567; cout << scientific << number << endl;

1.234567e+03

What is the result of the following arithmetic expression in C++? 2 + 4 * 2

10

What is the output of the following code? ​ int xNum = 0; int yNum = 0; do { for(yNum = 0; yNum < 3; yNum += 1) xNum += yNum; } while (xNum < 10); cout << xNum; ​

12

What would be the result of the following C++ code (assuming all necessary directives)? ​ double number = 1234.567; cout << fixed << number << endl; ​

1234.567000

What would be the result of the following C++ code (assuming all necessary directives)? ​ double number = 1234.56; cout << fixed; cout << setprecision(0); cout << number << endl;

1235

What is the result of the following arithmetic expression in C++? 2 * (4 + 4)

16

How many times will the instruction in the loop body of the following code be processed? int x = 0; do { x += 3; } while (x <= 3);

2

What is the value of the variable innerNum at the end of the execution of the following code? ​ int outerNum; int innerNum; for (outerNum = 1; outerNum < 2; outerNum++) { for (innerNum = 1; innerNum < 2; innerNum++) cout << "innerNum: " << innerNum << endl; }

2

What is the output of the following code? ​ int xNum = 0; int yNum = 0; do { xNum += yNum; } while (xNum == yNum++); cout << xNum; ​

3

In an if statement, the programmer must supply the condition that the computer needs to evaluate before further processing can occur. The condition must be which type of expression?

Boolean

What type of value is the outcome of the condition in a do while statement?

Boolean

What is the name of the process used to verify that the input data is within the expected range?

Data validation

What can be used to graphically represent a nested selection structure?

Flowcharts

What is used to summarize how the computer evaluates the logical operators in an expression?

Truth tables

What value is stored in the letter variable after the following code is executed? ​ char letter = 'a'; char letter2 = ' '; letter2 = toupper(letter);

a

A common error made when writing selection structures is to use a compound condition rather than which of the following?

a nested selection structure

Examine the following switch statement. What is needed to make a valid switch statement? switch { case 10: cout << "The answer is 10."; break; case 20: case 30: cout << "The answer is 20 or 30."; break; default: cout << "The answer is none of them."; break; case 40: cout << "The answer is 40."; }

a selectorExpression is needed

A(n) _____ is a numeric variable used for adding together something.

accumulator

What is required to fix the following invalid code? do { x++; } while (x

add a semicolon after the condition

In a posttest loop, the loop condition is processed _____ the instructions within the loop are processed.

after

Which of the following describes an item that appears between parentheses in a function's syntax?

argument

In a pretest loop, the loop condition is processed _____ the instructions within the loop are processed.

before

AND and OR are the two most commonly used examples of which type of operator?

boolean

Comparison operators evaluate to what type of value?

boolean

A posttest loop is also referred to as which of the following?

bottom-driven loop

In a selection structure, if a path contains more than one statement, the statements must be entered as a statement block, which means they must be enclosed in which of the following?

braces

Which character encloses a statement block within a switch statement?

braces

Which statement is used within a switch statement to tell the computer to exit the switch statement at that point?

break statement

What type of clause within a switch statement represents a different alternative?

case clause

Given the code below beginning a switch statement, what type of data would be required for the value in each case clause? ​ char letter = ' '; cout << "Enter a letter: ''; cin >> letter; ​ switch (letter) { ...... ​

char

What data type is required for the argument in the toupper and tolower functions?

char

Which of the following applications would require a nested repetition structure?

clock

The outer loop of a nested for loop ends with which of the following characters?

closing brace

Each case clause within a switch statement contains a value followed by which punctuation mark?

colon

Although not required, it is good programming practice to mark the end of the loop with a(n) _____.

comment

In a for statement, the second argument in the for clause is the _____ argument.

condition

A(n) _____ is a numeric variable used for counting something.

counter

A(n) _____ is always updated by a constant value.

counter

What type of clause may you include within a switch statement in addition to case clauses?

default

Which clause can be entered anywhere within a switch statement, but is usually coded as the last clause in the switch statement?

default

Within a switch statement, the _____ clause can contain one or more statements to be executed when the selectorExpression does not match any of the _____ clauses.

default, case

Which symbol in a flowchart is known as the decision symbol?

diamond

What type of loop statement should you use if the instructions in the loop body must be processed at least once?

do while

Which of the following is a repetition structure that performs a posttest loop?

do while

Selection structures that contain instructions on both the true and false paths are referred to as which of the following?

dual-alternative

Which of the following is true about nested repetition structures?

each loop can be either pretest or posttest

What is the result of the following code? ​ int xNum, yNum, zNum; ​ yNum = 0; zNum = 0; do { for (xNum = 1; xNum < yNum; yNum += 1) zNum += xNum; } while (zNum < 100); cout << "zNum: " << zNum;

endless loop

In a flowchart, what does a diamond that has more than two flow lines represent?

extended selection structure

Besides using the while statement to code pretest loops, you can also use the _____ statement in C++.

for

Which for clause is correct?

for (int i = 1; i < 10; i += 1)

In which type of repetition structure is it possible that the instructions in the loop body might never be processed?

for loop

A loop whose instructions are processed indefinitely is referred to as a(n) _____ loop.

infinite

Another name for an endless loop is a(n) _____ loop.

infinite

For a program to use the setprecision stream manipulator, it must include which file?

iomanip

Stream manipulators that do not have arguments, such as fixed and scientific, are defined in which file?

iostream

What are the consequences of writing selection structures to include an unnecessary nested selection structure?

less efficient code

What type of variable can be used only within the statement block in which it is defined?

local

A repetition structure is more commonly known as a _____.

loop

In a repetition structure, the requirement for not repeating the instructions is referred to as the _____ because it tells the computer when to exit stop the loop.

loop exit condition

In a repetition structure, the requirement for repeating the instructions is referred to as the _____ because it indicates when the computer should continue "looping" through instructions.

looping condition

In regards to the repetition structure, every _____ has an opposing _____; one is the opposite of the other.

looping condition, loop exit condition

What is wrong, if anything, with the following code? ​ double price = 0; cout << "Item price: "; cin >> price; do { cout << "Total cost: $" << price + price * .05 << endl; cout << "Item price: "; } while (price > 0);

missing the update read

A secondary decision is always made by which selection structure? Select one:

nested

When either a selection structure's true path or its false path contains another selection structure, the inner selection structure is referred to as which selection structure?

nested

What type of structure is created when a pretest loop is inside another pretest loop?

nested repetition

If the default clause is the last clause in a switch statement, what statement is required after the default clause?

no statement is required

What, if anything is required to make the following code valid? int x = 0; do x += 15; while (x < 100);

nothing; the code is valid

What type of loop is often used in programs that allow the user to select from a menu?

posttest

A while loop can be used to code a(n) _____ loop in C++.

pretest

Depending on the result of the evaluation of the condition, the instructions in a(n) _____ loop may never be processed.

pretest

What type of decision is always made by an outer selection structure?

primary

In a pretest loop, the _____ initializes the loop condition by providing its first value.

priming read

A programmer determines whether a problem's solution requires a nested selection structure by studying which of the following?

problem specification

A programmer determines whether a problem's solution requires a nested selection structure by studying the _____.

problem specifications

A common error made when writing selection structures is to do which of the following to the decisions made by the outer and nested structures?

reverse

To display real numbers in exponential notation, the programmer would use which stream manipulator?

scientific

In a switch statement, what immediately follows the switch clause?

selectorExpression

The data type of the value in a case clause within a switch statement must be compatible with the data type of which of the following?

selectorExpression

Each clause in a for statement is separated by a _____.

semicolon

The do while statement ends with what character?

semicolon

A(n) _____ should be easily distinguishable from the valid data recognized by the program.

sentinel value

Counter-controlled loops are controlled using a counter rather than a(n) _____.

sentinel value

A computer programmer can use which of the following to control the number of decimal places that appear when a real number is displayed?

setprecision stream manipulator

What type of selection structure occurs when there are one or more actions to be taken only when its condition evaluates to true?

single-alternative

Instead of an if statement, what type of statement can you often use to code a multiple-alternative selection structure?

switch

In the following switch statement, what is the expected output? ​ switchval = 83-23; switch (switchval) { case 30: cout << "switchval is 30"; break; case 40: cout << "switchval is 40"; break; case 50: cout << "switchval is 50"; break; default: cout << "switchval is more than 50"; }

switchval is more than 50

If there is no default clause in a switch statement and no match is found, what happens?

the instruction after the closing brace is executed

Which of the following is true about case clauses in a switch statement?

the value can be a literal constant

What, if anything, is wrong with the following code? ​ int final = 1;int varA = 0;int varB;do while (varA < 3){for (varB = 1; varB < 3; varB +=1)final = final * varB; varA += 1;}

the while condition is in the wrong place

Sentinel values are often referred to as _____ values, because they are the last values entered before the loop ends.

trailer

In a for statement, the third argument in the for clause is the _____ argument.

update

In a pretest loop, if you do not include the _____ in the loop body, there will be no way to enter the sentinel value after the loop body instructions are processed the first time.

update read

Adding a number to the value stored in a counter or accumulator is referred to as _____.

updating

What is the result of the following code? ​ int xNum = 0; int yNum = 0; do { xNum = xNum + yNum; yNum += 1; cout << "xNum: " << xNum; } while (xNum > 2);

xNum: 0 is printed

What is wrong with the following code? ​​ int xNum, yNum;dofor (xNum = 1; xNum < 10; xNum += 1)yNum += 2;while (yNum < 20);

yNum should be initialized


Conjuntos de estudio relacionados

Nutrition: Science and Applications Chapter 12 The Trace Minerals

View Set

[SECRET] Google Hangouts /Roll Guide

View Set

STUDY UNIT 8: Aids and experts used to investigate crime, irregularities and transgressions: digital forensics {362 to 393}

View Set

4. Google AdWords - Keyword Targeting - Fundamentals Exam

View Set

Word Smart and Word Smart II SAT vocabulary

View Set

Leccion 3 Elegir- Select si or no to indicate which of the following items you see in the Flash cultura video.

View Set