COSC TEST Practice Chapter5

Your page rank:

Total word count: 1176
Pages: 4

Calculate the Price

- -
275 words
Looking for Expert Opinion?
Let us have a look at your work and suggest how to improve it!
Get a Consultant

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

Flag

A do…while loop is a post-test loop.

true

What is the output of the following C++ code?

num = 10;
while (num > 10)
num = num – 2;
cout << num << endl;

10

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

False

The function eof returns true if the program has read past the end of the input file

True

What is the next Fibonacci number in the following sequence?

1, 1, 2, 3, 5, 8, 13, 21, …

34

The ____ statement can be used to eliminate the use of certain bool variables in a loop.

Break

A break statement is legal in a while loop, but not in a for loop.

False

The body of a do…while loop may not execute at all.

False

The do…while loop has an exit condition but no entry condition.

True

Consider the following code.

int limit;
int counter = 0;

cin >> limit;

while (counter < limit)
{
cin >> entry;
triple = entry * 3;
cout << triple;
counter++;
}
cout << endl;

This code is an example of a(n) ____ while loop.

Counter Controlled

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

Looping

It is possible that the body of a while loop may not execute at all, but the body of a for loop executes at least once.

False

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

do while loop

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

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.

____ loops are called post-test loops.

do – while

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

True

What is the output of the following C++ code?

count = 1;
num = 25;
while (count < 25)
{
num = num – 1;
count++;
}
cout << count << " " << num << endl;

25 1

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

Infinite

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

False

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

False

*Which executes first in a do…while loop?

*The statement

Loop control variables are automatically initialized in a loop.

False

Both while and for loops are pre-test loops.

True

When a continue statement is executed in a ____, the update statement always executes.

For loop

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

True

Which of the following is a repetition structure in C++?

do while

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;

110

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

True

The execution of a break statement in a while loop terminates the loop.

True

A sentinel-controlled while loop is an event-controlled while loop whose termination depends on a special value.

True

The fourth number in a Fibonacci sequence is found by taking the sum of the previous two numbers in the sequence.

True

After a break statement executes, the program continues to execute with the first statement after the structure.

True

If a continue statement is placed in a do…while structure, the loop-continue test is evaluated immediately after the continue statement.

True

A for loop is typically called an indexed for loop.

True

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;

2.24 1.25

Assume all variables are properly declared. What is the output of the following C++ code?

num = 100;
while (num <= 150)
num = num + 5;
cout << num << endl;

155

What is the output of the following loop?

count = 5;
cout << ‘St’;
do
{
cout << ‘o’;
count–;
}
while (count <= 5);

This is an infinite loop.

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

A Do While Loop

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

True

What is the output of the following C++ code?

int j;
for (j = 10; j <= 10; j++)
cout << j << " ";
cout << j << endl;

11 11

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;

125

Which of the following is true about a do…while loop?

Assume all variables are properly declared. The following for loop executes 20 times.

for (i = 0; i <= 20; i++)
cout << i;

false

An infinite loop may execute indefinitely.

True

In the for statement, if the loop condition is omitted, it is assumed to be false.

False

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

True

A syntax error will result if the control statements of a for loop are omitted.

False

An EOF-controlled while loop is another name for a sentinel-controlled while loop.

False

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

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

Loop Continue Test

A loop is a control structure that allows you to repeat a set of statements until certain conditions are met.

True

Which of the following 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;

The following while loop terminates when j > 20.

j = 0;
while (j < 20)

False

Share This
Flashcard

More flashcards like this

NCLEX 10000 Integumentary Disorders

When assessing a client with partial-thickness burns over 60% of the body, which finding should the nurse report immediately? a) ...

Read more

NCLEX 300-NEURO

A client with amyotrophic lateral sclerosis (ALS) tells the nurse, "Sometimes I feel so frustrated. I can’t do anything without ...

Read more

NASM Flashcards

Which of the following is the process of getting oxygen from the environment to the tissues of the body? Diffusion ...

Read more

Unfinished tasks keep piling up?

Let us complete them for you. Quickly and professionally.

Check Price

Successful message
sending