C# Quiz 5 (5.8-6.4.)

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

(True/False) If an increment or decrement operator is placed before a variable, it is referred to as the prefix increment or prefix decrement operator, respectively. If an increment or decrement opera¬tor is placed after a variable, it is referred to as the postfix increment or postfix decrement opera¬tor, respectively.

True

(True/False) It's possible to specify that a constant is of type decimal by appending the letter m to the constant.

True

(True/False) Many algorithms can be divided into an initialization phase, a processing phase and a termination phase.

True

(True/False) The for repetition statement handles the details of counter-controlled repetition.

True

(True/False) The sentinel value must be chosen so that it cannot be confused with an acceptable in¬put value

True

(True/False) Top-down, stepwise refinement helps lead to well-structured algorithms.

True

(True/False) Unary operators associate from right to left.

True

(True/False) Using top-down, stepwise refinement results in pseudocode that can be straightforwardly evolved into a C# program.

True

(True/False) Variables that store totals should generally be initialized to zero before being used in a program.

True

. (True/False) Modifying the control variable of a for statement in the body can cause errors.

True

(True/False) A loop that counts down from 10 to 1 using control variable counter should use the loop-continuation condition counter <= 1.

False

(True/False) A variable used only within a repetition statement should be declared within the statement.

False

(True/False) C# rounds fractional values when they're to be stored in an integer variable.

False

(True/False) Cast operators are used to perform implicit conversions between data types.

False

(True/False) Counting loops should be controlled with whatever data type most closely reflects the operations taking place, whether that is an int, float or double.

False

(True/False) Only one control variable may be initialized, incremented or decremented in a for statement header.

False

(True/False) Placing a space character between the symbols that compose an arithmetic assignment operator improves readability.

False

(True/False) Postincrementing a variable will delay the incrementing of a variable until the next time the variable is accessed.

False

(True/False) The C# operator ^ can be used for exponentiation.

False

(True/False) The cast operator is formed by enclosing a type name in braces.

False

(True/False) The initialization expression, condition and increment expression in a for statement's header must be separated with commas.

False

(True/False) The while statement is an example of a sequence structure.

False

(True/False) Unary operators (such as ++) cannot be used in conditions.

False

(True/False) When instance variables of the simple types are declared in a class, they're automatically assigned default values unless specified otherwise by the programmer. Variables of type bool and String are given null by default; everything else is assigned 0.

False

(True/False) When using top-down, stepwise refinement, only the last refinement is a com¬plete specification of the algorithm.

False

(True/False) You can create your own simple types.

False

(True/False) a -= 3 is equivalent to the expression a - a = 3.

False

(True/False) for statements cannot be represented as while statements.

False

(True/False) int division may yield a non-int result.

False

. (True/False) A while statement automatically increments a variable that a programmer specifies.

False

Counter-controlled repetition requires only a control variable, an initial value for the control variable and an increment or decrement.

False

A while statement allows you to specify that an action should repeat while: a) a specific condition remains false b) a specific condition remains true c) a specific condition remains either true or false d) None of the above.

b) a specific condition remains true

Which of the following terms is not used to refer to a sentinel value that breaks out of a while statement? a) signal value b) break value c) dummy value d) flag value

b) break value

A can be used in a repetition structure to control the number of times a set of statements will execute. a) declaration b) counter c) controller d) None of the above.

b) counter

What is typically the most difficult part of solving a problem on a computer? a) deciding what problem needs to be solved b) developing the algorithm for the solution c) producing a C# program from the algorithm d) None of the above.

b) developing the algorithm for the solution

Local variables must be ________. a) initialized when they are declared. b) initialized before their values are used in an expression. c) declared and initialized in two steps. d) declared at the top of the method.

b) initialized before their values are used in an expression.

. Counting loops should be controlled with values. a) double b) int c) char d) None of the above.

b) int

What is the size in bits of an int? a) 8 b) 16 c) 32 d) 64

c) 32

Which of the following operators associates from left to right? a) ++ b) ?: c) %= d) /

d) /

How many times is the body of the loop below executed? int counter = 1; while (counter > 20) { // body of loop counter = counter + 1; } a) 19 b) 20 c) 21 d) 0

d) 0

Which of the following generates a syntax error? a) c *= 3; b) c %= 2; c) c /= 4; d) None of the above.

d) None of the above.

Which statement is true? a) A while statement cannot be nested inside another while statement. b) An if statement cannot be nested inside another if statement. c) A while statement cannot be nested inside an if statement. d) None of the above.

d) None of the above.

Which of the following decrements the variable a by one? a) a-- b) a- c) --a d) a and c e) All of the above.

d) a and c

Which of the following is not one of the three phases that a program is typically split into using pseudocode? a) termination phase b) initialization phase c) processing phase d) action phase

d) action phase

Which of the following is not a simple type in C#? a) byte b) int c) bool d) bit

d) bit

Which primitive type can hold the largest value? a) int b) long c) float d) double

d) double

Which of the following will count down from 10 to 1 correctly? a) for (int j = 10; j <= 1; ++j) b) for (int j = 1; j <= 10; ++j) c) for (int j = 10; j > 1; --j) d) for (int j = 10; j >= 1; --j)

d) for (int j = 10; j >= 1; --j)

Which of the following segments will call the method readData four times? d) int i; i = 0; while (i < 4) { readData(); i = i + 1;

d) int i; i = 0; while (i < 4) { readData(); i = i + 1;

(True/False) A control variable that's declared in a for statement header is not accessible outside of the body of the for statement.

True

(True/False) A flag value should not be a legitimate data entry value.

True

(True/False) A variable used as a counter should be initialized when it's declared.

True

(True/False) Compressing statements before and in a for statement into the for header can reduce the readability of a program

True

(True/False) Counter-controlled repetition is often called definite repetition because the number of repetitions is known before the loop begins executing.

True

(True/False) If a while condition is never true, the body will never execute.

True

What is the resulting value of c at the end of the following code segment? int c = 8; c++; ++c; c %= 5; a) 0 b) 1 c) 3 d) None of the above

a) 0

In an activity diagram, the merge symbol has the same shape as what other symbol? a) decision symbol b) action symbol c) transition arrows d) initial state

a) decision symbol

Counter-controlled repetition is also known as: a) definite repetition b) indefinite repetition c) multiple-repetition structure d) double-repetition structure

a) definite repetition

It is known as when the number of repetitions is known before a loop begins executing. a) definite repetition b) infinite repetition c) total repetition d) None of the above.

a) definite repetition

The first line of the for statement is sometimes called the: a) for statement header b) increment header c) repetition header d) None of the above.

a) for statement header

Repetition in which the number of iterations is unknown before the loop begins executing is called ________. a) indefinite repetition b) controlled repetition c) top-down repetition d) None of the above.

a) indefinite repetition

In an expression containing values of the types int and double, the ________ values are ________ to ________ values for use in the expression. a) int, promoted, double. b) int, demoted, double. c) double, promoted, int. d) double, demoted, int.

a) int, promoted, double.

C and C++ are _______ typed languages. a) strongly b) moderately c) weakly d) the languages vary

a) strongly

Which of the following conditions would cause a while statement to stop executing? a) 3 <= 11 b) !(7 != 14) c) 6 != 9 d) All of the above.

b) !(7 != 14)

Which of the following for-loop control headers results in equivalent numbers of iterations: 1) for (int q = 1; q <= 100; ++q) 2) for (int q = 100; q >= 0; --q) 3) for (int q = 99; q > 0; q -= 9) 4) for (int q = 990; q > 0; q -= 90) a) 1) and 2) b) 3) and 4) c) 1) and 2) have equivalent iterations and 3 and 4 have equivalent iterations d) None of the loops have equivalent iterations

b) 3) and 4)

What does the expression x %= 10 do? a) Adds 10 to the value of x, and stores the result in x. b) Divides x by 10 and stores the remainder in x. c) Divides x by 10 and stores the integer result in x. d) None of the above.

b) Divides x by 10 and stores the remainder in x.

What is output by the following C# code segment? int temp = 180; while (temp != 80) { if (temp > 90) { Console.Write("This porridge is too hot! "); // cool down temp = temp - (temp > 150 ? 100 : 20); } else { if (temp < 70) { Console.Write("This porridge is too cold! "); // warm up temp = temp + (temp < 50 ? 30 : 20); } } } if (temp == 80) { Console.WriteLine("This porridge is just right!"); } a) This porridge is too cold! This porridge is just right! b) This porridge is too hot! This porridge is just right! c) This porridge is just right! d) None of the above.

b) This porridge is too hot! This porridge is just right!

Which of the following correctly represents the expression a = a + 3? a) 3a b) a += 3 c) a + 3 d) None of the above

b) a += 3

Which of the following is equivalent to this code segment? Segment: int total = 0; for (int i = 0; i <= 20; i += 2) { total += i; } a) int total = 0; for (int i = 20; i < 0; i += 1) { total += i; } b) int total = 0; for (int i = 0; i <= 20; total += i, i += 2); c) int total = 0; for (int i = 0, i <= 20, total += i; i += 2); d) int total = 0; for (int i = 2; i < 20; total += i, i += 2);

b) int total = 0; for (int i = 0; i <= 20; total += i, i += 2)

Which of the following is not a control statement in C#? a) do...while b) loop c) switch d) for

b) loop

A common logic error known as a(n) occurs when the programmer incor¬rectly specifies a conditional operator, such as < instead of <=. a) fatal error b) off-by-one error c) syntax error d) None of the above.

b) off-by-one error

Some compilers will automatically remove from loops body statements that do not need to be executed multiple times through a process known as . a) classification b) optimization c) interpretation d) None of the above.

b) optimization

The operator increases the value of the variable by 1 after the original value is used in the expression in which the variable appears. a) preincrement b) postincrement c) predecrement d) None of the above.

b) postincrement

Consider the following two C# code segments: Segment 1 Segment 2 int i = 0; for (int i=0; i <= 20; ++i) while (i < 20) { { Console.WriteLine (i); ++i; } Console.WriteLine (i); } Which of the following statements is true? a) The output from these segments is not the same. b) The scope of the control variable i is different for the two segments. c) Both (a) and (b) are true. d) Neither (a) nor (b) is true.

c) Both (a) and (b) are true.

Which statement is false? a) To ensure that the operands are of the same type, C# performs implicit conversion on selected operands. b) Cast operators are unary operators. c) Cast operators associate from right to left and are one level lower than the multiplicative operators. d) Cast operators are formed by placing parentheses around the name of a type.

c) Cast operators associate from right to left and are one level lower than the multiplicative operators.

Which of the following is not necessarily an error (either a syntax error or a logic error)? a) Neglecting to include an action in the body of a while statement that will eventually cause the condition to become false. b) Spelling a key word (such as while or if) with a capitalized first letter. c) Using a condition for a while statement that is initially false. d) An infinite loop.

c) Using a condition for a while statement that is initially false.

The header for (int i = 0; i <= 10; ++i) will cause i to be incremented: a) before the body begins execution b) after the body begins to execute, but before it finishes c) after the entire body executes d) None of the above.

c) after the entire body executes

When you know how many times a loop will execute in advance, a ________loop should be used. a) sentinel b) infinite c) counter-controlled d) None of the above.

c) counter-controlled

Floating-point numbers contain a fractional part and can be represented by the data type. a) frac b) real c) double d) None of the above.

c) double

Which of the following for headers is syntactically incorrect? a) for (int i = 1; i < 10;) b) for (; i == 3;) c) for (i == 3) d) None of the above.

c) for (i == 3)

A while statement can cause logic errors where the body never stops executing. This is known as a(n) . a) syntax error b) fatal error c) infinite loop d) None of the above.

c) infinite loop

A can be used in repetition structures to indicate the end of data entry. a) counter b) boolean c) sentinel value d) None of the above.

c) sentinel value


Set pelajaran terkait

LinkedIn Learning- Generative AI

View Set

(Ch. 7) Texas Principles of Real Estate Part 2

View Set

ME 383 Test 1_Metal Casting Processes

View Set

Bile-Acid Sequestrant and Fibrate Therapy

View Set

Science chapter 10 the periodic table

View Set

ATI Skills Module 3.0: Ostomy Care

View Set