Exam 5: Control Structures II Repetition

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

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

Free
(True/False)
4.9/5
(35)
Correct Answer:
Verified

False

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

Free
(Short Answer)
4.8/5
(41)
Correct Answer:
Verified

invariant

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++) \quad cout << "Hello World"; cout << "!" << endl;

Free
(Multiple Choice)
4.8/5
(30)
Correct Answer:
Verified

A

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.

(Short Answer)
5.0/5
(41)

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

(Multiple Choice)
4.9/5
(38)

If a(n) ____________________ statement is placed in a do...while structure, the loop-continue test is evaluated immediately after this statement.

(Short Answer)
4.9/5
(41)

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

(Short Answer)
4.9/5
(41)

The ____________________ loop has an exit condition but no entry condition.

(Short Answer)
5.0/5
(31)

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

(Short Answer)
4.8/5
(43)

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

(Multiple Choice)
4.9/5
(42)

What is the value of x after the following statements execute? int x = 5; Int y = 30; Do X = x * 2; While (x < y);

(Multiple Choice)
4.9/5
(42)

A loop that continues to execute endlessly is called a(n) ____ loop.

(Multiple Choice)
4.8/5
(38)

Which of the following loops does not have an entry condition?

(Multiple Choice)
4.7/5
(41)

Consider the following code. int limit; int reps = 0; cin >> limit; While (reps < limit) { \quad cin >> entry; \quad triple = entry * 3; \quad cout << triple; \quad reps++; } cout << endl; This code is an example of a(n) ____ while loop.

(Multiple Choice)
4.8/5
(36)

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++) { \quad cin >> num; \quad sum = sum + num; } cout << sum << endl;

(Multiple Choice)
4.8/5
(37)

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

(True/False)
4.9/5
(35)

Which of the following loops is guaranteed to execute at least once?

(Multiple Choice)
4.9/5
(34)

What executes immediately after a continue statement in a while and do-while loop?

(Multiple Choice)
4.8/5
(43)

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) { \quad sum = sum + num; \quad cin >> num; } cout << sum << endl;

(Multiple Choice)
4.8/5
(39)

A software ____________________ is a piece of code written on top of an existing piece of code intended to fix a bug in the original code.

(Short Answer)
4.9/5
(27)
Showing 1 - 20 of 50
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)