Quiz 3 C++

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

3.13 Bohm and Jacopini's work demonstrated that all programs could be written in terms of only three control statements, namely sequence, __________ and iteration.

Aa) selection

3.10 How many types of control statements exist in C? (a) 3 (b) 7 (c) 5 (d) 2

A

3.19 The __________ selection statement performs an action if a condition is true and skips that action if the condition is false. a) if b) when c) if...else d) switch

A

3.22 The __________ is called a single-selection statement. a) if b) when c) if...else d) switch

A

3.26 Which statement is true? a) Each of C's control statements is characterized as being single-entry, single-exit. b) Each of C's control statements is characterized as being single-entry, multiple-exit. c) Each of C's control statements is characterized as being multiple-entry, single-exit. d) Each of C's control statements is characterized as being multiple-entry, multiple-exit.

A

3.35 The conditional operator (?:) ________. (a) is the only ternary operator in C (b) is a unary operator (c) associates from left to right (d) accepts two operands

A

3.43 An uninitialized variable contains ________. (a) the value last stored in the memory location reserved for that variable (b) no value (c) a value of zero (d) a randomly assigned value

A

3.47 In indefinite iteration, an input value (a) should always be evaluated before being processed (b) should always be processed directly after it is entered (c) should never be modified (d) can be entered, processed, and evaluated in any order

A

3.55 Which of the following will not increment variable c by one? (a) c + 1; (b) c++; (c) ++c; (d) c += 1;

A

3.59 Which of the following statements is true? (a) A counter variable that stores only non-negative numbers should be declared as an unsigned integral type. (b) A counter variables that stores only non-negative numbers should be declared as a signed integral type. (c) The type of a counter does not matter (d)None of the above.

A

3.4 Pseudocode does not typically include __________.

A - definitions

3.16 Flowchart symbols are connected by arrows called __________.

A - flowlines

3.14 Which statement is true? a) Unless directed otherwise, the computer automatically executes C statements one before the other. b) The sequence structure is essentially built into C. c) A flowchart is a pseudocode representation of an algorithm or a portion of an algorithm. d) Like pseudocode, flowcharts are useful for developing and representing algorithms, although flowcharts are preferred by most programmers.

B

3.29 Indentation in the if selection statement is ________. (a) always mandatory (b) always optional (c) only mandatory if there is more than one statement following the if statement (d) only optional if there is more than one statement following the if statement

B

3.3 Which of the following is true of pseudocode programs? (a) they are executed by the computer (b) they help the programmer "think out" a program (c) they typically include definitions and all types of statements (d) all of the above are false

B

3.34 Which statement is false? a) A compound statement can be placed anywhere in a program that a single statement can be placed. b) The if selection statement can have only one statement in its body. c) A set of statements contained within a pair of braces ({and }) is called a compound statement. d) An if selection statement can have a compound statement in its body.

B

3.36 Which of the following will generate an error? (a) if (answer == 7) { puts("correct"); } else { puts("incorrect"); } (b) puts(answer == 7 ? "correct" : "incorrect"); (c) printf("%s\n", answer == 7 ? "correct" : "incorrect"); (d) answer == 7 ? puts("correct") : puts("incorrect");

B

3.39 The empty statement is represented by placing __________ where a statement would normally be. a) empty b) ; c) null d) :

B

3.45 Indefinite iteration is controlled by a (a) counter (b) sentinel value (c) data value (d) non-constant condition

B

3.53 If x = 3, which of the following sets xto 7? (a) x *= 4; (b) x += 4; (c) x =+ 4; (d) x + 4 = x;

B

3.56 In which of the following is y not equal to 5 after execution? Assume that x is equal to 4. (a) y = 5; (b) y = x++; (c) y = ++x; (d) y = x = 5;

B

3.58 Which of the following statements is true about undefined behavior, which can leave a system open to attack? (a) It's not possible to have undefined behavior when adding two integers. (b) Adding two integers can result in arithmetic overflow, which can cause undefined behavior. (c) You should not worry about undefined behavior in your programs. (d)None of the above

B

3.31 Which statement is true about the contents of a correct diamond symbol in a correct flowchart.

B - It must contain a condition or expression that can be either true or false.

3.38 Placing a semicolon after the parenthesized condition in an if statement leads to a __________ error in single-selection if statements and a __________ error in double-selection if statements.

B - logic, syntax

3.1 Specifying the order in which statements are to be executed in a computer program is called (a) an algorithm (b) transfer of control (c) program control (d) pseudocode

C

3.12 Various C statements enable you to specify that the next statement to be executed may be other than the next one in sequence. This is called __________. a) change of order b) instruction skipping c) transfer of control d) rerouting

C

3.20 The __________ selection statement performs an action if a condition is true and performs a different action if the condition is false. a) if b) when c) if...else d) switch

C

3.28 If grade has the value of 60 what will the following code print? if (grade >= 60) { puts("Passed"); } (a) nothing (b) 60 (c) Passed (d) puts("Passed");

C

3.32 A correct decision symbol has __________ flowlines emerging from it. a) 4 b) 3 c) 2 d) 1

C

3.33 Which of the following statements correctly prints "Passed" if the student's grade is greater than or equal to 60 and "Failed" if the student's grade is less than 60? [The quotes, of course, should not print.] a) printf("%s\n", grade >= 60 : "Passed" : "Failed"); b) grade >= 60 : puts("Passed ") ? puts("Failed "); c) printf("%s\n", grade >= 60 ? "Passed" : "Failed"); d) grade >= 60 ? puts("Passed ") ? puts("Failed ");

C

3.37 A statement is called a block if it ________. (a) is a compound statement (b) contains definitions (c) is a compound statement that contains definitions (d) does not contain definitions

C

3.40 What is wrong with the following loop? While (sum <= 1000) { sum = sum + 30; } (a) The parenthesis should be braces. (b) The braces around sum = sum +30; should be removed. (c) While should be while. (d) There should be a semicolon after While (sum <=1000).

C

3.41 How many times will the following program print hello? i = 1; while (i <= 10) { puts("hello"); } (a) 10 (b) 8 (c) an infinite number of times (d) 0

C

3.44 Counter-controlled iteration is often called _________ iteration be-cause the number of iterations is known before the loop begins executing. a) indefinite b) sentinel c) definite d) determinate

C

3.49 Which operation does not take place in the following example? int x = 21; double y = 6; double z = 14; y = x / z; x = 5.5 * y; (a) implicit conversion (b) promotion (c) explicit conversion (d) truncation

C

3.5 Which statement is false? a) Pseudocode is an artificial and informal language that helps you develop algorithms. b) Pseudocode is similar to everyday English. c) Pseudocode is an actual programming language. d) Pseudocode programs are not actually executed on computers.

C

3.50 Which of the following is not a synonym for "sentinel value." a) signal value b) dummy value c) counter value d) flag value

C

3.51 Having a loop within a loop is known as (a) recursion (b) doubling up (c) nesting (d) a redundancy

C

3.54 Which assignment expression is equivalent to c = c / 2 ? (a) c / = 2 (b) c / c = 2 (c)c /= 2 (d)c =/ 2

C

3.6 Which statement is false? a) Pseudocode helps you "think out" a program before attempting to write it in a programming language such as C. b) Pseudocode programs consist purely of characters so programmers may conveniently type pseudocode programs into a computer using an editor program. c) A carefully prepared pseudocode program is only a beginning; it still takes a tremendous amount of work to convert a pseudocode program into a C program. d) Pseudocode consists only of action statements.

C

3.7 Which of the following encompasses the other three? (a) sequence structure (b) iteration structure (c) control structure (d) selection structure

C

3.8 In a flowchart of an algorithm, what is the shape of the decision symbol? (a) circle (b) rectangle (c) diamond (d) rounded rectangle

C

3.9 Which of the following is an iteration statement? (a) if (b) if...else (c) do...while (d) switch

C

3.27 Any C program we'll ever need to build can be constructed from only __________ different control statements combined in only __________ ways.

C - 7, 2

3.2. The two key attributes of an algorithm are:

C - actions and order of actions

3.17 Small circle symbols in a flowchart are often called __________ symbols.

C - connector

3.11 Normally, statements in a program are executed one after the other in the order in which they are written. This is called __________ execution. a) inline b) seeking c) ordered d) sequential

D

3.21 The __________ selection statement performs one of many different actions, depending on the value of an expression. a) if b) when c) if...else d) switch

D

3.25 Which is not a C iteration statement? a) while b) do...while c) for d) do...for

D

3.42 Consider the following correct segment of a correct C program: p = 2; while (p < 2000) { p = 2 * p; } What is the value of p after this while loop completes its execution? a) 1023 b) 1024 c) 2047 d) 2048

D

3.46 A fatal logic error is always caused by: (a) not initializing variables before executing an iteration statement (b) choosing a sentinel value that is also a data value (c) using a counter variable in a calculation after the loop (d) an attempt to divide by zero

D

3.48 What is the final value of x after performing the following operations? int x = 21; double y = 6; double z = 14; y = x / z; x = 5.5 * y; (a) 8.25 (b) 5.5 (c) 5 (d) 8

D

3.52 Which statement is true? a) With nested control statements, the inner control statement is executed in sequence after the outer control statement completes its own execution. b) With nested control statements, the inner control statement is executed exactly once. c) Experience has shown that the most difficult part of solving a problem on a computer is converting an already correct algorithm to a C program. d) A double-selection statement can be nested in an iteration statement.

D

3.57 Which statement is true? a) The expression ++(a + 1) adds 2 to a. b) The expression **a multiplies a by 1. c) The ANSI standard for the C programming language specifies the order in which each operator's operands will be evaluated. d) The expression --(abc * 37) is a syntax error

D

3.15 The __________ flowchart symbol is also called the action symbol.

D - rectangle

3.24 The __________ is called a multiple selection statement.

D - switch

3.18 The diamond flowcharting symbol is also called the __________ symbol.

D -decision

3.30 The C compiler ignores __________ characters like blanks, tabs and newlines used for indentation and vertical spacing.

Dd) whitespace

3.23 The __________ is called a double selection statement.

c) if...else


Kaugnay na mga set ng pag-aaral

Одежда.EF Pre Unit 1C - Things you wear

View Set

Musculoskeletal Disorders Passpoint prepu

View Set

Domain III: Immediate and Emergency Care

View Set

Lecture 9 - Controlling for the effects of uncontrollable factors

View Set

Real Estate Dynamics CH 14 Quizzes - FINANCE

View Set

Psych 1010 Chapter 9: Defense Mechanisms

View Set