Library › Computer Science 9618 › Programming
AS Level · Computer Science 9618

Programming

Revise Programming for Computer Science 9618 (AS Level) — revision notes and instant AI marking.

📖 Revision notes · preview
  Cambridge International AS & A Level Computer Science (9618)

Programming

The big idea: Paper 2 marks your pseudocode the way a compiler would read it: declared variables, the right construct for the job, and procedures and functions with clear interfaces. Write it in the Cambridge style and every line earns its mark.

Summary — What This Chapter Covers
  • Declare constants with CONSTANT (literal values only) and variables with DECLARE Name : TYPE; assign with ←.
  • Data types: INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE. A REAL literal always has a digit either side of the point (4.0, 0.5).
  • Arithmetic: + − * /, DIV (quotient) and MOD (remainder). "/" always gives a REAL.
  • Built-in functions you are given in the insert: LEFT, RIGHT, MID, LENGTH, TO_UPPER, TO_LOWER, NUM_TO_STR, STR_TO_NUM, IS_NUM, ASC, CHR, INT, RAND, the date functions and EOF.
  • Selection: IF … THEN … ELSE … ENDIF (nested where needed) and CASE OF … OTHERWISE … ENDCASE, including ranges such as 70 TO 100.
  • Iteration: count-controlled FOR … NEXT, post-condition REPEAT … UNTIL (runs at least once), pre-condition WHILE … ENDWHILE (may run zero times).
  • Procedures are called with CALL; functions return one value and are used inside an expression. Parameters are passed BYVAL (default) or BYREF.
  • Know the vocabulary: header, interface, parameter, argument, return value, local and global variables.
1. Programming Basics
11.1

Constants, variables, assignment, input and output

Every Paper 2 algorithm starts with the data it needs. A variable holds a value that can change while the program runs; a constant is fixed when the program is written. Declare both at the top so the reader (and the examiner) can see the types.

CONSTANT MaxMark = 100
CONSTANT PassText = "Pass"
DECLARE StudentName : STRING
DECLARE Mark : INTEGER
DECLARE Percentage : REAL
DECLARE Passed : BOOLEAN

INPUT StudentName
INPUT Mark
Percentage ← (Mark / MaxMark) * 100
Passed ← Percentage >= 50
OUTPUT StudentName, " scored ", Percentage, "%"

A constant may only be given a literal: CONSTANT Limit = MaxMark * 2 is not allowed. Constants make code easier to read and to update, because the value is changed in one place.

Operators
OperatorMeaningExampleResult
+ − * /add, subtract, multiply, divide (always REAL)7 / 23.5
DIVinteger quotient17 DIV 53
MODremainder17 MOD 52
= <> < > <= >=comparison, gives BOOLEAN"cat" = "Cat"FALSE (case sensitive)
AND OR NOTlogic on BOOLEAN valuesNOT (3 > 2)FALSE
&join strings (or a CHAR to a STRING)"Al" & "i""Ali"
Built-in functions and library routines

You never have to memorise exact string functions: the exam insert lists them. What you must do is use them correctly: count positions from 1, and give MID a start and a length, not a start and an end.

FunctionReturnsExample
LEFT(S, x) / RIGHT(S, x)leftmost / rightmost x charactersLEFT("ABCDEFGH", 3) → "ABC"
MID(S, x, y)y characters starting at position xMID("ABCDEFGH", 2, 3) → "BCD"
LENGTH(S)number of charactersLENGTH("Happy Days") → 10
TO_UPPER(x) / TO_LOWER(x)x converted (CHAR or STRING)TO_UPPER("Error 803") → "ERROR 803"
NUM_TO_STR(x) / STR_TO_NUM(x)convert between number and stringSTR_TO_NUM("23.45") → 23.45
IS_NUM(S)TRUE if S is a valid numberIS_NUM("-12.36") → TRUE
ASC(c) / CHR(x)ASCII value / characterASC('A') → 65, CHR(66) → 'B'
INT(x)integer part of a REALINT(27.5415) → 27
RAND(x)
Worked Example
Practice Question
🔓 Read the full Programming note → You're seeing the preview · sign in to read it all
Also in the full note
  • Selection and the three loops
  • Procedures, functions and parameters
What's inside
📖 Revision notes 🎯 Learn mode ✦ AI flashcards ✓ Instant AI marking 🧊 3D explorers 🧪 Experiments & simulations 📈 Progress tracking
📄 Practise Programming with Computer Science 9618 past papers Every paper with its mark scheme — answer online, marked instantly. Open →

Read the full Programming notes free

That's the preview — create a free account to read the rest, plus flashcards and practice questions with instant AI marking. No credit card.

Unlock the full notes free →

More Computer Science topics