01 / 21

Program Function
and Purpose

Understand what programs do, why they exist, and how to describe a program's behavior, inputs, outputs, and intended purpose.

AP Computer Science Principles

What Is a Program?

A program is a collection of statements (instructions) that a computer executes to accomplish a specific task. Programs are written in programming languages and can range from a single line to millions of lines of code.

Software
Programs that run on devices: apps, websites, games, operating systems
Code
The human-readable instructions that make up a program

Function vs. Purpose

The AP exam draws a clear distinction between these two terms. Understanding the difference is essential for the Create Performance Task and multiple-choice questions.

Function
How a program works: the specific behavior it exhibits when given inputs, including computed outputs and side effects.
Purpose
Why a program was created: the problem it was intended to solve or the creative goal it aims to achieve.

The Input-Process-Output Model

INPUT User data, sensors, files, other programs PROGRAM Algorithms, logic, computation OUTPUT Display, sound, data, actions Purpose: WHY does this pipeline exist? Function: WHAT does each step do?

Key Definitions for the AP Exam

1
Program: A collection of program statements that performs a specific task when run by a computer.
2
Code Segment: A portion of a program; can be a single line or many lines taken from a larger program.
3
Behavior: What a program does when it runs, described by how the user interacts with it and what the program produces.
4
Input: Data sent to a program for processing (mouse clicks, keyboard, sensor, file, another program's output).
5
Event: An action that causes part of a program to execute, such as a click, key press, or timer.

How to Describe a Program

When asked to describe a program on the AP exam or in your Create Task, always address these four dimensions:

1. Inputs
What data does the program receive? From where?
2. Processing
What algorithms or logic transform the data?
3. Outputs
What results does the program produce?
4. Purpose
What problem does it solve? For whom?

Function vs. Purpose: Side by Side

Function Purpose
Question answered What does it do? Why was it made?
Perspective Technical / observable Human / motivational
Example (calculator) Takes two numbers, applies an operation, returns result To help students solve math problems quickly
Example (weather app) Fetches API data, parses JSON, displays forecast To help people plan daily activities around weather

The same forecast data becomes a decision on a park bench

A hiker checks a phone on a park bench with rain clouds in the distance.A weather app’s purpose is to help people plan. Its functions receive location and forecast data, process a response and display information or an alert.

Separate the purpose from the executed steps

A human planning goal sits beside an input-process-output chain from location and service response to a conditional weather alert.The person wants to plan an outdoor activity. The app receives location and a weather-service response, parses the data and checks severeWeather before displaying an alert. The service’s output is an input to the app.

Step-by-Step: Identifying Function and Purpose

1
Read the program or description carefully. Look for what happens when the program runs.
2
Identify the inputs. What data enters the program? User clicks? Typed text? Sensor data?
3
Trace the processing. What does the code do with those inputs? Sorting? Calculating? Filtering?
4
Identify the outputs. What does the user see, hear, or receive as a result?
5
State the purpose. Ask: "Why would someone build this?" The answer is the purpose.

Example 1: Tip Calculator

# Tip Calculator Program bill = INPUT("Enter bill amount:") tipPercent = INPUT("Enter tip %:") \(\text{tip} = \text{bill} \times \frac{\text{tipPercent}}{100}\) \(\text{total} = \text{bill} + \text{tip}\) DISPLAY("Tip: $" + \(\text{tip}\)) DISPLAY("Total: $" + \(\text{total}\))
Function
Takes a bill amount and tip percentage as input, calculates the tip and total, and displays both values.
Purpose
To help restaurant diners quickly determine how much to tip and what their total bill will be.

Example 2: Password Checker

# Password Strength Checker password = INPUT("Enter password:") IF \(\text{LENGTH}(\text{password}) < 8\) DISPLAY("Weak: too short") ELSE IF \(\text{hasSpecialChar}(\text{password}) \land \text{hasNumber}(\text{password})\) DISPLAY("Strong password") ELSE DISPLAY("Medium strength")
Function
Accepts a password string, checks its length and character types, and displays a strength rating.
Purpose
To help users create stronger passwords by giving immediate feedback on password security.

Example 3: Event-Driven Program

User clicks "Sort" button Event Handler onButtonClick: sortList(data) Display sorted list on screen Event-Driven Programming Code runs in response to events, not in a fixed sequence

Program Documentation

Documentation is a written description of a program's function, purpose, and behavior. It helps others (and your future self) understand what the code does and why.

1
Comments in code: Lines starting with // or # that explain what each section does.
2
README files: Describe the overall purpose, setup instructions, and usage.
3
API documentation: Describes functions, parameters, and return values for other developers.

Types of Program Inputs

Tactile
Mouse clicks, taps, swipes, keyboard presses, game controller
Audio/Visual
Microphone, camera, image files, video feeds
Sensor
GPS, accelerometer, temperature, heart rate, proximity
Data
Files, databases, APIs, web requests, another program's output
System
Timers, system clock, random number generators, OS events

Types of Program Outputs

Visual
Text on screen, graphics, animations, charts, notifications
Audio
Sound effects, music, spoken text (text-to-speech)
Data
Files saved, database records, data sent to other programs

Common Mistakes to Avoid

Confusing function with purpose
Saying "the purpose is to sort a list" when that is the function. The purpose would be "to help users find items faster."
Describing code, not behavior
Writing "Line 3 assigns x to 5" instead of describing what the user experiences when the program runs.
Missing inputs or outputs
Forgetting that inputs can be from other programs and outputs include data files, not just screen displays.

Summary: Key Concepts

Concept Definition Example
Program Collection of instructions A weather app
Function What it does (behavior) Fetches and displays forecast
Purpose Why it was created Help people plan for weather
Input Data the program receives ZIP code, GPS coordinates
Output Results the program produces Temperature, rain forecast
Event Action triggering code User taps "Refresh"

Question 1 of 5

A fitness app tracks a user's daily steps using a phone's accelerometer and displays a bar chart of weekly activity. Which of the following best describes the purpose of this program?

Question 2 of 5

Which of the following is an example of a program input that does NOT come directly from a user?

Question 3 of 5

A program accepts a list of student names and test scores, then displays the class average and the name of the highest scorer. Which of the following best describes the function of this program?

Question 4 of 5

In an event-driven program, which of the following best describes what happens when no events have occurred?

Question 5 of 5

A developer writes comments in their code explaining that a function calculates shipping costs based on package weight and destination. This is an example of: