Written Response 2: Algorithms, errors and testing, and abstraction
Air-quality sensor
- Units 2 and 3
- 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 school's air sensor measures fine-particle pollution (PM2.5, in micrograms per cubic meter) every four hours, so it takes six readings a day. When the sensor fails, it records -1 instead of a reading.
averageValid returns the average of the readings that aren't -1. The program displays the day's average and shows an alert when it is above 35.
Example: for the list below, the program displays 22.4.
Source: Sample program written for this practice question (hypothetical)
Procedure: averageValid
PROCEDURE averageValid(readings)
{
total ← 0
count ← 0
FOR EACH r IN readings
{
IF(r ≠ -1)
{
total ← total + r
count ← count + 1
}
}
RETURN(total / count)
}Source: Sample program written for this practice question (hypothetical)
List: storing the readings in todayReadings
todayReadings ← [14, 22, -1, 31, 27, 18]Source: Sample program written for this practice question (hypothetical)
Calling the procedure and using the list
dayAverage ← averageValid(todayReadings)
DISPLAY(dayAverage)
IF(dayAverage > 35)
{
DISPLAY("Air quality alert")
}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 pointConsider the iteration statement in averageValid. Explain what determines when it stops. If specific variable values cause it to stop, identify them; if not, explain how the iteration statement ends.
0 / 2,500 characters
Part (b)
1 pointWrite a call to averageValid with specific argument(s) that the procedure accepts but that cause it to behave incorrectly. Describe the incorrect behavior, and explain why it happens as a result of your call. If no call with accepted arguments can make averageValid behave incorrectly, explain why.
0 / 2,500 characters
Part (c)
1 pointExplain how the list todayReadings 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.