CSC 134 Chapter 8 Quiz

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

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

int xNum = 0; int yNum = 0; do { for (yNum = 0; yNum < 3; yNum += 1) xNum += yNum; } while (xNum < 10) ; cout << xNum;

12

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; innerNum < 2; outerNum++) { for (innerNum = 1; innerNum < 2; innerNum++) cout << "innerNum: " << innerNum << endl;

2

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

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

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

3

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

Boolean

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

add a semicolon after the condition

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

bottom-driven loop

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

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

do while

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

do while

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

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

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

nested repetition

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

The do while statement ends with what character?

semicolon

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

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; do for (xNum = 1; xNum < 10; xNum += 1) yNum += 2; while (yNum < 20) ;

yNum should be initialized


Conjuntos de estudio relacionados

Spinal Cord & Spinal Nerves: Anatomy Chapter 14

View Set

From the Middle Ages through the Renaissance

View Set

Texas Insurance License Ch.1 Quiz

View Set

kidney, pancreas, liver transplant

View Set

Food & Safety Taps practice test

View Set

Macbeth study questions (for act 1)

View Set