Program Functionality (College Board AP® Computer Science Principles): Revision Note

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

Program function & purpose

What is a program?

  • A program is a collection of statements that work together to accomplish a specific task

  • A statement is a single instruction that directs the computer to perform a specific action

  • Statements are the smallest building blocks of any program

  • A code segment is a group of statements that work together to complete part of a task

  • Combining code segments allows programs to solve increasingly complex problems

What is the purpose of a program?

  • A program is built to solve a problem or to pursue an interest through creative expression

  • Understanding a program's purpose helps developers design and build it more effectively

How is program behavior described?

  • The behavior of a program is how it functions during execution, often described by how a user interacts with it

  • A program can be described in two levels of detail: broadly, by what it does; or in more detail, by both what it does and how its statements accomplish that function

How does program execution work?

  • By default, program statements execute sequentially, from top to bottom, each statement completes before the next one begins

  • This default sequential flow is interrupted by events (in event-driven programming, statements execute when triggered rather than in sequence) and by procedure calls (which pause the current flow to run the procedure's statements, then return)

  • The order in which statements execute directly affects what the program does and the output it produces

User interaction

  • Programs interact with users by accepting input and producing output

  • An event, such as a button click or key press, is associated with an action and supplies input data to the program

  • Output is any data sent from a program to a device, screens, speakers, files, or other devices

  • User interaction is a core part of program functionality: input shapes what the program does, and output communicates the result

Term

Meaning

Example

Statement

A single instruction for the computer to carry out

DISPLAY("Hello")

Code segment

A code segment is a collection of program statements that is part of a program

A block of code that calculates and displays a total

Execution

The process of carrying out program statements in order

Running a program from start to finish

Input

Data provided by the user during program execution

A number typed into a prompt

Output

Information the program displays or returns to the user

A result printed to the screen

Examiner Tips and Tricks

  • The AP exam uses a pseudocode reference sheet with its own syntax — DISPLAY produces output and INPUT receives it; so you should be comfortable reading both pseudocode and your own programming language.

Input handling

How does input affect program functionality?

  • The functionality of a program is directly affected by the input it receives

  • Different inputs to the same program can produce different outputs

  • Programs must be designed to handle varied inputs, including:

    • Expected values

    • Edge cases (Inputs at or just beyond the extremes (minimum and maximum) of the input range)

    • Invalid or unexpected data

  • Handling a range of inputs correctly is essential to ensuring a program works as intended across real-world scenarios

"Image coming soon"

Examiner Tips and Tricks

  • When asked to describe program behavior, focus on what the program does with its input and what it produces as output. Do not describe the code line by line; examiners want to see that you understand what the program achieves overall.

  • When testing program functionality, think about inputs that cover every possible case the program is designed to handle. A program that only works for typical inputs is not fully functional.

  • For the AP Create Performance Task, you will need to explain how your program handles input and produces output in your written response on exam day. Be specific about what data your program receives, how it processes that data, and what it returns to the user.

Worked Example

A student writes a program that takes a number as input and displays whether it is positive, negative, or zero. Which of the following sets of inputs would best test the full functionality of the program?

(A) 1, 2, 3

(B) -1, 0, 1

(C) 100, 200, 300

(D) 0, 0, 0

[1]

Answer:

(B) -1, 0, 1 [1 mark]

  • -1, 0, and 1 each trigger a different branch of the program, covering all three conditions; negative, zero, and positive; making this the only option that fully tests the program's functionality

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.