1.2 Program function and purposeWhy it exists, and what it does

A program, also called software or code, is a collection of program statements that performs a specific task when a computer runs it. Programs are written to solve a problem or to pursue an interest through creative expression, like a game, an animation or a music maker. That reason is the program's purpose. Knowing the purpose guides every decision the developers make, from what to build first to how the screens should look.
A program's function is what it actually does when it runs: what inputs it takes, how it processes them, and what outputs it produces. Developers often describe the function by describing the program's behavior, which is how it acts while it runs, and they usually describe that behavior from the user's side: "you type a stop number and it shows how many minutes until the next bus."
| Program | Purpose (why it exists) | Function (what it does) |
|---|---|---|
| Tip splitter | Friends split a restaurant bill fairly | Takes bill, people, tip %; shows each share |
| Bus tracker | Riders stop waiting in the cold | Takes a stop; shows minutes until the next bus |
| Flashcards | Students remember vocabulary | Shows a word; checks the typed answer; repeats misses |
?Wait, what's the difference between a program and a code segment again?
Here is a whole small program, written in the pseudocode the AP exam uses. Don't worry about every symbol yet: Unit 3 teaches the language line by line. For now, read it for its function. It takes three values in, does some arithmetic, and shows one value out.
1PROCEDURE tipShare(bill, people, percent)12{3 tip ← bill * percent / 10024 RETURN((bill + tip) / people)25}6DISPLAY(tipShare(60, 4, 20))3
- line 1 Three inputs arrive as parameters
- line 3-4 Processing: 12 of tip, then 72 split 4 ways
- line 6 Output: the share is shown on the screen
?Wait, what does PROCEDURE mean?
One more expectation from the course: a program needs to work for a variety of inputs and situations, not just the one the developer tried first. The tip splitter works for 60 dollars and 4 people. Does it work for 1 person? For a 0 percent tip? For 0 people? Thinking about all of those is part of designing the function, and it leads straight into testing in Topic 1.4.
I thought about it. Show me
- Purpose: the problem it solves for people. Here, helping middle school students practice multiplication facts.
Why?
Purpose answers "why does this exist and for whom?" It is about people, not code. - Inputs: the product the student types. (The random numbers are produced by the program itself, so they are not user input.)
Why?
An input is data sent to the program for processing. The typed answer comes from the user. - Outputs: the two numbers shown, the message Correct or Try again, and the score.
Why?
An output is any data the program sends to a device, here to the screen. Notice the message depends on the input: outputs are usually based on input. - Function, in one sentence: it shows a problem, checks the typed answer against the product, and reports the result and running score.
Answer: Purpose: helping middle school students practice multiplication facts. Input: the typed product. Outputs: the two numbers, Correct or Try again, and the score.
Stuck? Get a hint
- Purpose is about people and a problem. Find the "helps ... to ..." part.
- An input is something sent into the program. What does the student send?
- An output is anything the program shows, plays or sends out.
- AIt reads the temperature sensor every minute and stores the reading.
- BIt helps gardeners know when their plants need water.
- CIt displays a red icon when the soil moisture is below 30 percent.
- DIt sends a text message after three dry readings in a row.
Show the answer
B. Purpose is why the program exists for people: helping gardeners know when to water. The other three describe what the program does with its inputs and outputs, which is its function. The trap is that function statements sound more "technical", so they feel more important.

When a written-response prompt asks about purpose, name a specific group of people and the problem the program solves for them. "It helps anyone" earns nothing. "It helps high school runners track weekly mileage" does.
- Purpose: the problem the program solves, or the interest it pursues, for people.
- Function: what it does when it runs. Inputs, processing, outputs. Its behavior is usually described from the user's side.
- A program is a collection of statements that performs a task. A code segment is part of a program.
- A program should work for a variety of inputs and situations, not only the obvious one.