chapter 5 quiz

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the output of the following C++ code? int j;for (j = 10; j <= 10; j++)cout << j << " ";cout << j << endl; 10 11 10 11 11 10 10

10 11

Suppose sum and num are int variables, and the input is 18 25 61 6 -1. What is the output of the following code?sum = 0;cin >> num;while (num != -1){sum = sum + num;cin >> num;}cout << sum << endl; 119 92 110 109

110

Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code?sum = 0;cin >> num;for (int j = 1; j <= 4; j++){sum = sum + num;cin >> num;}cout << sum << endl; 126 127 125 124

125

Suppose sum, num, and j are int variables, and the input is 4 7 12 9 -1. What is the output of the following code?cin >> sum;cin >> num;for (j = 1; j <= 3; j++){cin >> num; sum = sum + num;}cout << sum << endl; 42 25 24 41

24

What is the output of the following C++ code?count = 1;num = 25;while (count < 25){num = num - 1;count++;}cout << count << " " << num << endl; 24 1 24 0 25 1 25 0

25 1

What is the next Fibonacci number in the following sequence?1, 1, 2, 3, 5, 8, 13, 21, ... 56 43 273 34

34

What is the value of x after the following statements execute?int x = 5;int y = 30;dox = x * 2;while (x < y); 20 40 10 5

40

Consider the following code. (Assume that all variables are properly declared.)cin >> ch;while (cin){cout << ch;cin >> ch;}This code is an example of a(n) ____ while loop. flag-controlled EOF-controlled sentinel-controlled counter-controlled

EOF-controlled

What is the output of the following loop?count = 5;cout << 'St';do{cout << 'o';count--;} while (count <= 5); St This is an infinite loop. Stop Sto

This is an infinite loop.

The ____ statement can be used to eliminate the use of certain (flag) variables. break if switch while

break

The ____________________ statement is typically used for two purposes: • To exit early from a loop.• To skip the remainder of a switch structure.

break

Consider the following code. int limit;int reps = 0;cin >> limit;while (reps < limit){cin >> entry;triple = entry * 3;cout << triple;reps++; }cout << endl;This code is an example of a(n) ____ while loop. counter-controlled EOF-controlled flag-controlled sentinel-controlled

counter-controlled

To generate a random number, you can use the function rand of the header file ____________________.

cstdlib

Which of the following is a repetition structure in C++? if do...while switch while...do

do...while

Which of the following loops does not have an entry condition? sentinel-controlled while loop EOF-controlled while loop for loop do...while loop

do...while loop

Which of the following loops is guaranteed to execute at least once? sentinel-controlled while loop for loop counter-controlled while loop do...while loop

do...while loop

Assume that all variables are properly declared. The following for loop executes 20 times. for (i = 0; i <= 20; i++)cout << i; True False

false

In a sentinel-controlled while loop, the body of the loop continues to execute until the EOF symbol is read. True False

false

The following while loop terminates when j > 20. j = 0; while (j < 20)j++; True False

false

The statement in the body of a while loop acts as a decision maker. True False

false

A(n) ____-controlled while loop uses a bool variable to control the loop. counter flag sentinel EOF

flag

When a continue statement is executed in a ____, the update statement always executes. while loop switch structure for loop do...while loop

for loop

What is the initial statement in the following for loop? (Assume that all variables are properly declared.)int i;for (i = 1; i < 20; i++)cout << "Hello World";cout << "!" << endl; i = 1; i < 20; i++; cout << "Hello World";

i = 1;

A loop that continues to execute endlessly is called a(n) ____ loop. definite infinite unhinged end

infinite

A loop ____________________ is a set of statements that remains true each time the loop body is executed.

invariant

The function eof is a member of the data type ____________________.

istream

What executes immediately after a continue statement in a while and do-while loop? update statement the body of the loop loop-continue test loop condition

loop-continue test

In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s). looping sequence branching selection

looping

In a while and for loop, the loop condition is evaluated before executing the body of the loop. Therefore, while and for loops are called ____________________ loops.

pretest

A semicolon at the end of the for statement (just before the body of the loop) is a(n) ____________________ error.

semantic

Which of the following statements generates a random number between 0 and 50? srand(time(10));num = rand() % 50; srand(time(10));num = rand()/50; srand(time(0));num = rand()50; srand(time(0));num = rand() % 50;

srand(time(0));num = rand() % 50;

Which executes first in a do...while loop? loop condition the statement the expression update statement

the statement

Assume all variables are properly declared. The output of the following C++ code is 2 3 4 5. n = 1;while (n < 5){n++;cout << n << " ";} True False

true

In a counter-controlled while loop, the loop control variable must be initialized before the loop. True False

true

In the case of the sentinel-controlled while loop, the first item is read before the while loop is entered. True False

true

The control statements in the for loop include the initial statement, loop condition, and update statement. True False

true

The control variable in a flag-controlled while loop is a bool variable. True False

true

The number of iterations of a counter-controlled loop is known in advance. True False

true

What is the output of the following C++ code?num = 10;while (num > 10)num = num - 2;cout << num << endl; 8 0 6 10

10

____ loops are called posttest loops. while for do...while break

do...while


Set pelajaran terkait

Chapter 7: Introduction to Hypothesis Testing

View Set

2014 NEC Chapter 2 Wiring and Protection

View Set

CW 1.1: Early Tensions Between East and West

View Set

Intermediate Accounting II - Test 2 (Chapter 16, 17 & 18)

View Set

Quiz 1 : Completing the Application, Underwriting and Delivering the Policy

View Set