WorksheetsProgramming Logic and Design, 5th edition. Ch 5-8
Total questions: 126
Worksheet time: 2hrs 33mins
What is a repetition structure?
causes a statement or set of statements to execute repeatedly.
Writing a long sequence of statements can be time consuming
uses a true/false condition to control the number of times that it repeats.
What is an off-by-one error?
The series of values separated with commas
Because array subscripts start at 0 rather than 1, you have to be careful not to perform.
they do not allow a program to use an invalid array subscript
a loop iterates one time too many or one time too few.
This is a prewritten function that is built into a programming language.
standard function
library function
custom function
cafeteria function
Which type of loop repeats a statement or set of statements as long as the Boolean expression is false?
For
Do-Until
Do-While
While
The test condition in a While loop must always be an integer value.
True
False
Modules can be called from statements in the body of any loop.
True
False
How many times would the following loop iterate?
Set k = 1
Do
Display k
Set k = k + 1
Until k > 2
2
infinite
1
3
Can you store a mixture of data types in an array?
False
True
How many times would the following loop iterate?
Set k = 1
While k <= 5
Display k
End While
0
4
5
infinite
What is usually the first subscript in an array?
( - )
0
1
( _ )
A(n) ________ represents a special value that marks the end of a list of values.
counter
sentinel
Step
End For
Statements that appear between the While and End While clauses are known as the ________.
body of the loop
iteration values
loop
While statements
How many times would the following loop iterate?
Set k = 1
While k > 5
Display k
End While
0
5
infinite
4
What is a search algorithm?
is an Integer variable used as a loop counter
Boolean variable that is used as a flag
a simple technique for finding an item in an array.
a loop to sequentially step through an array, starting with the first element.
Accepting February 29 for input only in a leap year is a check that should be caught by a ________ check.
reasonableness
data
time
day
A loop that accumulates a total as it reads each number from a series is often said to keep a(n) ________.
maximum values
accumulation
average
running total
Which array element does the sequential search algorithm first look at?
If-Else
Loop
True/False
Set
What would display if the following pseudocode was coded and executed?
Declare String user = "Martha and George"Display substring(user, 1, 3)
art
a
M
Mar
What is a subscript?
allows you to store a group of items of the same data type together in memory
also known as indexes
Each element in an array is assigned a unique number
are used to identify specific elements in an array
Many programming languages let you assign an integer value to a real variable without causing an error.
True
False
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
You have a car green
You have a green car
You have a greencar
You have a cargreen
A(n) ________ is another term for input validation.
input error
error trap
input trap
type mismatch
What is an array size declarator?
a named storage location in memory.
a separate item that must be declared and individually processed
a nonnegative integer
If you ever need to modify the program so the array is a different size
Select all that apply. Which of the following is a check for data accuracy?
the user enters the number of hours watching movies in a given day
the user selects a username of any length, using any keyboard characters
the user enterss a phone number to be formatted as (555)555-5555
the user enters a number in an allowable range
Programs should be designed to inspect all input before processing that input.
True
False
A programmer is not permitted to use library functions for input validation.
True
False
Select all that apply. Which of the following is(are) mathematical functions?
pow
abs
sin
round
If the integer variable, number has the value 5, then the following statement would return 25 to result.
Set result = sqrt(number)
True
False
What is an array element?
is a named storage location in memory
The storage locations in an array are known as elements.
Each item in an array is called an element, and each element is accessed by its numerical index.
is an ordinary variable, it can hold only one value at a time.
In most languages, can the size of an array be changed while the program is running?
True
False
This part of a function definition specifies the data type of the value that the function returns.
header
footer
body
Return statement
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.
True
False
What is the value of r after the following statement is coded and executed?
Declare Integer i = 12Declare Real rSet r = toReal(i)
12.0
1.2
12
0.12
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
There is no check for uppercase Y or N.
There is nothing wrong with this pseudocode
The Boolean expression should be an OR, not AND
There is no priming read
Each element in a two-dimensional array has two subscripts.
True
False
A____-controlled loop uses a true/false condition to control the number of times that it repeats.
Boolean
condition
decision
count
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.
True
False
Which function could be used to validate that the correct data type was input for an amount of money?
random
isString
isReal
length
Which function returns a string that is within another string?
sudstring
contains
append
concatenate
Select all that apply. Which of the following are input validation error types?
inaccurate data
incorrect data type
unreasonable data
empty input
Which function could be used to simplify the process of string validation?
isReal
isString
lengh
toLower
A____ -controlled loop repeats a specific number of times.
Boolean
condition
decision
count
The purpose of ________ is to get the first input value for the validation of a loop.
GIGO
the priming read
the key
the first input value
Give a general description of the input validation process.
If the input is invalid, the program should discard it and prompt the user to enter the correct data
first just before the loop and then inside the loop.
purpose is to get the first input value that will be tested by the validation loop
If the test score is invalid, however, the expression will be true and the statements in the body of the loop will execute.
The priming read is placed ________ the loop.
before and inside
before
inside
below
Given the following statement, what is the subscript for the data value 92?
Declare Inter numbers[5] = 83, 92, 78, 94, 61
92
1
2
0
Checking for the accuracy of data, even when the user provides valid input, is part of input validation.
True
False
The function body follows the function header in a function definition.
True
False
What do computer programmers say about the fact that computers can't tell the difference between good and bad data?
garbage output comes from garbage input
bad in means bad data out
garbage input, garbage output
garbage in, garbage out
Each repetition of a loop is known as a(n)___.
cycle
revolution
orbit
iteration
If an array, names, consists of a list of usernames, then names[1] holds the value of the first username in the list.
True
False
This part of a function definition is comprised of one or more statements that are executed when the function is called.
header
footer
body
Return statement
Random numbers are useful in simulation programs where the computer must randomly decide how an object will behave.
True
False
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]
Amy
Your test score is:
94
Joe
Your test score is:
94
Amy
Your test score is:
83
Joe
Your test score is:
76
The While loop is a ____ type of loop.
pretest
posttest
post iterative
perqualified
To calculate the total of the values in an array, a loop is used with an accumulator variable.
True
False
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
65
89
88
98
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"
93
Not a valid number
"93"
93
Not a valid number
This term describes any mechanism that accepts input, performs some operation that cannot be seen on the input, and produces output.
Glass box
White box
Opaque box
Black box
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 random number is generated between 5 and 10
A random number is generated between 1 and 10
The numbers 5 and 10 are the arguments of the random number function
The needNumber variable will contain 5 values
Select all that apply. Which of the following types of programs might use random numbers?Correct!
Games
simulations
statistical analysis
grade calculation
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
There is no check for uppercase Y or N.
The Boolean expression should be an OR, not AND.
There is no priming read
There is nothing wrong with this pseudocode
When a function finishes executing, it returns a value back to the part of the program that called it.
True
False
While and For loops are considered pretest loops because they test the condition before processing the statement or statements in the loop body.
True
False
The following pseudocode is for a loop that will perform three iterations.
For start = 5 To 10 Steps 2
Do something
End For
True
False
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?
7
Seven
SIZE
Neves
The following pseudocode is for a loop that will perform three iterations.
For start = 6 To 2 Step -3
Do something
End
True
False
Why should you take care to choose a unique value as a sentinel?
A sentinel value must be unique enough that it will not be mistaken as a regular value in the list
the number of values in the list could be different each time the program is executed
When a program reads the sentinel value, it knows it has reached the end of the list, so the loop terminates
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?
SIZE
7
Integer
numbers
A program that calculates the total of a series of numbers typically has what two elements?
A variable that accumulates the total of the numbers as they are read.
The starting value that is used will depend on the situation.
The loop increments the counter variable by adding 1 to it.
A loop that reads each number in the series.
The statements that appear in the body of the loop are executed.
What does the phrase “garbage in, garbage out” mean?
is unaware of this fact, and the program processed the bad data just as if it were good data
GIGO
refers to the fact that computers cannot tell the difference between good data and bad data
design your programs in such a way that bad input is never accepted
One drawback to the sequential search is that it cannot be used with an array that contains string elements.
True
False
Should an accumulator be initialized to any specific value?
Why or why not?
Yes, starting at 1 will give the correct total when the loop finishes
Yes, starting with anu value other than 0, it will contain the correct total when the loop finishes.
No, accumulator those not start with a number at all but a dash sign (-)
No, as soon as you initialize the accumulator variable, the code know what you what it as.
Unlike variables, arrays need to be initialized separately from the declaration.
True
False
What is an accumulator?
The program would read the sales for each day as input and calculate the total of those numbers
The number variable, declared in line 3, will be used to hold a number entered by the user
The variable used to keep the running total
The counter variable, declared in line 10, will be used as a counter by the loop.
When you increment a variable, what are you doing?
When you decrement a variable, what are you doing?
the loop increments the counter variable by adding 1 to it.
increase its value
flip negative and positive for each increment.
decrease its value
you specify a negative step value to decrement the counter variable
How many subscripts do you need to access one element in a two-dimensional array?
none
one
three
two
Select all that apply. When will the search in a sequential search stop?
When the search item is not found, and the end of the array is reached
It always goes through the entire array
When the counter reaches a negative value
When the search item is found
What three actions do count-controlled loops typically perform using the counter variable?
Increment
Initialization
count-controlled
Test
For loop
Two-dimensional arrays can be thought of as containing ________.
rows and columns
lines and boxes
rows and pages
elements and columns
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?
Set average = getAverage (studentScores)
Set average = getAverage (studentScores, 25)
Set average = getAverage (studentScores, 24)
Set getAverage = average (studentScores [25])
This is a string inside of another string.
substring
inner string
mini string
component string
An individual element in an array is identified by its ________.
subscript
value
integer
size
Subscripts are used to identify specific elements in an array.
True
False
What is a condition-controlled loop?
repeats a specific number of times
uses a true/false condition to control the number of times that it repeats
What type of error occurs when a loop through an array iterates one time too few or one time too many?
runtime error
syntax error
validation error
off-by-one error
What is a count-controlled loop?
repeats a specific number of times
uses a true/false condition to control the number of times that it repeats
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.
True
False
Does the While loop test its condition before or after it performs an iteration?
Before
After
Between
Never
In pseudocode, this statement causes a function to end and sends a value back to the part of the program that called the function.
End
Send
Exit
Return
Validation loops are also known as
error traps
doomsday loops
error avoidance loops
defensive programming loops
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?
SIZE
Interger
Real
N/A
What is an infinite loop?
A loop that cannot be terminated until proven false
A loop that continues to repeat until the program is interrupted
Does the Do-While loop test its condition before or after it performs an iteration?
Before
After
Between
Never
What is the difference between a pretest loop and a posttest loop?
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
The Do-While loop, it performs an iteration before testing its condition
The While loop, it tests its condition before performing an iteration
The While loop, Any loop that can be written as a Do-While loop can also be written as a While loop
What is a loop iteration?
When the loop executes, the condition is tested
If the condition is false, the program exits the loop
Each execution of the body of a loop
The term parallel array is a synonym for a two-dimensional array.
True
False
What is the difference between a Do-While loop and a Do-Until loop?
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
The Do-While loop is a pretest loop. The Do-While loop always performs no iteration, if its condition is false to begin with
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
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
This type of error occurs when you try to assign a value of one data type to a variable of another data type.
type mismatch error
Boolean logic error
relational error
bit conversion error
________ 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.
Two-dimensional
Sequential
Binary
Parallel
The input operation that appears just before a validation loop is known as the
prevalidation read
primordial read
initialization read
priming read
Why are library functions like “black boxes”?
any mechanism that accepts input
you do not see the internal workings of library functions
performs some operation that cannot be seen on the input
produces output
What is the purpose of the Return statement in a function?
A local variable named monthlySales is declared in line 32.
A person with $30,000 in monthly sales will earn an 18 percent commission ($5,400).
It specifies the value that is returned from the function when the function ends.
The term empty input describes what happens when
the user presses the Spacebar and then the Enter key
an input operation attempts to read data, but there is no data to read
the user enters 0 when 0 is an invalid value
the user enters any invalid data as input
This type of function returns either True or False.
Binary
TrueFalse
Boolean
logical
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.
sentinel
flag
signal
accumulator
What is a library function?
make a programmer’s job easier
they perform many of the tasks that programmers commonly need to perform
Most programming languages come with a library of functions that have already been written
GIGO stands for
great input, great output
garbage in, gardage out
GIGahertz Output
GIGabyte Operation
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?
99
7
8
6
What is a counter variable?
simply counter
A count-controlled loop uses a variable
to store the number of iterations that it has performed
comparing it to a maximum value
What is a sentinel?
Ask the user at the beginning of the program how many items the list contains
special value that marks the end of a list of values.
You have been asked to design a program that the clerk can use to perform these calculations
This is a design tool that describes the input, processing, and output of a function.
hierarchy chart
IPO chart
datagram chart
data processing
The integrity of a program’s output is only as good as the integrity of the program’s
compiler
programming language
input
debugger
What does “array bounds checking” mean?
they do not allow a program to use an invalid array subscript
a loop iterates one time too many or one time too few
typically happens at runtime, which is while the program is running
the subscript 0, but it iterates one too many times, ending with the subscript 100
A(n) ____ loop has no way of ending and repeats until the program is interrupted.
indeterminate
interminable
infinite
timeless
What is the term used for the number inside the brackets of an array that specifies how many values the array can hold?
size declarator
size initializatino
number declarator
subscript declarator
Which of the following array declarations would be best suited for storing prices of items sold in a store?
Declare String itemPrice [SIZE]
Declare itemPrice [Real]
Declare Integer itemPrice [SIZE]
Declare Real itemPrice [SIZE]
A(n)____variable keeps a running total.
sentinel
sum
total
accumulator
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.
time
day
reasonableness
date
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"
Impossible! Enter an age greater than 0:
Thank you
Thank you
Thank you.
Impossible! Enter an age greater than 0:
Impossible! Enter an age greater than 0:
A _____ loop always executes at least once.
pretest
postest
condition-controlled
count-controlled
The For loop is a ____ type of loop.
Pretest
Posttest
Prequalified
Post iterative
This is an example of a data type conversion function in pseudocode.
sqrt
toReal
substring
isNumeric
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.
True
False
How does a function differ from a module?
A function is a module that returns a value back to the part of the program that called it.
a module is a group of statements that exist within a program for the purpose of performing a specific task.
A function is a special type of module
A programmer is not permitted to use library functions for input validation.
True
False
