I got a 41/50 on the final, and these are the questions I got wrong.

Question 50

Consider the following procedures for string manipulation.

Procedure Call Explanation concat(str1, str2) Returns a single string consisting of str1 followed by str2. For example, concat(“key”, “board”) returns “keyboard”. prefix(str, length) Returns the first length characters of str or str if length is greater than the number of characters in str. For example, prefix(“delivery”, 3) returns “del” and prefix(“delivery”, 100) returns “delivery”. The variable initials is to be assigned a string consisting of the first letter of the string firstName followed by the first letter of the string lastName. Which of the following assigns the correct string to initials ?

Question 47

Consider the following code segment.

The figure presents twelve blocks of code that consist of 12 total lines. Line 1: [begin block] a ← 10 [end block] Line 2: [begin block] b ← 20 [end block] Line 3: [begin block] c ← 30 [end block] Line 4: [begin block] d ← 40 [end block] Line 5: [begin block] x ← 20 [end block] Line 6: [begin block] b ← x plus b [end block] Line 7: [begin block] a ← x plus 1 [end block] Line 8: [begin block] d ← c plus d divided by 2 [end block] Line 9: [begin block] DISPLAY [begin block] a [end block] [end block] Line 10: [begin block] DISPLAY [begin block] b [end block] [end block] Line 11: [begin block] DISPLAY [begin block] c [end block] [end block] Line 12: [begin block] DISPLAY [begin block] d [end block] [end block] What is displayed as a result of executing the code segment?

Question 46

Consider the following code segment.

The figure presents four blocks of code that consist of 4 lines. Line 1: [begin block] first ← true [end block] Line 2: [begin block] second ← false [end block] Line 3: [begin block] second ← first [end block] Line 4: [begin block] first ← second [end block] What are the values of first and second as a result of executing the code segment?

Question 45

Consider the following code segment.

theList ← [-2, -1, 0, 1, 2] count1 ← 0 count2 ← 0 FOR EACH value IN theList

{ IF(value > 0) { count1 ← count1 + 1 } ELSE { count2 ← count2 + 1 } }

What are the values of count1 and count2 as a result of executing the code segment?

Question 43

Consider the following code segment.

The figure presents three blocks of code that consist of 5 total lines. Throughout the third block of code are nested blocks of code. Line 1: [begin block] x ← 0 [end block] Line 2: [begin block] result ← 0 [end block] [Begin Block] Line 3: REPEAT UNTIL [begin block] x is greater than 5 [end block] [Begin Block] Line 4: [begin block] result ← result plus x [end block] Line 5: [begin block] x ← x plus 1 [end block] [End Block] [End Block] What is the value of result after the code segment is executed?

Question 39

The list wordList contains a list of 10 string values. Which of the following is a valid index for the list?

Question 35

In a certain video game, the variable maxPS represents the maximum possible score a player can earn. The maximum possible score depends on the time it takes the player to complete the game. The value of maxPS should be 30 if time is greater than 120 and 50 otherwise.

Which of the following code segments correctly sets the value of maxPS based on the value of time ?

Question 31

Assume that both lists and strings are indexed starting with index 1.

The list wordList has the following contents.

[“abc”, “def”, “ghi”, “jkl”]

Let myWord be the element at index 3 of wordList. Let myChar be the character at index 2 of myWord. What is the value of myChar ?

Question 16

Which of the following best explains how messages are typically transmitted over the Internet?