Written Response 2: Algorithms, errors and testing, and abstraction
PIN lockout
- Units 3 and 5
- 3 points
- About 45 minutes
Three prompts about the program's code. (a) Algorithm development: explain how a loop or condition works, such as how many times a loop runs or what makes it stop. (b) Errors and testing: describe a call, input or change that causes an error or wrong behavior and explain why. (c) Data and procedural abstraction: explain how the list or procedure manages complexity, or explain, step by step, an algorithm that uses the list. On the exam: Question 2 of 2 (3 points: parts (a), (b) and (c) are worth 1 point each). Section II has 2 written-response questions (4 prompts) in 60 minutes, taken in Bluebook at the end-of-course exam; no calculator. On the real exam the questions are about your own Create performance task program, and you can see your Personalized Project Reference (screenshots of your procedure and list code). The Create task is 30% of the AP score, scored on 6 one-point rows: video, program requirements, WR1, WR2(a), WR2(b) and WR2(c). On this site you answer the same kinds of prompts about a short sample program given with the question.
The question and its sources
Answer parts (a), (b) and (c) about the sample program below. On the exam these prompts are about your own Create task program and your Personalized Project Reference; here, the code segments below play that role. Refer to the specific code in every answer, and write in complete sentences.
About the program
A phone's lock screen allows 3 guesses at the PIN. savedPin holds the correct PIN, which the owner set up earlier; for testing, savedPin is 4821.
Each time the user types a guess, the program adds it to the list attempts and calls checkLogin, which returns "unlocked", "locked" or "keep trying". The program keeps asking for guesses until the result is not "keep trying". When the phone locks, the owner must wait before trying again (not shown).
Source: Sample program written for this practice question (hypothetical)
Procedure: checkLogin
PROCEDURE checkLogin(attempts, correctPin, maxTries)
{
tries ← 0
FOR EACH pin IN attempts
{
tries ← tries + 1
IF(pin = correctPin)
{
RETURN("unlocked")
}
IF(tries = maxTries)
{
RETURN("locked")
}
}
RETURN("keep trying")
}Source: Sample program written for this practice question (hypothetical)
List: storing the guesses in attempts, and calling the procedure
attempts ← []
status ← "keep trying"
REPEAT UNTIL(status ≠ "keep trying")
{
APPEND(attempts, INPUT())
status ← checkLogin(attempts, savedPin, 3)
}
DISPLAY(status)Source: Sample program written for this practice question (hypothetical)
Suggested time: 45 minutes
Your answers are saved in this browser as you type.
Part (a)
1 pointIn checkLogin, the IF that checks the PIN comes before the IF that checks the number of tries. Explain how the order of these two IF statements affects the result. Use a specific list of attempts for which swapping the two IF statements would change what checkLogin(attempts, 4821, 3) returns.
0 / 2,500 characters
Part (b)
1 pointA teammate changes IF(tries = maxTries) to IF(tries > maxTries). Write a call to checkLogin with specific arguments that shows the incorrect behavior this change causes. Describe the incorrect behavior, and explain why it happens.
0 / 2,500 characters
Part (c)
1 pointExplain how the list attempts uses abstraction to manage complexity in this program. Then suppose the program did not use a list. Describe how the code that uses the list would have to change to keep the same behavior, or explain why the same behavior would not be possible without a list.
0 / 2,500 characters
Checking scoring…
Scoring it yourself shows you the rubric, examples and a model answer. Try writing your answer first.