AP CSP MOCK
star
star
star
star
star
Last updated 3 months ago
25 questions
1
A student writes a program that processes thousands of currency transactions and rounds the results to the nearest cent. Over time, they notice the program's totals are off by several dollars.
A student writes a program that processes thousands of currency transactions and rounds the results to the nearest cent. Over time, they notice the program's totals are off by several dollars.
1
A student sends a private file to a teacher via email. Which approach provides the strongest protection against unauthorized access during transfer?
A student sends a private file to a teacher via email. Which approach provides the strongest protection against unauthorized access during transfer?
1
A school’s meal tracking system records data each time a student buys a lunch in the cafeteria. For every transaction, the system stores:- The student's name and ID number
- The date and time of purchase
- The items purchased and their prices
- The payment method (e.g., prepaid card, cash)
Which of the following CANNOT be determined from the information stored in the system?Responses:
A school’s meal tracking system records data each time a student buys a lunch in the cafeteria. For every transaction, the system stores:
- The student's name and ID number
- The date and time of purchase
- The items purchased and their prices
- The payment method (e.g., prepaid card, cash)
Which of the following CANNOT be determined from the information stored in the system?
Responses:
1
count ← 0REPEAT UNTIL (count > 5){ IF (count MOD 2 = 0) { DISPLAY(count) } count ← count + 1}
count ← 0
REPEAT UNTIL (count > 5)
{
IF (count MOD 2 = 0)
{
DISPLAY(count)
}
count ← count + 1
}
1
result ← 0REPEAT 4 TIMES{ result ← result + 2 IF (result MOD 3 = 0) { result ← result + 1 }}
result ← 0
REPEAT 4 TIMES
{
result ← result + 2
IF (result MOD 3 = 0)
{
result ← result + 1
}
}
1
x ← 5y ← 3REPEAT UNTIL (x ≤ 0){ y ← y + 1 x ← x - 1 IF (y MOD 2 = 0) { x ← x - 1 }}
What is the value of y after the code segment executes?
x ← 5
y ← 3
REPEAT UNTIL (x ≤ 0)
{
y ← y + 1
x ← x - 1
IF (y MOD 2 = 0)
{
x ← x - 1
}
}
What is the value of y after the code segment executes?
1
x ← 0y ← 0REPEAT 5 TIMES{ y ← y + 1 IF (y MOD 2 = 1) { x ← x + y } ELSE { x ← x + 2 }}
What is the value of x after the code segment executes?
x ← 0
y ← 0
REPEAT 5 TIMES
{
y ← y + 1
IF (y MOD 2 = 1)
{
x ← x + y
}
ELSE
{
x ← x + 2
}
}
What is the value of x after the code segment executes?
1
counter ← 0sum ← 0REPEAT UNTIL (counter > 5){ IF (counter ≠ 3) { sum ← sum + counter } counter ← counter + 1}
What is the value of sum after the code segment executes?
counter ← 0
sum ← 0
REPEAT UNTIL (counter > 5)
{
IF (counter ≠ 3)
{
sum ← sum + counter
}
counter ← counter + 1
}
What is the value of sum after the code segment executes?
1
aList ← [2, 4, 6, 8, 10]count ← 0result ← 0FOR EACH item IN aList{ IF (item MOD 4 = 0) { count ← count + 1 result ← result + item }}
What are the values of count and result after this code segment executes?
aList ← [2, 4, 6, 8, 10]
count ← 0
result ← 0
FOR EACH item IN aList
{
IF (item MOD 4 = 0)
{
count ← count + 1
result ← result + item
}
}
What are the values of count and result after this code segment executes?
1
x ← 1REPEAT UNTIL (x > 30){ IF (x MOD 3 = 0 AND x MOD 5 = 0) { DISPLAY("both") } ELSE { IF (x MOD 3 = 0) { DISPLAY("three") } ELSE { IF (x MOD 5 = 0) { DISPLAY("five") } } } x ← x + 1}
How many times will "both" be displayed when this code segment executes?
x ← 1
REPEAT UNTIL (x > 30)
{
IF (x MOD 3 = 0 AND x MOD 5 = 0)
{
DISPLAY("both")
}
ELSE
{
IF (x MOD 3 = 0)
{
DISPLAY("three")
}
ELSE
{
IF (x MOD 5 = 0)
{
DISPLAY("five")
}
}
}
x ← x + 1
}
How many times will "both" be displayed when this code segment executes?
1
a ← 0b ← 0REPEAT 4 TIMES{ a ← a + 1 REPEAT a TIMES { b ← b + 1 }}
}
What is the value of b after the code segment executes?
a ← 0
b ← 0
REPEAT 4 TIMES
{
a ← a + 1
REPEAT a TIMES
{
b ← b + 1
}
}
}
What is the value of b after the code segment executes?
1
total ← 0index ← 1REPEAT UNTIL (index > 5){ IF (index MOD 2 = 0) { total ← total - index } ELSE { total ← total + index * 2 } index ← index + 1}
total ← 0
index ← 1
REPEAT UNTIL (index > 5)
{
IF (index MOD 2 = 0)
{
total ← total - index
}
ELSE
{
total ← total + index * 2
}
index ← index + 1
}
1
PROCEDURE mystery(n){ result ← 0 counter ← 0 REPEAT UNTIL (counter > n) { IF (counter MOD 3 = 0 OR counter MOD 5 = 0) { result ← result + counter } counter ← counter + 1 } RETURN(result)}
What is returned by the call mystery(10)?
PROCEDURE mystery(n)
{
result ← 0
counter ← 0
REPEAT UNTIL (counter > n)
{
IF (counter MOD 3 = 0 OR counter MOD 5 = 0)
{
result ← result + counter
}
counter ← counter + 1
}
RETURN(result)
}
What is returned by the call mystery(10)?
1
PROCEDURE sumEvens(numList){ sum ← 0 FOR EACH num IN numList { IF (num MOD 2 = 0) { sum ← sum + num } } RETURN(sum)}
What will be returned by the call sumEvens([3, 8, 2, 9, 4])?
PROCEDURE sumEvens(numList)
{
sum ← 0
FOR EACH num IN numList
{
IF (num MOD 2 = 0)
{
sum ← sum + num
}
}
RETURN(sum)
}
What will be returned by the call sumEvens([3, 8, 2, 9, 4])?
1
PROCEDURE mystery(aList, val){ count ← 0 FOR EACH item IN aList { IF (item > val) { count ← count + 1 } } RETURN(count)}
What will be returned by the call mystery([15, 7, 22, 9, 18], 12)?
PROCEDURE mystery(aList, val)
{
count ← 0
FOR EACH item IN aList
{
IF (item > val)
{
count ← count + 1
}
}
RETURN(count)
}
What will be returned by the call mystery([15, 7, 22, 9, 18], 12)?
1
PROCEDURE transform(list1){ list2 ← [] FOR EACH item IN list1 { IF (item < 0) { APPEND(list2, item * -1) } ELSE { APPEND(list2, item * 2) } } RETURN(list2)}
What will be returned by the call transform([-3, 4, 0, -2, 5])?
PROCEDURE transform(list1)
{
list2 ← []
FOR EACH item IN list1
{
IF (item < 0)
{
APPEND(list2, item * -1)
}
ELSE
{
APPEND(list2, item * 2)
}
}
RETURN(list2)
}
What will be returned by the call transform([-3, 4, 0, -2, 5])?
1
PROCEDURE modifyList(aList){ length ← LENGTH(aList) i ← 1 REPEAT UNTIL (i > length) { IF (aList[i] MOD 3 = 0) { REMOVE(aList, i) length ← length - 1 } ELSE { i ← i + 1 } } RETURN(aList)}
What will be returned by the call modifyList([6, 4, 9, 5, 12, 7])?
PROCEDURE modifyList(aList)
{
length ← LENGTH(aList)
i ← 1
REPEAT UNTIL (i > length)
{
IF (aList[i] MOD 3 = 0)
{
REMOVE(aList, i)
length ← length - 1
}
ELSE
{
i ← i + 1
}
}
RETURN(aList)
}
What will be returned by the call modifyList([6, 4, 9, 5, 12, 7])?
1
PROCEDURE process(aList){ result ← [] i ← 1 j ← LENGTH(aList) REPEAT UNTIL (i > j) { APPEND(result, aList[i] + aList[j]) i ← i + 1 j ← j - 1 } RETURN(result)}
What will be returned by the call process([3, 1, 4, 2, 7])?
PROCEDURE process(aList)
{
result ← []
i ← 1
j ← LENGTH(aList)
REPEAT UNTIL (i > j)
{
APPEND(result, aList[i] + aList[j])
i ← i + 1
j ← j - 1
}
RETURN(result)
}
What will be returned by the call process([3, 1, 4, 2, 7])?
1
PROCEDURE f1(n){ IF (n ≤ 1) { RETURN(1) } ELSE { RETURN(n * f2(n - 1)) }}
PROCEDURE f2(n){ IF (n ≤ 1) { RETURN(1) } ELSE { RETURN(n + f1(n - 1)) }}
What will be returned by the call f1(3)?
PROCEDURE f1(n)
{
IF (n ≤ 1)
{
RETURN(1)
}
ELSE
{
RETURN(n * f2(n - 1))
}
}
PROCEDURE f2(n)
{
IF (n ≤ 1)
{
RETURN(1)
}
ELSE
{
RETURN(n + f1(n - 1))
}
}
What will be returned by the call f1(3)?
1
PROCEDURE findPattern(wordList){ matchList ← [] FOR EACH word IN wordList { IF (LENGTH(word) > 3 AND word[1] = "a") { APPEND(matchList, word) } } RETURN(matchList)}
What will be returned by the call findPattern(["apple", "art", "about", "cat", "atom"])?
PROCEDURE findPattern(wordList)
{
matchList ← []
FOR EACH word IN wordList
{
IF (LENGTH(word) > 3 AND word[1] = "a")
{
APPEND(matchList, word)
}
}
RETURN(matchList)
}
What will be returned by the call findPattern(["apple", "art", "about", "cat", "atom"])?
1
PROCEDURE insertItem(aList, item, position){ length ← LENGTH(aList) IF (position < 1 OR position > length + 1) { RETURN(aList) } newList ← [] i ← 1 REPEAT UNTIL (i > length + 1) { IF (i = position) { APPEND(newList, item) } IF (i ≤ length) { APPEND(newList, aList[i]) } i ← i + 1 } RETURN(newList)}
What will be returned by the call insertItem([10, 20, 30], 25, 2)?
PROCEDURE insertItem(aList, item, position)
{
length ← LENGTH(aList)
IF (position < 1 OR position > length + 1)
{
RETURN(aList)
}
newList ← []
i ← 1
REPEAT UNTIL (i > length + 1)
{
IF (i = position)
{
APPEND(newList, item)
}
IF (i ≤ length)
{
APPEND(newList, aList[i])
}
i ← i + 1
}
RETURN(newList)
}
What will be returned by the call insertItem([10, 20, 30], 25, 2)?
1
PROCEDURE combine(list1, list2){ result ← [] len1 ← LENGTH(list1) len2 ← LENGTH(list2) minLen ← minimum(len1, len2) i ← 1 REPEAT UNTIL (i > minLen) { APPEND(result, list1[i]) APPEND(result, list2[i]) i ← i + 1 } RETURN(result)}
PROCEDURE minimum(a, b){ IF (a ≤ b) { RETURN(a) } ELSE { RETURN(b) }}
What will be returned by the call combine([2, 4, 6], [3, 5])?
PROCEDURE combine(list1, list2)
{
result ← []
len1 ← LENGTH(list1)
len2 ← LENGTH(list2)
minLen ← minimum(len1, len2)
i ← 1
REPEAT UNTIL (i > minLen)
{
APPEND(result, list1[i])
APPEND(result, list2[i])
i ← i + 1
}
RETURN(result)
}
PROCEDURE minimum(a, b)
{
IF (a ≤ b)
{
RETURN(a)
}
ELSE
{
RETURN(b)
}
}
What will be returned by the call combine([2, 4, 6], [3, 5])?
1
PROCEDURE calculateSum(listA, listB){ IF (LENGTH(listA) ≠ LENGTH(listB)) { RETURN(0) } sum ← 0 i ← 1 len ← LENGTH(listA) REPEAT UNTIL (i > len) { IF (listA[i] = listB[i]) { sum ← sum + listA[i] } i ← i + 1 } RETURN(sum)}
What will be returned by the call calculateSum([5, 3, 7, 2], [8, 3, 7, 5])?
PROCEDURE calculateSum(listA, listB)
{
IF (LENGTH(listA) ≠ LENGTH(listB))
{
RETURN(0)
}
sum ← 0
i ← 1
len ← LENGTH(listA)
REPEAT UNTIL (i > len)
{
IF (listA[i] = listB[i])
{
sum ← sum + listA[i]
}
i ← i + 1
}
RETURN(sum)
}
What will be returned by the call calculateSum([5, 3, 7, 2], [8, 3, 7, 5])?

1
A file storage application allows users to save their files on cloud servers. A group of researchers gathered user data for the first eight years of the application’s existence. Some of the data are summarized in the following graphs. The line graph on the left shows the number of registered users each year. The line graph on the right shows the total amount of data stored by all users each year. The circle graph shows the distribution of file sizes currently stored by all users.
(note: 1 MB = 1,000 KB)Which of the following best describes the average amount of data stored per user for the first eight years of the application’s existence?
A file storage application allows users to save their files on cloud servers. A group of researchers gathered user data for the first eight years of the application’s existence. Some of the data are summarized in the following graphs. The line graph on the left shows the number of registered users each year. The line graph on the right shows the total amount of data stored by all users each year. The circle graph shows the distribution of file sizes currently stored by all users.
(note: 1 MB = 1,000 KB)
Which of the following best describes the average amount of data stored per user for the first eight years of the application’s existence?
1
Convert 2391 in base 10 to binary
Convert 2391 in base 10 to binary