Final-Quizes7,8,9,10 Flashcards
textbook chapters 6,7,10, & 14
(7)An input validation loop is sometimes called an ERROR HANDLER(T/F)
True
(7)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(T/F)
False
(7) 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.(T/F)
True
(7)Programs should be designed to inspect all input before processing that input.(T/F)
True
(7)A priming read is needed when a pretest loop is executed.(T/F)
True
(7) A Boolean function can often be used to validate data(T/F)
True
(7) The most difficult input error to validate is an empty read.(T/F)
False
(7) Defensive programming is the practice of anticipating errors that an happen while a program is running and designing the program to catch and deal with those errors.(T/F)
True
(7) Checking for the accuracy of data, even when the user provides valid input, is part of input validation.(T/F)
True
(7) Checking that input data is reasonable is programmatically impossible.(T/F)
False
(7) Input validation is not needed if the program is well designed.(T/F)
False
(7) A programmer is not permitted to use library functions for input validation.(T/F)
False
(7) What do computer programmers say about the fact that computer can’t tell the difference between good and bad data?
Garbage in, Garbage out
(7-14) The purpose of _________ is to get the first input value for the validation of a loop.
The priming read
(7-15)Designing a program to avoid common errors is called ______________ programming.
defensive
(7)Input __________ is commonly done with a loop that iterates as long as an input variable contains bad data.
validation
(7)A(n) ____________ is another term for input validation.
Error Trap
(7) The priming read is placed __________ the loop.
before
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) date
B) time
C) reasonableness
C) reasonableness
Accepting February 29 for input only in a leap year is a check that should be caught by a ____________ check.
A) date
B) time
C) reasonableness
A) date
(7)Which function could be used to validate an entry for a user’s chosen name that must be between 4 and 12 characters?
legnth
(7-22) Which function could be used to validate that the correct data type was input for an amount of money?
A)isReal
B)isString
C)Legnth
A)isReal
(7) which function could be used to simplify the process of string validation?
A)isReal
B)isString
C)toLower
C) toLower
(7) 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:
B) Thank you.
Impossible! Enter an age greater than 0:
C) Impossible! Enter an age greater than 0:
Thank you.
C) Impossible! Enter an age greater than 0:
Thank you.
(7) What would display if the following statements are coded and executed and the user enters -3, at the first prompt, 0 at the next prompt, and 22 at the third prompt?
Display “Enter your age:”
Input age
While age <=0
Display “Impossible! Enter an age greater than 0:”
Input age
End While
Display “Thank you.”
A) Impossible! Enter an age greater than 0:
Impossible! Enter an age greater than 0:
Thank you.
B) Impossible! Enter an age greater than 0:
Impossible! Enter an age greater than 0:
Impossible! Enter an age greater than 0:
C) Thank you.
A) Impossible! Enter an age greater than 0:
Impossible! Enter an age greater than 0:
Thank you.
(7-26) 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 no priming read
C) The Boolean expression should be an OR, not AND
B) There is no priming read
(6-15) Which function returns a string that is within another string?
A) append
B) contains
C) substring
C) substring
(6-1) Library functions are built into a programming language and can be called whenever they are needed(T/F)
True
The input column in an IPO chart describes the process that the function performs on input data.(T/F)
False
The input column in an IPO chart describes the process that the function performs on input data.(T/F)
False
Many programming languages let you assign an integer value to a real variable without causing an error(T/F)
True
(6) Random numbers are useful in simulation programs where the computer must randomly decide how an object will behave.(T/F)
True
(6) Random numbers are useful in simulation programs where the computer must randomly decide how an object will behave.(T/F)
True
(6-5) The function body follows the function header in a function definition.(T/F)
True
(6-5) The function body follows the function header in a function definition.(T/F)
True
(6)The TO INTEGER function accepts a real number as its argument and preserves any fractional part in the returned number(T/F)
False
(6) When a function finishes executing, it returns a value back to the part of the program that called it.(T/F)
True
(6)If the string variable name has the value “Anne Marie”, then the following statement would return 9:(T/F)
Set number = legnth(name)
False
(6-9) If the string variable name has the value “Anne.Smith”, then the following statement would return annesmith.(T/F)
Set newName = toLower(name)
False
(6) If the string variable name has the value “Anne.Smith”, then the following statement would return annesmith. (T/F)
Set newName = toLower(name)
False
(6-10) If the integer variable number has the value 5, then the following statement would return 25 to result. (T/F)
Set result = sqrt(number)
False: sqrt(5) is not 25
Given an integer variable number, the only possible values for number that could result from the following statement are 1 and 2. (T/F)
Set number = random(0,2)
False
(6-12) The following pseudocode would display: Hello,friend.(T/F)
Declare String str1= “Hello,”
Declare String str2= “friend”
Set message = append(str1,str2)
Display Message
True
A function ___________ specifies the return data type, name of the function and the parameter variable(s).
header
(6)Which function accepts two strings as arguments and returns True if the second string is contained in the first string or FALSE if not?
contains
(6) Which function joins two strings?
concatenate
(6) What is the value of y after the following statement is coded and executed, given that x = 25?
Set y = sqrt(x)
5
What is the value of y after the following statement is coded and executed, given that x = 3?
Set y = pow(x,x)
27
bc (3^3)= 333= 9*3=27
What is the value of r after the following statement is coded and executed?
Declare integer i = 12
Declare Real r
Set r = toReal(i)
A)12
B)1.2
C)12.0
C) 12.0
(6-20) 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 greencar
B) you have a cargreen
B) you have a cargreen
(6-20) 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 greencar
B) You have a green car
C) you have a cargreen
C) you have a cargreen
append means to squish together
(6) A ___________ is a module that returns a value back to the part of the program that called it.
function
A function ___________ comprises one or more statements that are executed when the function is called
body
What is the data type of the value returned by the random function?
A) Real
B) String
C) Integer
C) Integer
(6) The ___________ function does the same thing as using the mathematical ^ operator.
“pow” function
(6-25) Which of the following errors will occur when attempting to assign a real value to an integer variable?
A) conversion error
B) type mismatch error
C) assignment error
B) type mismatch error
(6) What would display if the following pseudocode was coded and executed?
Declare String user = “Joey”
If isInteger(user) Then
Set IntUser= stringTointeger(user)
Display IntUser
Else
Display “Not a valid number”
Not a valid number
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 “Not a valid number”
A) 100
B) 93
C) Not a valid number
B) 93
(6) What would display if the following pseudocode was coded and executed
Declare String user = “Martha and George”
Declare Integer number
Set number = legnth(user)
Display number
A) 17
B) 15
C) Martha and George
A) 17
What would display if the following pseudocode was coded and executed?
Declare String user = “Martha and George”
Display substring (user, 1,3)
Art
bc count the characters starting from 0
the substring to be displayed are chars 1,2,3
A=1 R=2 T=3
(6-30) What would be the value of numS if the following pseudocode was coded and run?
Declare String prose = “She sells seashells at the seashore”
Declare Integer counter
Declare Integer numS = 0
For counter = 0 to legnth(prose)
If substring(prose, counter, counter) == “s” Then
Set numS = numS +1
End If
End For
A) 6
B) 8
C) 30
A) 6
bc prose has 5 chars + 1
is 6
(8-1)Subscripts are used to identify specific elements in an array.(T/F)
True
(8) Unlike variables, arrays need to be initialized separately from the declaration. (T/F)
False
(8) Array bounds checking happens at runtime. (T/F)
True
(8)The first step when calculating the average of all values in an array is to get the sum of all the values (T/F)
True
(8-5) If an array, names consists of a list of usernames, then names[1] holds the value of the first username in the list.(T/F)
False
name[0] holds the first name in the list.
(8) Each element in a two dimensional array has two subscripts. (T/F)
True
(8) To calculate the total of the values in an array, a loop is used with an accumulator variable.(T/F)
True
An array, like a variable, can hold only one value.(T/F)
False
(8)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. (T/F)
True
(8-10) The number of elements in an array is the value of the subscript of the last element in that array.(T/F)
False
(8) One drawback to the sequential search is that it cannot be used with an array that contains string elements.(T/F)
False
(8)The term “parallel array” is a synonym for a two-dimensional array.(T/F)
False
(8) An individual element in an array is identified by its ____________.
subscript
(8) A type of loop that exists in some programming languages specifically for stepping through an array and retreiving the value of each element is known as a ___________ loop.
A) Step
B) For Each
C) While Each
B) For Each
(8-15)
____________ arrays are two or more arrays that hold related date where each element of one array has the same subscript as a corresponding element in the other arrays.
paralell arrays
(8) Two-dimensional arrays can be thought as containing ____________.
rows and columns
(8) Every element in an array is assigned a unique number known as a(n) __________.
subscript
(8) 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
(8)When working with arrays, most programming languages perform ____________ to ensure that programs don’t use invalid subscripts.
array bounds checking
(8-20) What type of error occurs when a loop through an array iterates one time to few or one time too many?
A) runtime error
B) off-by-one error
C) validation error
B) off-by-one error
(8-21) How many subscripts do you need to access one element in a two-dimensional array?
Two
(8) In the following declaration, what is the data type of the elements in the array?
Declare Integer numbers[SIZE]
Integer
(8-23) Which of the following statements is true about this array declaration??
Declare Integer numbers[5] = 123,456,789,321,654
A) This is an error; there should be 6 integers in the array
B) This is an array declaration and initialization
C) None of these statements are true
B) This is an array declaration and initialization
Given the following statement, what is the subscript for the data value 92?
Declare Integer numbers[5] = 83,92,78,94,61
1 is the subscript
(8-25) Which of the following array declarations would be best suited for storing prices of items sold in a store?
A) Declare Integer itemPrice[SIZE]
B) Declare Real itemPrice[SIZE]
C) Declare String itemPrice[SIZE]
B) Declare Real itemPrice[SIZE]
(8) What would display if following statements are coded and executed?
Declare Integer scores[3]= 76,94,83
Declare String names[3]= “Joe”,”Amy”,”Pat”
Display names[1]
Display “Your test score is: “
Display scores[2]
A) Joe Your test score is: 94
B) Amy your test score is: 94
C) Amy your test score is: 83
C) Amy your test score is: 83
(8-27) 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, 25)
B) Set getAverage = average(studentScores[25])
C) Set average = getAverage(studentScores)
A) Set average = getAverage(studentScores,25)
(6-1) Library functions are built into a programming language and can be called whenever they are needed(T/F)
True
(6)The input column in an IPO chart describes the process that the function performs on input data.(T/F)
False
(6) If the string variable name has the value “Anne Marie”, then the following statement would return 9:(T/F)
Set number = legnth(name)
False
(6) If the string variable name has the value “Anne.Smith”, then the following statement would return annesmith. (T/F)
Set newName = toLower(name)
False
(6-10) If the integer variable number has the value 5, then the following statement would return 25 to result. (T/F)
Set result = sqrt(number)
False: sqrt(5) is not 25
(6-5) The function body follows the function header in a function definition.(T/F)
True
(6) Random numbers are useful in simulation programs where the computer must randomly decide how an object will behave.(T/F)
True
(6) What is the value of r after the following statement is coded and executed?
Declare integer i = 12
Declare Real r
Set r = toReal(i)
A)12
B)1.2
C)12.0
C) 12.0
(6)Many programming languages let you assign an integer value to a real variable without causing an error(T/F)
True
Given an integer variable number, the only possible values for number that could result from the following statement are 1 and 2. (T/F)
Set number = random(0,2)
False
(6)Which function accepts two strings as arguments and returns True if the second string is contained in the first string or FALSE if not?
contains
(6)The TO INTEGER function accepts a real number as its argument and preserves any fractional part in the returned number(T/F)
False
(6)A function ___________ specifies the return data type, name of the function and the parameter variable(s).
header
(6-15) Which function returns a string that is within another string?
substring
(6) When a function finishes executing, it returns a value back to the part of the program that called it.(T/F)
True