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

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

Event-driven programming basics

What is event-driven programming?

  • Event-driven programming is a programming approach where the flow of the program is determined by events rather than following a fixed sequence of statements

  • An event is an action that occurs as a result of user interaction or another trigger

  • When an event occurs, the program runs a specific section of code in response

  • This allows programs to respond dynamically to user actions instead of executing instructions in a single, predetermined order

Types of events

  • Events are typically triggered by user interactions with a program's interface

Event

How it occurs

Example

Key press

The user presses a key on the keyboard

Pressing the spacebar to pause a game

Mouse click

The user clicks on an element in the program

Clicking a "Submit" button on a form

Mouse movement

The user moves the mouse over an area

Hovering over a menu to reveal options

Screen tap

The user taps a touchscreen element

Tapping an icon to open an application

Timer

A set amount of time has passed

A countdown that triggers an action when it reaches zero

Program start

The program begins running

Initializing variables or playing a welcome animation when a game launches

Event handlers

  • An event handler is a section of code (a procedure) that is executed when a specific event is detected

  • The program listens for events and calls the appropriate handler when one occurs

  • Multiple event handlers can exist within a single program, each responding to a different event

  • Event-driven programs spend most of their execution time waiting for events to occur rather than actively running code

  • Events are one way input enters a program, but programs can receive input from many other sources too

Examiner Tips and Tricks

  • When the AP exam describes a program that responds to user actions (clicks, key presses, screen taps), it is describing event-driven programming. Look for keywords like "event", "trigger", and "action" in the question to identify this concept.

  • For the Create Performance Task, event handlers (such as "when button clicked" blocks) are considered built-in abstractions, not student-developed code. If you use one, make sure your student-developed procedure is a separate, named procedure that you have written yourself.

Input processing

How do programs process input?

  • Input is any data provided to a program from an external source

  • Input can come in a variety of forms, including tactile (touch), audio, visual, or text, and a program needs to work for a variety of inputs and situations

  • A computer receives input, processes it using the program's logic, and produces output

  • The input-output relationship describes how specific inputs are transformed by the program's processing to produce specific outputs

  • The same program can produce different outputs depending on the data it receives as input

  • A program's output depends on its input or its prior state (the internal values stored during previous execution)

Input sources

  • User input: data entered directly by a person (typing text, clicking buttons, speaking into a microphone)

  • File input: data read from a stored file (loading a saved document or reading a dataset)

  • Sensor input: data collected automatically from a device (a fitness tracker recording heart rate)

  • Network input: data received from another system or application over a connection (receiving messages in a chat program)

Examiner Tips and Tricks

  • The AP exam may ask you to identify what type of input a program uses or how changing the input affects the output. Always trace the path from input through processing to output when answering these questions. Do not confuse the input source with the input itself. The keyboard is the source; the text the user types is the input.

  • For the AP Create Performance Task, your program must include instructions for input from the user, a device, an online data stream, or a file. On exam day, you will need to explain how your program receives and processes this input to produce output.

Worked Example

A fitness application collects heart rate data from a wearable sensor and displays a message to the user. When the heart rate exceeds 150 beats per minute, the program displays "High intensity". Otherwise, it displays "Normal".

Which of the following best describes the input to this program?

(A) The message displayed on the screen

(B) The heart rate data collected from the sensor

(C) The wearable sensor device

(D) The threshold value of 150 beats per minute

[1]

Answer:

(B) The heart rate data collected from the sensor [1 mark]

  • The heart rate data is the input — the sensor is merely its source, the message is the output, and the 150 bpm threshold is part of the processing logic

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.