Quiz6-Functions Flashcards
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
Many programming languages let you assign an integer value to a real variable without causing an error(T/F)
True
Random numbers are useful in simulation programs where the computer must randomly decide how an object will behave(T/F)
True
The function body follows the function header in a function definition.(T/F)
True
The TO INTEGER function accepts a real number as its argument and preserves any fractional part in the returned number.(T/F)
False
When a function finishes executing, it returns a value back to the part of the program that called it.(T/F)
True
If the string variable name has the value “Anne Marie”, then the following statement would return 9: (T/F)
Set number = length(name)
False
If the string variable name has the value “Anne.Smith”, then the following statement would return annesmith. (T/F)
Set newName = toLower(name)
False
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) would not be 25
Given an integer variable number, the only possible values for number that could result from the following statement are 1 and 2.
Set number = random(0,2)
False
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
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
Which function returns a string that is within another string?
substring
Which function joins two strings?
concatenate
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)= 33=93=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
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
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) Boolean
D) Integer
D) Integer
The __________ function does the same thing as using the mathematical ^ operator.
“pow”
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
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”
93
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
counting the characters including the spaces in the “Martha and George” adds to 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, and 3. therefore 1=A 2=R 3=T
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 program is looped to run 6 times (0-legnth of prose which is 5 chars +1 from 0)
Therefore when it counts 6 s even if its not done the prose the program will end.