COSC 1436 Practice

7 September 2022
4.7 (114 reviews)
50 test answers

Unlock all answers in this set

Unlock answers (46)
question
In a __ control structure, the computer executes particular statements depending on some condition(s). a. looping b. repetition c. selection d. sequence
answer
c. selection
question
What does <= mean? a. less than b. greater than c. less than or equal to d. greater than or equal to
answer
c. less than or equal to
question
Which of the following is a relational operator? a = b. == c. ! d. &&
answer
b. ==
question
Which of the following is the "not equal to" relational operator? a. ! b. I c. != d. &
answer
c. !=
question
Suppose x is 5 and y is 7. Choose the value of the following expression: (x ! = 7) & & (x <= y) a. false b. true c. 0 d. null
answer
b. true
question
Suppose that x is an int variable. Which of the following expressions always evaluates to true? a. (x > 0) I I (x <= 0) b. (x >= 0) I I (x == 0) c. (x > 0) && ( x <= 0) d. (x > 0) & & (x == 0)
answer
a. (x > 0) I I (x <= 0)
question
Which of the following operators has the highest precedence? a. ! b. * c. % d. =
answer
a. !
question
Which of the following operators has the lowest precedence? a. ! b. II c. && d. =
answer
d. =
question
Which of the following expressions correctly determines that x is greater than 10 and less than 20? a. 10 < x < 20 b. ( 1 0 < x < 20) c. 10 < x & & x < 20 d. 10 < x I I x < 20
answer
c. 10 < x & & x < 20
question
The expression in an if statement is sometimes called a(n) __ . a. selection statement b. action statement c. decision maker d. action maker
answer
c. decision maker
question
What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout « x « " " « y « " " « z « endl; a. 35 45 80 b. 35 45 10 c. 35 45 -10 d. 35 45 0
answer
b. 35 45 10
question
When one control statement is located within another, it is said to be __ . a. blocked b. compound c. nested d. closed
answer
c. nested
question
What is the output of the following code? if (6 > 8) { cout « " ** " « endl ; cout « "****" « endl; } else if (9 == 4) cout « "***" « endl; else cout « "*" « endl; a. * b. ** c. *** d ****
answer
a. *
question
To develop a program, you can use an informal mixture of C++ and ordinary language, called __ . a. assert code b. pseudocode c. cppcode d. source code
answer
b. pseudocode
question
Which of the following will cause a logical error if you are trying to compare x to 5? a. if (x == 5) b. if (x = 5) c. if (x <= 5) d. if (x >= 5)
answer
b. if (x = 5)
question
The appearance of = in place of == resembles a(n) __ . a. syntax error b. silent killer c. compilation error d. input failure
answer
b. silent killer
question
The conditional operator ? : takes __ arguments. a. two b. three c. four d. five
answer
b. three
question
What is the value of x after the following statements execute? int x; x = (5 <= 3 & & 'A' < 'F') ? 3 : 4 a. 2 b. 3 c. 4 d. 5
answer
c. 4
question
Assume you have three int variables: x = 2, Y = 6 , and z. Choose the value of z in the following expression: z = ( y / x > 0) ? x : y; a. 2 b. 3 c. 4 d. 6
answer
a. 2
question
What is the output of the following code? char lastlnitial = 'S'; switch (lastlnitial) { case 'A': cout « "section 1" «endl; break; case 'E': cout « "section 2" «endl; break; case 'C': cout « "section 3" «endl; break; case 'D': cout « "section 4" «endl; break; default: cout « "section 5" «endl; } a. section 2 b. section 3 c. section 4 d. section 5
answer
d. section 5
question
What is the output of the following code? char lastlnitial = 'A'; switch (lastlnitial) { case 'A': cout « "section 1" «endl; break; case 'E': cout « "section 2" «endl; break; case 'C': cout « "section 3" «endl; break; case 'D': cout « "section 4" «endl; break; default: cout « "section 5" «endl; } a. section 1 b. section 2 c. section 3 d. section 5
answer
a. section 1
question
What is the output of the following code fragment if the input value is 4? int num; int alpha = 10; cin » num; switch (num) { case 3: alpha++; break; case 4: case 6: alpha = alpha + 3;case 8: alpha = alpha + 4; break; default: alpha = alpha + 5; } cout « alpha « endl; a. 13 b. 14 c. 17 d. 22
answer
a. 13
question
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 4: break; case 5: case 6: y = y - 3; } cout « y « endl; a. 2 b. 5 c. 8 d. 10
answer
a. 2
question
For a program to use the assert function, it must include which of the following? a. #include c. #include b. #include d. #include NDEBUG
answer
b. #include
question
You can disable assert statements by using which of the following? a. #include b. #define c. #clear NDEBUG d. #define NDEBUG
answer
d. #define NDEBUG
question
In __ structures, the computer repeats particular statements a certain number of times depending on some condition(s). a. looping b. branching c. selection d. sequence
answer
a. looping
question
What is the output of the following C++ code? count = 1; num = 25; while (count < 25) { num = num - 1; count++; } cout « count « " " « num « endl; a. 24 0 b. 24 1 c. 25 0 d. 25 1
answer
d. 25 1
question
What is the output of the following C++ code? num = 10; while (num > 10) num = num - 2; cout « num « endl; a. 0 b. 6 c. 8 d. 10
answer
d. 10
question
A loop that continues to execute endlessly is called a(n) __ loop. a. end b. unlimited c. infinite d. definite
answer
c. infinite
question
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; a. 150 b. 155 c. 160 d. 165
answer
b. 155
question
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. a. flag-controlled b. counter-controlled c. BOF-controlled  d. sentinel-controlled
answer
b. counter-controlled
question
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; a. 92 b. 109 c. 110 d 119
answer
c. 110
question
A(n) __ -controlled while loop uses a bool variable to control the loop. a. counter b. sentinel c. flag d. BOF
answer
c. flag
question
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) __ loop. a. sentinel-controlled b. flag-controlled c.EOF-controlled d. counter-controlled
answer
c.EOF-controlled
question
What is the next Fibonacci number in the following sequence? 1, 1,2,3,5,8, 13,21, ... a. 34 b. 43 c. 56 d. 273
answer
a. 34
question
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; a. i = 1; b. i < 20; c. i ++ ; d cout « "Hello World";
answer
a. i = 1;
question
What is the output of the following C++ code? int j; for (j = 10; j <= 10; j++) cout « j « " "; cout « j « endl; a. 10 b. 10 10 c. 10 11 d. 11 11
answer
c. 10 11
question
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 b. 25 c. 41 d. 42
answer
a. 24
question
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; a. 124 b. 125 c. 126 d 127
answer
b. 125
question
Which executes first in a do ... while loop? a. statement b. loop condition c. initial statement d. update statement
answer
a. statement
question
What is the value of x after the following statements execute? int x = 5; int y = 30; do x = x * 2; while (x < y); a. 5 b. 10 c. 20 d. 40
answer
d. 40
question
What is the output of the following loop? count = 5; cout « 'St'; do { cout « '0'; count--; } while (count <= 5); a. St b. Sto c. Stop d. This is an infmite loop.
answer
d. This is an infmite loop.
question
__ loops are called post-test loops. a. break b. for c. while d. do ... while
answer
d. do ... while
question
Which of the following loops is guaranteed to execute at least once? a. counter-controlled while loop b. for loop c. do ... while loop d. sentinel-controlled while loop
answer
c. do ... while loop
question
Which of the following loops does not have an entry condition? a. BOF-controlled while loop b. sentinel-controlled while loop c. do ... while loop d. for loop
answer
c. do ... while loop
question
Which of the following is a repetition structure in C++? a. if b. switch c. while ... do d. do ... while
answer
d. do ... while
question
Which of the following is true about a do ... while loop? a. The body of the loop is executed at least once. b. The logical expression controlling the loop is evaluated before the loop is entered. c. The body of the loop may not execute at all. d. It cannot contain a break statement.
answer
a. The body of the loop is executed at least once.
question
Which of the following is not a function of the break statement? a. To exit early from a loop b. To skip the remainder of a switch structure c. To eliminate the use of certain bool variables in a loop d. To ignore certain values for variables and continue with the next iteration of a loop
answer
d. To ignore certain values for variables and continue with the next iteration of a loop
question
Which executes immediately after a continue statement in a while and do-while loop? a. loop-continue test b. update statement c. loop condition d. the body of the loop
answer
a. loop-continue test
question
When a continue statement is executed in a __ ' the update statement always executes. a. while loop b. for loop c. switch structure d. do ... while loop
answer
b. for loop