Programming
The core skill of computer science. Design, read, write, debug and evaluate programs that solve real problems and produce robust, reliable outcomes.
Students must be competent at designing, reading, writing and debugging programs in at least one of Python, C# or Java. Repeated practice is essential — students should write many programs of increasing complexity throughout the course.
Writing Programs (2.1.1)
Programs must be written in a high-level programming language — Python, C# or Java for this qualification. A high-level language is close to English, making it easier for humans to read and write than low-level languages. High-level programs must be translated (compiled or interpreted) before the computer can execute them.
Well-written programs should: solve the stated problem correctly, handle all valid inputs, reject invalid inputs gracefully, be readable by other programmers, and be efficient in their use of time and memory.
Readable Programs (2.1.2)
Programs that are easy to read are much easier to maintain, debug and develop collaboratively. Techniques to improve readability include:
- Comments — Explanatory text in the code. Explain what the code does.
- Descriptive names — Use meaningful names for variables, constants, and subprograms.
- Indentation — Code inside loops, IF blocks and subprograms must be consistently indented.
- Consistent naming conventions — e.g. camelCase or snake_case throughout.
- Blank lines — Separate logical sections of code.
Types of Errors (2.1.3)
Syntax Error
Breaks language rules. Detected before runtime. Examples: missing colon, misspelled keyword.
Runtime Error
Occurs while running — program crashes. Examples: division by zero, index out of range.
Logic Error
Program runs but produces wrong output. Algorithm is flawed. Example: off-by-one in loop.
Test Plans and Test Data (2.1.4)
A test plan documents all tests with: description, inputs, expected output, actual output. Three types of test data:
- Normal data — Typical valid values.
- Boundary data — Values at the exact edges of acceptable ranges.
- Erroneous data — Completely invalid inputs the program should reject.
Fixing errors — Interpret error messages from compiler/interpreter. Use trace tables to locate bugs. Always re-test after fixing.
Trace tables — Manually step through code tracking variable values. Essential for finding logic errors and exam questions.
Evaluating programs — Assess correctness, efficiency, readability, input validation. Suggest specific improvements like constants, refactoring.
Structural Components (2.2.1 & 2.2.2)
- Variable declarations — Named storage with data types.
- Command sequences — Instructions executed in order.
- Selection (IF/ELSE, CASE) — Conditional branching.
- Iteration (loops) — FOR (count-controlled), WHILE (pre-condition), REPEAT…UNTIL (post-condition).
- Data structures — Arrays, records, strings.
- Subprograms — Reusable procedures and functions.
Loop Types — When to Use Each
FOR loop — Known number of repetitions. WHILE loop — Condition checked before each iteration (may run zero times). REPEAT…UNTIL — Always runs at least once (post-condition).
INTEGER
Whole numbers: -5, 0, 42
REAL
Decimal numbers: 3.14, -0.5
BOOLEAN
TRUE or FALSE
CHAR
Single character: ‘A’, ‘7’
STRING
Sequence of characters: “Hello”
Data Structures (2.3.2)
- Records — Group of related data items of different types.
- 1D Arrays — List of same-type items accessed by index (starting 0).
- 2D Arrays — Grid accessed by row and column indices.
String Manipulation (2.3.3)
- LENGTH(str) — number of characters
- Concatenation (&) — join strings
- Substring — extract part
- Uppercase/Lowercase — case conversion
Variables vs Constants (2.3.4)
- Variable — value can change during execution.
- Constant — value set once and never changed (CONST). Benefits: readability, single point of update.
Global vs Local Variables (2.3.5)
- Local variable — declared inside subprogram, only accessible there.
- Global variable — declared outside all subprograms, accessible everywhere. Use sparingly.
Best practice: prefer local variables. Pass parameters rather than relying on globals.
User Input (2.4.1)
Programs accept user input using RECEIVE statements. In pseudocode: RECEIVE name FROM (STRING) KEYBOARD. The program must respond appropriately — use the value in calculations, display it back, store it.
Validation (2.4.2)
Validation checks that data entered is reasonable before use. Types: range check, type check, length check, presence check, format check. Validation loops repeatedly ask until valid data entered.
File Handling (2.4.3)
Programs can read from and write to text files to persist data. Pseudocode: READ MyFile.txt record and WRITE MyFile.txt data. Loop until end of file to read all records.
Arithmetic Operators (2.5.1)
| Operator | Name | Example |
|---|---|---|
| + | Add | 5+3=8 |
| – | Subtract | 9-4=5 |
| * | Multiply | 3*7=21 |
| / | Divide | 10/4=2.5 |
| MOD | Modulus | 10 MOD 3 = 1 |
| DIV | Integer div | 10 DIV 3 = 3 |
| ^ | Exponent | 2^8=256 |
MOD tests even/odd; DIV gives whole quotient.
Relational Operators (2.5.2)
| Symbol | Meaning |
|---|---|
| = | Equal to |
| <> | Not equal |
| > | Greater than |
| >= | ≥ |
| < | Less than |
| <= | ≤ |
Logical Operators (2.5.3)
| Operator | Result |
|---|---|
| AND | TRUE only if both TRUE |
| OR | TRUE if at least one TRUE |
| NOT | Reverses TRUE/FALSE |
Used to combine conditions: IF age >= 18 AND hasID = TRUE THEN
Benefits of Subprograms (2.6.1)
- Avoids code repetition (DRY principle)
- Improved readability — main program reads like high-level description
- Easier testing and debugging — modular isolation
- Team development — different developers per subprogram
- Reusability across programs
Subprograms can be user-written or pre-existing (built-in functions, libraries).
Procedures vs Functions (2.6.2)
- Procedure — performs task, does not return a value. Called as standalone statement.
- Function — performs task and returns a single value. Called within expression. Uses RETURN.
Pseudocode: PROCEDURE … END PROCEDURE; FUNCTION includes RETURN.
Parameters (2.6.3)
Parameters allow data to be passed into subprograms, making them flexible and reusable.
- Defined in subprogram header:
PROCEDURE Add(a, b) - Arguments supplied at call:
Add(5, 3) - Parameters are local to subprogram
- Multiple parameters separated by commas
