Computing Lab 2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which of the following is not a good reason for choosing a certain loop control? A) if the loop is in a function B) the minimum number of iterations of the loop C) the condition for ending the loop D) what the loop does

A

Which of the following symbols has the highest precedence? A) ++ B) && C) || D) -

A

27) Which boolean operation is described by the following table? ...A............B.........Operation True......True..........True True.....False.........False False.....True.........False False...False.........False A) or B) not C) and D) none of the above

C

Given the following enumerated data type definition, what is the value of SAT? enum myType {SUN, MON, TUE, WED, THUR, FRI, SAT, NumDays}; A) 5 B) 7 C) 6 D) 8 E) unknown

C

If x is 0, what is the value of (!x = = 0)? A) true B) unable to determine C) false D) undefined

C

What is wrong with the following switch statement? int ans; cout < < "Type y for yes on n for no\n"; cin > > ans; switch (ans) { case 'y': case 'Y': cout < < "You said yes\n"; break; case 'n': case 'N': cout < < "You said no\n"; break; default: cout < <"invalid answer\n"; } A) break; is illegal syntax. B) There are no break statements on 2 cases. C) ans is a int. D) nothing

C

13) What is the output of the following code fragment? { int x = 13; cout < < x < <","; } cout < < x < < endl; A) 0,13 B) 13,0 C) 13,13 D) Nothing, there is a syntax error.

D

22) Which loop structure always executes at least once? A) while B) for C) sentinel D) do-while

D

Given the following code, what is the final value of i? int i; for(i = 0; i < = 4;i ++ ) { cout < < i < < endl; } A) 5 B) 0 C) 3 D) 4

D

What is the output of the following code fragment? int i = 5; switch(i) { case 0: i = 15;break; case 1: i = 25;break; case 2: i = 35;break; case 3: i = 40; default: i = 0; } cout < < i < <endl; A) 35 B) 15 C) 25 D) 0 E) 40

D

What is the value of x after the following code executes? int x = 10; if( ++ x > 10) { x = 13; } A) 10 B) 11 C) 9 D) 13

D

What is wrong with the following for loop? for(int i = 0;i < 10;i - - ) { cout < < "Hello\n"; } A) cannot use a for-loop for this B) i is not initialized. C) off-by-one error D) infinite loop

D

Which of the following are equivalent to (!(x < 15 && y > = 3))? A) (x > = 15 && y < 3) B) (x > 15 || y < 3) C) (x > 15 && y < = 3) D) (x > = 15 || y < 3) E) C and D

D

When testing a program with a loop, which of the following tests should be done? A) the maximum number of iterations B) no iterations of the loops C) one less than the maximum number of iterations D) one more than the maximum number of iterations E) A, B, and C

E

Which of the following are allowed in the third section of the for loop statement? A) i - - B) i += 2 C) i ++ D) cout < < "Hello\n" E) all of the above

E

Which of the following data types can be used in a switch controlling expression? A) enum B) char C) float D) int E) A, B, and D

E

Which of the following data types may be used in a switch statement? A) char B) enum C) int D) long E) all of the above

E

(T/F) A boolean expression may evaluate to more than 2 values.

False

(T/F) A break statement in a switch stops your program.

False

(T/F) All nested if-else statements can be converted into switch statements.

False

(T/F) In an enumerated data type, different constants may not have the same value.

False

(T/F) It is illegal to make function calls inside a switch statement.

False

(T/F) The break statement causes all loops to exit.

False

What is the value of x after the following code executes? int x = 10; if(x ++ > 10) { x = 13; } A) 9 B) 10 C) 11 D) 13

B

19) If a programming language does not use short-circuit evaluation, what is the output of the following code fragment if the value of myInt is 0? int other = 3, myInt; if(myInt != 0 && other % myInt != 0) cout < < "other is odd\n"; else cout < < "other is even\n"; A) run-time error, no output B) other is odd C) 0 D) other is even

A

Given the following code, what is the final value of i? int i,j; for(i = 0;i < 4;i ++) { for(j = 0;j < 3;j ++ ) { if(i = = 2) break; } } A) 4 B) 3 C) 0 D) 5

A

If you need to write a do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the user enters a correct number, what is the loop condition? A) (2 > number || number > 5) B) (2 < = number && number < = 5) C) (2 < 5 < number) D) (2 > number && number > 5) E) (2 < = num < = 5)

A

If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test? A) (x > = 10 || y < = 3) B) (x > =10 && y < = 3) C) (x > 10 || y < 3) D) (x < 10 && y > 3)

A

What is the output of the following code fragment? int x = 0; { int x = 13; cout < < x < <","; } cout < < x < < endl; A) 13,0 B) 13,13 C) 0,13 D) Nothing, there is a syntax error.

A

What is the value of the following expression? (true && (4/3 || !(6))) A) true B) illegal syntax C) false D) 0

A

Which of the following are valid case statements in a switch? A) case 1: B) case 1.5: C) case 'ab': D) case x < 4:

A

Which boolean operation is described by the following table? ..A............B...........Operation True.....True.............True True....False............True False....True.............True False...False...........False A) not B) or C) and D) none of the above

B

Which of the following boolean expressions tests to see if x is between 2 and 15 (including 2 and 15)? A) (x < = 15 || x > = 2) B) (x > = 2 && x < = 15) C) (2 < = x < = 15) D) (2 < = x || x < = 15)

B

What is the output of the following code fragment if x is 15? if(x < 20) if(x < 10) cout < < "less than 10 "; else cout < < "large\n"; A) nothing B) large C) less than 10 D) no output, syntax error

B

26) Given the following enumerated data type definition, what is the value of SAT? enum myType {SUN=3, MON=1, TUE=3, WED, THUR, FRI, SAT, NumDays}; A) 5 B) 7 C) 6 D) 8 E) unknown

B

How many times is "Hi" printed to the screen? for(int i = 0;i < 14;i ++ ); cout < < "Hi\n"; A) 15 B) 1 C) 14 D) 13

B

(T/F) A semicolon by itself is a valid C++ statement

True

(T/F) All switch statements can be converted into nested if-else statements.

True

A compound statement that contains variable declarations is called a ___

block

A ___ expression is an expression that can be thought of as being true or false

boolean

The code following the ___ case is executed if none of the other cases are matched in a switch statement

default

A ___ loop always executes the loop body at least once, regardless of the condition

do-while

___ is a type whose values are defined by a list of constants of type int

enumerated type

A switch statement variable must be ___

integer type

Each repetition of a loop body is called ___.

iteration

Variables defined inside a set of braces are said to be ___ to that block of code

local variables

The compiler always pairs an else with ___

nearest if

A loop that iterates one too many or one too few times is said to be ___

off-by-one


संबंधित स्टडी सेट्स

Database Foundations Final Practice Test

View Set

Chapter 10. Nursing Care of Patients in Pain

View Set

International Business Exam Questions

View Set

Management Accounting quiz 4 (Chapter 9)

View Set