QUIZ 2 Flashcards
int limit;
int reps =0;
cin»limit;
while (reps <limit)
{
cin»_space; entry;
triple = entry*3;
cout «_space;triple;
reps++;
}
cout«endl;
This code is an example of a(n) ________ while loop.
counter-controlled
Putting in front of a logical expression reverses the value of that logical expression
!
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)
if(x=5)
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;
110
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;
2
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;
2
What is the output of the following C++ code?
num=10;
while (num>10)
num=num-2;
cout «_space;num «_space;endl;
10
Consider the following code.
Int limit
Int reps =0;
Cin»_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.
Counter-controlled
In C++, the operators != and == have the same order of precedence.
True
Suppose x and is 5 and y is 7. Choose the value of the following expression:
(x != 7) && (x <= y)
True
When one control statement is located within another, it is said to be
nested
Which of the following statements generates a random number between 0 and 50?
srand(time(0));
num = rand() % 50;
A(n) ______-controlled while loop uses a bool variable to control the loop.
flag
Which of the following is a repetition structure in C++?
while…do
if
switch
do…while
do…while
A loop that continues to execute endlessly is called a(n) _______ loop.
infinite
Which of the following expressons correctly determines that x is greater than 10 and less than 20?
10<x && x<20
To generate a random number, you can use the function rand of the header file
cstdlib
What is the initial statement in the following for loop?
int i;
for (i=1; i<20; i++)
cout«”hello world”;
cout«”!” «_space;endl;
i=1
Which of the following is relational operator?
==
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
pass
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;
24
The control statements in the for loop include the initial statement, loop condition, and update statement.
true
Assume that all variables are properly declared. The following for loop executes 20 times.
for (i=0; i <= 20, i++)
cout «_space;1;
false
You can use either a(n) _________ to store the value of a logical expression.
an int variable or a bool variable
In a ____ control structure, the compute executes particular statements depending on some condition
Selection
In a switch statement, if the value of the expression does not match any of the case values, the statements following ____ label execute.
default
Suppose that x is an int variable. Which of the following expression always evaluates to true?
(x > 0) I I (x <= 0)
The value of the expression 6 < 5 || ‘g’ > ‘a’ && 7 < 4
is
false
What is the value of x after the following statements execute?
Int x;
X = (5 <= 3 && ‘A’ < ‘F’) ? 3 : 4
4
What is the output of the following C++ code?
count = 1;
num = 25;
while (count < 25)
{
num = num - 1;
count++;
}
cout «_space;count «_space;” “ «_space;num «_space;endl;
25 1