0984

Programming Concepts

Programming · 4 question types

Exam Frequency Analysis

Past paper frequency (2018 to 2024)

This topic accounts for approximately 13% of your exam marks.

stable
High
Stable13%

Paper 2 is almost entirely programming. Variable types, assignments, loops and conditionals are tested every session.

A string is a sequence of characters such as "Hello world" or "PASSWORD123". CIE pseudocode names four string operations you must know.

LENGTH

LENGTH(s) returns the number of characters in the string s.

Password ← "letmein"
OUTPUT LENGTH(Password)      // outputs 7

Name ← ""
OUTPUT LENGTH(Name)          // outputs 0 (empty string)

A common use is validation: rejecting a password that is too short.

INPUT Password
IF LENGTH(Password) < 8
   THEN
      OUTPUT "Password must be at least 8 characters"
ENDIF

SUBSTRING

SUBSTRING(s, start, length) returns a piece of the string s, beginning at position start and length characters long.

In CIE pseudocode, strings are 1-indexed: the first character is at position 1.

Word ← "Revision"
OUTPUT SUBSTRING(Word, 1, 3)   // outputs "Rev"
OUTPUT SUBSTRING(Word, 4, 5)   // outputs "ision"
OUTPUT SUBSTRING(Word, 1, 1)   // outputs "R"

Useful for extracting parts of formatted data: e.g. taking the first three letters of a postcode, or splitting a date string "05/12/2024" into day, month and year.

UCASE (uppercase)

UCASE(s) returns the string s with every letter changed to uppercase.

Name ← "Sarah"
OUTPUT UCASE(Name)             // outputs "SARAH"

LCASE (lowercase)

LCASE(s) returns the string s with every letter changed to lowercase.

Name ← "SARAH"
OUTPUT LCASE(Name)             // outputs "sarah"

Putting them together

A common idiom: standardise an input before comparing it so that minor differences in case do not cause false rejections.

Exam tip

Using string functions in pseudocode

What comes up: Questions give a short piece of pseudocode using SUBSTRING, LENGTH, LCASE, or UCASE and ask you either to write pseudocode that uses them correctly or to trace through the output. This question type recurs across multiple papers.

Write (key points): (1) CIE strings are 1-indexed: the first character is at position 1, not 0. When using SUBSTRING(s, start, length), count characters from 1. (2) LENGTH(s) returns the total number of characters — use it for validation (e.g. checking a password is at least 8 characters long). (3) To compare input case-insensitively, convert with LCASE or UCASE before comparing, so that "YES" and "yes" are treated the same.

Watch out: A common slip is to start counting from 0 (as in Python). In CIE pseudocode, position 1 is always the first character. Using SUBSTRING(s, 0, n) or starting at 0 will cost marks.