QUIZ 2 Flashcards

1
Q

int limit;
int reps =0;
cin»limit;

while (reps <limit)
{
cin&raquo_space; entry;
triple = entry*3;
cout &laquo_space;triple;
reps++;
}
cout«endl;

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

A

counter-controlled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Putting in front of a logical expression reverses the value of that logical expression

A

!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which of the following will causes a logical error if you are attempting to compare x to 5?

if (x==5)
if(x=5)
if(x>=5)
if(x<=5)

A

if(x=5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Suppose sum and num are int variables, 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;

A

110

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Assume you have three int variable: x =2 , y=6, and z. Choose the value of z in the following expression: z(y/x>0) ? x:y;

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

Int x =55;
Int y = 5;

Switch (x%7)
{
Case 0;
Case 1;
Y++;
Case 2:
Case 3:
Y=y+2;
Case 5:
Case 6:
Y=y-3;
}
Cout«y«endl;

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Consider the following code.
Int limit
Int reps =0;

Cin&raquo_space; limit

While (reps < limit)
{
Cin»entry;
Triple=entry*3;
Cout«triple;
Cout«triple;
Reps++;
}
Cout«endl;

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

A

Counter-controlled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In C++, the operators != and == have the same order of precedence.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Suppose x and is 5 and y is 7. Choose the value of the following expression:
(x != 7) && (x <= y)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When one control statement is located within another, it is said to be

A

nested

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which of the following statements generates a random number between 0 and 50?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

flag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

do…while

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

infinite

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which of the following expressons correctly determines that x is greater than 10 and less than 20?

A

10<x && x<20

17
Q

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

A

cstdlib

18
Q

What is the initial statement in the following for loop?
int i;
for (i=1; i<20; i++)
cout«”hello world”;
cout«”!” &laquo_space;endl;

A

i=1

19
Q

Which of the following is relational operator?

A

==

20
Q

Consider the following statemnets.

Int score;
String grade;

If (score >= 65)
Grade = “pass”;
Else
Grade = “fail”;

If score is equal to 75, the value of grade is

A

pass

21
Q

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;

A

24

22
Q

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

A

true

23
Q

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

A

false

24
Q

You can use either a(n) _________ to store the value of a logical expression.

A

an int variable or a bool variable

25
Q

In a ____ control structure, the compute executes particular statements depending on some condition

A

Selection

26
Q

In a switch statement, if the value of the expression does not match any of the case values, the statements following ____ label execute.

A

default

27
Q

Suppose that x is an int variable. Which of the following expression always evaluates to true?

A

(x > 0) I I (x <= 0)

28
Q

The value of the expression 6 < 5 || ‘g’ > ‘a’ && 7 < 4
is

A

false

29
Q

What is the value of x after the following statements execute?

Int x;
X = (5 <= 3 && ‘A’ < ‘F’) ? 3 : 4

A

4

30
Q

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

count = 1;
num = 25;
while (count < 25)
{
num = num - 1;
count++;
}
cout &laquo_space;count &laquo_space;” “ &laquo_space;num &laquo_space;endl;

A

25 1