Algorithms and programming
Build an abstraction and explain it
Use parameters, return values, and a list to express a reusable algorithm.
Algorithm examples use AP reference notation, including one-based list indices.
Give a procedure one clear job
A parameter supplies information to a procedure. A return value supplies information back to the caller. CountAtLeast works for different lists and thresholds, so its caller can ask a question without repeating the loop.
The list groups an arbitrary number of scores under one name. Without it, adding another score could require another variable and another copy of the condition. This is the complexity that the data abstraction manages.
PROCEDURE CountAtLeast(scores, threshold)
{
count ← 0
FOR EACH score IN scores
{
IF (score ≥ threshold)
{
count ← count + 1
}
}
RETURN(count)
}
DISPLAY(CountAtLeast([42, 65, 80], 70))Explain development with evidence
For your own project, describe the input, the result, and how the algorithm reaches it. Explain how changing a parameter changes the result. Choose tests that distinguish correct behavior from a plausible mistake, such as using > when the requirement says at least.
Use the current official Create task instructions to check submission requirements. This example is for learning procedure design; develop and explain your own solution for assessed work.
Check yourself
What does CountAtLeast([42, 65, 80], 70) return?Show answer
1. Only 80 is at least 70. With a threshold of 65, it returns 2.
References used to build these lessons
We used these official documents as references when building this course's lessons. They are the sources for the syllabus structure and course requirements.
College Board · Effective fall 2023