wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming Logic and Design, 5th edition. Ch 5-8

Total questions: 126

Worksheet time: 2hrs 33mins

Name
Class
Date
1.
  1. What is a repetition structure?

a)

causes a statement or set of statements to execute repeatedly.

b)

Writing a long sequence of statements can be time consuming

c)

uses a true/false condition to control the number of times that it repeats.

2.

What is an off-by-one error?

a)

The series of values separated with commas

b)

Because array subscripts start at 0 rather than 1, you have to be careful not to perform.

c)

they do not allow a program to use an invalid array subscript

d)

a loop iterates one time too many or one time too few.

3.

This is a prewritten function that is built into a programming language.

a)

standard function

b)

library function

c)

custom function

d)

cafeteria function

4.

Which type of loop repeats a statement or set of statements as long as the Boolean expression is false?

a)

For

b)

Do-Until

c)

Do-While

d)

While

5.

The test condition in a While loop must always be an integer value.

a)

True

b)

False

6.

Modules can be called from statements in the body of any loop.

a)

True

b)

False

7.

How many times would the following loop iterate?

Set k = 1

Do

Display k

Set k = k + 1

Until k > 2

a)

2

b)

infinite

c)

1

d)

3

8.
  1. Can you store a mixture of data types in an array?

a)

False

b)

True

9.

How many times would the following loop iterate?

Set k = 1

While k <= 5

Display k

End While

a)

0

b)

4

c)

5

d)

infinite

10.
  1. What is usually the first subscript in an array?

a)

( - )

b)

0

c)

1

d)

( _ )

11.

A(n) ________ represents a special value that marks the end of a list of values.

a)

counter

b)

sentinel

c)

Step

d)

End For

12.

Statements that appear between the While and End While clauses are known as the ________.

a)

body of the loop

b)

iteration values

c)

loop

d)

While statements

13.

How many times would the following loop iterate?

Set k = 1

While k > 5

Display k

End While

a)

0

b)

5

c)

infinite

d)

4

14.
  1. What is a search algorithm?

a)

is an Integer variable used as a loop counter

b)

Boolean variable that is used as a flag

c)

a simple technique for finding an item in an array.

d)

a loop to sequentially step through an array, starting with the first element.

15.

Accepting February 29 for input only in a leap year is a check that should be caught by a ________ check.

a)

reasonableness

b)

data

c)

time

d)

day

16.

A loop that accumulates a total as it reads each number from a series is often said to keep a(n) ________.

a)

maximum values

b)

accumulation

c)

average

d)

running total

17.
  1. Which array element does the sequential search algorithm first look at?

a)

If-Else

b)

Loop

c)

True/False

d)

Set

18.

What would display if the following pseudocode was coded and executed?

Declare String user = "Martha and George"Display substring(user, 1, 3)

a)

art

b)

a

c)

M

d)

Mar

19.
  1. What is a subscript?

a)

allows you to store a group of items of the same data type together in memory

b)

also known as indexes

c)

Each element in an array is assigned a unique number

d)

are used to identify specific elements in an array

20.

Many programming languages let you assign an integer value to a real variable without causing an error.

a)

True

b)

False

21.

What would display if the following pseudocode is coded and executed?

Declare String str1 = "car"Declare String str2 = "green"Set message = append(str1, str2)Display "You have a " , message

a)

You have a car green

b)

You have a green car

c)

You have a greencar

d)

You have a cargreen

22.

A(n) ________ is another term for input validation.

a)

input error

b)

error trap

c)

input trap

d)

type mismatch

23.
  1. What is an array size declarator?

a)

a named storage location in memory.

b)

a separate item that must be declared and individually processed

c)

a nonnegative integer

d)

If you ever need to modify the program so the array is a different size

24.

Select all that apply. Which of the following is a check for data accuracy?

a)

the user enters the number of hours watching movies in a given day

b)

the user selects a username of any length, using any keyboard characters

c)

the user enterss a phone number to be formatted as (555)555-5555

d)

the user enters a number in an allowable range

25.

Programs should be designed to inspect all input before processing that input.

a)

True

b)

False

26.

A programmer is not permitted to use library functions for input validation.

a)

True

b)

False

27.

Select all that apply. Which of the following is(are) mathematical functions?

a)

pow

b)

abs

c)

sin

d)

round

28.

If the integer variable, number has the value 5, then the following statement would return 25 to result.

Set result = sqrt(number)

a)

True

b)

False

29.
  1. What is an array element?

a)

is a named storage location in memory

b)

The storage locations in an array are known as elements.

c)

Each item in an array is called an element, and each element is accessed by its numerical index.

d)

is an ordinary variable, it can hold only one value at a time.

30.
  1. In most languages, can the size of an array be changed while the program is running?

a)

True

b)

False

31.

This part of a function definition specifies the data type of the value that the function returns.

a)

header

b)

footer

c)

body

d)

Return statement

32.

If a user is asked to enter the number of widgets he or she wants to buy and enters "two", the program will automatically change the entry to an integer.

a)

True

b)

False

33.

What is the value of r after the following statement is coded and executed?

Declare Integer i = 12Declare Real rSet r = toReal(i)

a)

12.0

b)

1.2

c)

12

d)

0.12

34.

What is wrong with the following pseudocode that validates a user's entry?

Display "Do you want to play again? Enter y or n."

While toLower(choice) != "y" AND toLower(choice) != "n"

Display "Please answer y or n. Play again?"

Input choice

End While

a)

There is no check for uppercase Y or N.

b)

There is nothing wrong with this pseudocode

c)

The Boolean expression should be an OR, not AND

d)

There is no priming read

35.

Each element in a two-dimensional array has two subscripts.

a)

True

b)

False

36.

A____-controlled loop uses a true/false condition to control the number of times that it repeats.

a)

Boolean

b)

condition

c)

decision

d)

count

37.

Defensive programming is the practice of anticipating errors that can happen while a program is running and designing the program to catch and deal with those errors.

a)

True

b)

False

38.

Which function could be used to validate that the correct data type was input for an amount of money?

a)

random

b)

isString

c)

isReal

d)

length

39.

Which function returns a string that is within another string?

a)

sudstring

b)

contains

c)

append

d)

concatenate

40.

Select all that apply. Which of the following are input validation error types?

a)

inaccurate data

b)

incorrect data type

c)

unreasonable data

d)

empty input

41.

Which function could be used to simplify the process of string validation?

a)

isReal

b)

isString

c)

lengh

d)

toLower

42.

A____ -controlled loop repeats a specific number of times.

a)

Boolean

b)

condition

c)

decision

d)

count

43.

The purpose of ________ is to get the first input value for the validation of a loop.

a)

GIGO

b)

the priming read

c)

the key

d)

the first input value

44.

Give a general description of the input validation process.

a)

If the input is invalid, the program should discard it and prompt the user to enter the correct data

b)

first just before the loop and then inside the loop.

c)

purpose is to get the first input value that will be tested by the validation loop

d)

If the test score is invalid, however, the expression will be true and the statements in the body of the loop will execute.

45.

The priming read is placed ________ the loop.

a)

before and inside

b)

before

c)

inside

d)

below

46.

Given the following statement, what is the subscript for the data value 92?

Declare Inter numbers[5] = 83, 92, 78, 94, 61

a)

92

b)

1

c)

2

d)

0

47.

Checking for the accuracy of data, even when the user provides valid input, is part of input validation.

a)

True

b)

False

48.

The function body follows the function header in a function definition.

a)

True

b)

False

49.

What do computer programmers say about the fact that computers can't tell the difference between good and bad data?

a)

garbage output comes from garbage input

b)

bad in means bad data out

c)

garbage input, garbage output

d)

garbage in, garbage out

50.

Each repetition of a loop is known as a(n)___.

a)

cycle

b)

revolution

c)

orbit

d)

iteration

51.

If an array, names, consists of a list of usernames, then names[1] holds the value of the first username in the list.

a)

True

b)

False

52.

This part of a function definition is comprised of one or more statements that are executed when the function is called.

a)

header

b)

footer

c)

body

d)

Return statement

53.

Random numbers are useful in simulation programs where the computer must randomly decide how an object will behave.

a)

True

b)

False

54.

What would display if following statements are coded and executed?

Declare Integer scored[3] = 76, 94, 83

Declare String names[3] = "Joe", "Amy", "Pat"

Display names[1]

Display "Your test score is: ''

Display scores[2]

a)

Amy

Your test score is:

94

b)

Joe

Your test score is:

94

c)

Amy

Your test score is:

83

d)

Joe

Your test score is:

76

55.

The While loop is a ____ type of loop.

a)

pretest

b)

posttest

c)

post iterative

d)

perqualified

56.

To calculate the total of the values in an array, a loop is used with an accumulator variable.

a)

True

b)

False

57.

Given the following array declaration, what value is stored in testScores[2][0]?

Declare Integer testScores[3][3] = 66,77,88,

98, 87, 76,

65, 74, 89

a)

65

b)

89

c)

88

d)

98

58.

What would display if the following pseudocode was coded and executed?

Declare String grade = "93"

If isInteger (grade) Then

Set intGrade = stringToInteger (grade)

Display intGrade

Else

Display "Note a valid number"

a)

93

Not a valid number

b)

"93"

c)

93

d)

Not a valid number

59.

This term describes any mechanism that accepts input, performs some operation that cannot be seen on the input, and produces output.

a)

Glass box

b)

White box

c)

Opaque box

d)

Black box

60.

Select all that apply. Which of the statement(s) would be true if the following pseudocode was coded and executed?Declare Integer needNumberSet needNumber = random(5, 10)

a)

A random number is generated between 5 and 10

b)

A random number is generated between 1 and 10

c)

The numbers 5 and 10 are the arguments of the random number function

d)

The needNumber variable will contain 5 values

61.

Select all that apply. Which of the following types of programs might use random numbers?Correct!

a)

Games

b)

simulations

c)

statistical analysis

d)

grade calculation

62.

What is wrong with the following pseudocode that validates a user's entry?

Display "Do you want to play again? Enter y or n."

While toLower(choice) != "y" AND toLower (choice) != "n"

Display "Please answer y or n. Play again?"

Input choice

End While

a)

There is no check for uppercase Y or N.

b)

The Boolean expression should be an OR, not AND.

c)

There is no priming read

d)

There is nothing wrong with this pseudocode

63.

When a function finishes executing, it returns a value back to the part of the program that called it.

a)

True

b)

False

64.

While and For loops are considered pretest loops because they test the condition before processing the statement or statements in the loop body.

a)

True

b)

False

65.

The following pseudocode is for a loop that will perform three iterations.

For start = 5 To 10 Steps 2

Do something

End For

a)

True

b)

False

66.

Look at the following pseudocode and answer questions a through d.

Constant Integer SIZE = 7

Declare Real numbers [SIZE]

What is the size of the array?

a)

7

b)

Seven

c)

SIZE

d)

Neves

67.

The following pseudocode is for a loop that will perform three iterations.

For start = 6 To 2 Step -3

Do something

End

a)

True

b)

False

68.

Why should you take care to choose a unique value as a sentinel?

a)

A sentinel value must be unique enough that it will not be mistaken as a regular value in the list

b)

the number of values in the list could be different each time the program is executed

c)

When a program reads the sentinel value, it knows it has reached the end of the list, so the loop terminates

69.

Look at the following pseudocode and answer questions a through d.

Constant Integer SIZE = 7

Declare Real numbers [SIZE]

What is the name of the array that is being declared?

a)

SIZE

b)

7

c)

Integer

d)

numbers

70.
  1. A program that calculates the total of a series of numbers typically has what two elements?

a)
  • A variable that accumulates the total of the numbers as they are read.

b)
  1. The starting value that is used will depend on the situation.

c)

The loop increments the counter variable by adding 1 to it.

d)
  • A loop that reads each number in the series.

e)
  1. The statements that appear in the body of the loop are executed.

71.
  1. What does the phrase “garbage in, garbage out” mean?

a)

is unaware of this fact, and the program processed the bad data just as if it were good data

b)

GIGO

c)

refers to the fact that computers cannot tell the difference between good data and bad data

d)

design your programs in such a way that bad input is never accepted

72.

One drawback to the sequential search is that it cannot be used with an array that contains string elements.

a)

True

b)

False

73.
  1. Should an accumulator be initialized to any specific value?

  2. Why or why not?

a)

Yes, starting at 1 will give the correct total when the loop finishes

b)

Yes, starting with anu value other than 0, it will contain the correct total when the loop finishes.

c)

No, accumulator those not start with a number at all but a dash sign (-)

d)

No, as soon as you initialize the accumulator variable, the code know what you what it as.

74.

Unlike variables, arrays need to be initialized separately from the declaration.

a)

True

b)

False

75.
  1. What is an accumulator?

a)

The program would read the sales for each day as input and calculate the total of those numbers

b)

The number variable, declared in line 3, will be used to hold a number entered by the user

c)

The variable used to keep the running total

d)

The counter variable, declared in line 10, will be used as a counter by the loop.

76.
  1. When you increment a variable, what are you doing?

  2. When you decrement a variable, what are you doing?

a)
  1. the loop increments the counter variable by adding 1 to it.

b)

increase its value

c)

flip negative and positive for each increment.

d)

decrease its value

e)

you specify a negative step value to decrement the counter variable

77.

How many subscripts do you need to access one element in a two-dimensional array?

a)

none

b)

one

c)

three

d)

two

78.

Select all that apply. When will the search in a sequential search stop?

a)

When the search item is not found, and the end of the array is reached

b)

It always goes through the entire array

c)

When the counter reaches a negative value

d)

When the search item is found

79.
  1. What three actions do count-controlled loops typically perform using the counter variable?

a)

Increment

b)

Initialization

c)

count-controlled

d)

Test

e)

For loop

80.

Two-dimensional arrays can be thought of as containing ________.

a)

rows and columns

b)

lines and boxes

c)

rows and pages

d)

elements and columns

81.

Which is the correct way to pass an array named studentScores that holds 25 values to a function named getAverage and save the result to a variable named average?

a)

Set average = getAverage (studentScores)

b)

Set average = getAverage (studentScores, 25)

c)

Set average = getAverage (studentScores, 24)

d)

Set getAverage = average (studentScores [25])

82.

This is a string inside of another string.

a)

substring

b)

inner string

c)

mini string

d)

component string

83.

An individual element in an array is identified by its ________.

a)

subscript

b)

value

c)

integer

d)

size

84.

Subscripts are used to identify specific elements in an array.

a)

True

b)

False

85.
  1. What is a condition-controlled loop?

a)

repeats a specific number of times

b)

uses a true/false condition to control the number of times that it repeats

86.

What type of error occurs when a loop through an array iterates one time too few or one time too many?

a)

runtime error

b)

syntax error

c)

validation error

d)

off-by-one error

87.

What is a count-controlled loop?

a)

repeats a specific number of times

b)

uses a true/false condition to control the number of times that it repeats

88.

It is usually much easier to process a large number of items in an array than to process a large number of items that are stored in separate variables.

a)

True

b)

False

89.
  1. Does the While loop test its condition before or after it performs an iteration?

a)

Before

b)

After

c)

Between

d)

Never

90.

In pseudocode, this statement causes a function to end and sends a value back to the part of the program that called the function.

a)

End

b)

Send

c)

Exit

d)

Return

91.

Validation loops are also known as

a)

error traps

b)

doomsday loops

c)

error avoidance loops

d)

defensive programming loops

92.

Look at the following pseudocode and answer questions a through d.

Constant Integer SIZE = 7

Declare Real numbers [SIZE]

What data type are the array elements?

a)

SIZE

b)

Interger

c)

Real

d)

N/A

93.
  1. What is an infinite loop?

a)

A loop that cannot be terminated until proven false

b)

A loop that continues to repeat until the program is interrupted

94.
  1. Does the Do-While loop test its condition before or after it performs an iteration?

a)

Before

b)

After

c)

Between

d)

Never

95.

What is the difference between a pretest loop and a posttest loop?

a)

In the Do-While loop, make sure the Do clause and the While clause are aligned.

  • Indent the statements in the body of the loop

b)

The Do-While loop, it performs an iteration before testing its condition

c)

The While loop, it tests its condition before performing an iteration

d)

The While loop, Any loop that can be written as a Do-While loop can also be written as a While loop

96.
  1. What is a loop iteration?

a)

When the loop executes, the condition is tested

b)

If the condition is false, the program exits the loop

c)

Each execution of the body of a loop

97.

The term parallel array is a synonym for a two-dimensional array.

a)

True

b)

False

98.

What is the difference between a Do-While loop and a Do-Until loop?

a)

The Do-While loop is a posttest loop. the Do-While loop always performs at least one iteration, even if its condition is false to begin with

b)

The Do-While loop is a pretest loop. The Do-While loop always performs no iteration, if its condition is false to begin with

c)

A loop that iterates until a condition is false is known as a Do-Until loop, the Do-Until loop is a pretest loop, it will always iterate at least two times

d)

A loop that iterates until a condition is true is known as a Do-Until loop, the Do-Until loop is a posttest loop; it will always iterate at least one times

99.

This type of error occurs when you try to assign a value of one data type to a variable of another data type.

a)

type mismatch error

b)

Boolean logic error

c)

relational error

d)

bit conversion error

100.

________ arrays are two or more arrays that hold related data where each element of one array has the same subscript as a corresponding element in the other arrays.

a)

Two-dimensional

b)

Sequential

c)

Binary

d)

Parallel

101.

The input operation that appears just before a validation loop is known as the

a)

prevalidation read

b)

primordial read

c)

initialization read

d)

priming read

102.
  1. Why are library functions like “black boxes”?

a)

any mechanism that accepts input

b)

you do not see the internal workings of library functions

c)

performs some operation that cannot be seen on the input

d)

produces output

103.
  1. What is the purpose of the Return statement in a function?

a)

A local variable named monthlySales is declared in line 32.

b)

A person with $30,000 in monthly sales will earn an 18 percent commission ($5,400).

c)
  • It specifies the value that is returned from the function when the function ends.

104.

The term empty input describes what happens when

a)

the user presses the Spacebar and then the Enter key

b)

an input operation attempts to read data, but there is no data to read

c)

the user enters 0 when 0 is an invalid value

d)

the user enters any invalid data as input

105.

This type of function returns either True or False.

a)

Binary

b)

TrueFalse

c)

Boolean

d)

logical

106.

A(n)____is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list.

a)

sentinel

b)

flag

c)

signal

d)

accumulator

107.
  1. What is a library function?

a)

make a programmer’s job easier

b)

they perform many of the tasks that programmers commonly need to perform

c)

Most programming languages come with a library of functions that have already been written

108.

GIGO stands for

a)

great input, great output

b)

garbage in, gardage out

c)

GIGahertz Output

d)

GIGabyte Operation

109.

Look at the following pseudocode and answer questions a through d.

Constant Integer SIZE = 7

Declare Real numbers [SIZE]

What is the subscript of the last element in the array?

a)

99

b)

7

c)

8

d)

6

110.
  1. What is a counter variable?

a)

simply counter

b)

A count-controlled loop uses a variable

c)

to store the number of iterations that it has performed

d)

comparing it to a maximum value

111.
  1. What is a sentinel?

a)

Ask the user at the beginning of the program how many items the list contains

b)

special value that marks the end of a list of values.

c)

You have been asked to design a program that the clerk can use to perform these calculations

112.

This is a design tool that describes the input, processing, and output of a function.

a)

hierarchy chart

b)

IPO chart

c)

datagram chart

d)

data processing

113.

The integrity of a program’s output is only as good as the integrity of the program’s

a)

compiler

b)

programming language

c)

input

d)

debugger

114.
  1. What does “array bounds checking” mean?

a)

they do not allow a program to use an invalid array subscript

b)

a loop iterates one time too many or one time too few

c)

typically happens at runtime, which is while the program is running

d)

the subscript 0, but it iterates one too many times, ending with the subscript 100

115.

A(n) ____ loop has no way of ending and repeats until the program is interrupted.

a)

indeterminate

b)

interminable

c)

infinite

d)

timeless

116.

What is the term used for the number inside the brackets of an array that specifies how many values the array can hold?

a)

size declarator

b)

size initializatino

c)

number declarator

d)

subscript declarator

117.

Which of the following array declarations would be best suited for storing prices of items sold in a store?

a)

Declare String itemPrice [SIZE]

b)

Declare itemPrice [Real]

c)

Declare Integer itemPrice [SIZE]

d)

Declare Real itemPrice [SIZE]

118.

A(n)____variable keeps a running total.

a)

sentinel

b)

sum

c)

total

d)

accumulator

119.

If the user, when asked for his/her date of birth, enters a date in the future, this error should be caught by a ________ check.

a)

time

b)

day

c)

reasonableness

d)

date

120.

What would display if the following statements are coded and executed and the user enters 3 twice at the prompts?

Display "Enter your age: "

Input age

Do

Display "Impossible! Enter an age greater than 0:"

Input age

While age <= 0

Display "Thank you"

a)

Impossible! Enter an age greater than 0:

Thank you

b)

Thank you

c)

Thank you.

Impossible! Enter an age greater than 0:

d)

Impossible! Enter an age greater than 0:

121.

A _____ loop always executes at least once.

a)

pretest

b)

postest

c)

condition-controlled

d)

count-controlled

122.

The For loop is a ____ type of loop.

a)

Pretest

b)

Posttest

c)

Prequalified

d)

Post iterative

123.

This is an example of a data type conversion function in pseudocode.

a)

sqrt

b)

toReal

c)

substring

d)

isNumeric

124.

If a user is asked to enter the number of widgets he or she wants to buy, the isInteger function can be used to validate this input.

a)

True

b)

False

125.
  1. How does a function differ from a module?

a)

A function is a module that returns a value back to the part of the program that called it.

b)

a module is a group of statements that exist within a program for the purpose of performing a specific task.

c)

A function is a special type of module

126.

A programmer is not permitted to use library functions for input validation.

a)

True

b)

False