Quiz6-Functions Flashcards

1
Q

Library functions are built into a programming language and can be called whenever they are needed.(T/F)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The input column in an IPO chart describes the process that the function performs on input data.(T/F)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Many programming languages let you assign an integer value to a real variable without causing an error(T/F)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Random numbers are useful in simulation programs where the computer must randomly decide how an object will behave(T/F)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The function body follows the function header in a function definition.(T/F)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The TO INTEGER function accepts a real number as its argument and preserves any fractional part in the returned number.(T/F)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When a function finishes executing, it returns a value back to the part of the program that called it.(T/F)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

If the string variable name has the value “Anne Marie”, then the following statement would return 9: (T/F)

Set number = length(name)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

If the string variable name has the value “Anne.Smith”, then the following statement would return annesmith. (T/F)

Set newName = toLower(name)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If the integer variable number has the value 5, then the following statement would return 25 to result.(T/F)

Set result = sqrt(number)

A

False: sqrt(5) would not be 25

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The following pseudocode would display: Hello, friend. (T/F)

Declare String str1=”Hello,”
Declare String str2=” friend”
Set message = append(str1,str2)
Display message

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A function ___________ specifies the return data type, name of the function and the parameter variable(s).

A

header

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which function accepts two strings as arguments and returns TRUE if the second string is contained in the first string or FALSE if not?

A

contains

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which function returns a string that is within another string?

A

substring

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which function joins two strings?

A

concatenate

17
Q

What is the value of y after the following statement is coded and executed, given that x = 25?

Set y = sqrt(x)

A

5

18
Q

What is the value of y after the following statement is coded and executed, given that x = 3?

Set y = pow(x, x)

A

27
bc (3^3)= 33=93=27

19
Q

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

A

C) 12.0

20
Q

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

A

C) You have a cargreen
append means to squish together

21
Q

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

A

function

22
Q

A function _________ comprises one or more statements that are executed when the function is called.

A

Body

23
Q

What is the data type of the value returned by the random function?

A) Real

B) String

C) Boolean

D) Integer

A

D) Integer

24
Q

The __________ function does the same thing as using the mathematical ^ operator.

A

“pow”

25
Q

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

A

B) type mismatch error

26
Q

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”

A

Not a Valid Number

27
Q

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

93

28
Q

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

A) 17
counting the characters including the spaces in the “Martha and George” adds to 17

29
Q

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

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

A

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

30
Q

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

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.