Computer Science (9618)
Topic 3 of 5Cambridge A Levels

Programming Fundamentals

Variables, data types, selection, iteration, procedures, functions, recursion, and OOP principles for CIE A Level CS 9618.

Stage 1: Topic Introduction Video

Start the topic with a quick definition, relevance, and learning outcomes before entering the full lesson body.

Introduction

30-60 sec

Hook the learner with a simple definition, relevance, and learning outcomes.

Placed at the beginning of the topic journey.

Dry-run assets generated

Written lesson and quiz remain available while this stage video is being prepared.

Branding: seekhoasaan-default-2026Narration: neutral-friendly-urdu-englishSubtitles: burned-in-dual-language

Programming Fundamentals — CIE A Level Computer Science 9618


1. Variables, Constants, and Data Types


Variable: Named memory location that stores a value which can change during execution.

Constant: Named value that cannot change during execution (e.g., PI = 3.14159).


Standard data types in 9618 pseudocode:


| Data Type | Description | Example |

|---|---|---|

| INTEGER | Whole numbers | 42, −7, 0 |

| REAL | Decimal numbers | 3.14, −0.5 |

| CHAR | Single character | 'A', '5', '!' |

| STRING | Sequence of characters | "Karachi", "A Level" |

| BOOLEAN | TRUE or FALSE | TRUE, FALSE |


Declaring variables:

~~~

DECLARE Name : STRING

DECLARE Age : INTEGER

DECLARE Score : REAL

DECLARE Passed : BOOLEAN

~~~


Type casting: Converting between types.

  • INT(3.7) → 3 (truncates)
  • STRING(42) → "42"
  • REAL("3.14") → 3.14

2. Selection Statements


IF-THEN-ELSE:

~~~

IF Score >= 70 THEN

Grade ← 'A'

ELSEIF Score >= 60 THEN

Grade ← 'B'

ELSE

Grade ← 'C'

ENDIF

~~~


CASE-OF (switch):

~~~

CASE OF Day

1 : OUTPUT "Monday"

2 : OUTPUT "Tuesday"

...

7 : OUTPUT "Sunday"

OTHERWISE : OUTPUT "Invalid"

ENDCASE

~~~


3. Iteration (Loops)


FOR loop: Used when number of iterations is known.

~~~

FOR i ← 1 TO 10

OUTPUT i * i

NEXT i

~~~


WHILE loop: Tests condition before each iteration.

~~~

WHILE Total < 100 DO

Total ← Total + Next

ENDWHILE

~~~


REPEAT-UNTIL: Executes at least once; tests condition after.

~~~

REPEAT

INPUT Number

UNTIL Number > 0

~~~


Key difference: WHILE can execute zero times; REPEAT-UNTIL executes at least once.


4. Arrays


1D Array:

~~~

DECLARE Marks : ARRAY[1:30] OF INTEGER

Marks[1] ← 85

OUTPUT Marks[1]

~~~


2D Array (e.g., seating plan):

~~~

DECLARE Seats : ARRAY[1:10, 1:20] OF CHAR

Seats[3, 7] ← 'X'

~~~

Stage 2: Mid-Lesson Concept Video

Inserted into lesson flow using deterministic content sectioning (split by nearest heading).

Concept Breakdown

60-120 sec

Teach the core concept step-by-step with at least one worked explanation.

Placed in the middle of the lesson flow.

Dry-run assets generated

Written lesson and quiz remain available while this stage video is being prepared.

Branding: seekhoasaan-default-2026Narration: neutral-friendly-urdu-englishSubtitles: burned-in-dual-language

Traversing an array:

~~~

FOR i ← 1 TO 30

Sum ← Sum + Marks[i]

NEXT i

Average ← Sum / 30

~~~


5. Procedures and Functions


Procedure: A named block of code that performs an action. No return value.

~~~

PROCEDURE PrintHeading(Title : STRING)

OUTPUT "=== " & Title & " ==="

ENDPROCEDURE


CALL PrintHeading("Results")

~~~


Function: Returns a single value.

~~~

FUNCTION Factorial(N : INTEGER) RETURNS INTEGER

IF N <= 1 THEN

RETURN 1

ELSE

RETURN N * Factorial(N - 1)

ENDIF

ENDFUNCTION


OUTPUT Factorial(5) // outputs 120

~~~


Parameters:

  • Pass by value: Procedure receives a copy — changes don't affect original.
  • Pass by reference: Procedure receives the original variable — changes persist.

6. Recursion


A function that calls itself. Every recursive function must have:

  1. A base case (terminating condition — stops recursion)
  2. A recursive case (calls itself with modified parameters moving toward base case)

Example — Factorial:

  • f(0) = 1 (base case)
  • f(n) = n × f(n−1) (recursive case)

f(4) = 4 × f(3) = 4 × 3 × f(2) = 4 × 3 × 2 × f(1) = 4 × 3 × 2 × 1 × f(0) = 24


Recursion vs iteration:

  • Recursion: elegant, matches mathematical definition — but uses more memory (call stack grows)
  • Iteration: more efficient in memory and speed — preferred for performance-critical code
  • Stack overflow: too many recursive calls can exhaust the call stack

7. Object-Oriented Programming (OOP)


Class: A blueprint/template defining attributes (data) and methods (behaviour).

Object: An instance of a class with specific attribute values.


Four pillars of OOP:


  1. Encapsulation: Bundling data and methods within a class; controlling access via PUBLIC/PRIVATE.
  • PRIVATE attributes: only accessible within the class (via getter/setter methods)
  • PUBLIC methods: accessible from outside

  1. Inheritance: A subclass inherits attributes and methods from a superclass (parent class).
  • Enables code reuse
  • Subclass can add new attributes/methods or override inherited ones

  1. Polymorphism: Same method name behaves differently in different classes.
  • Method overriding: subclass provides different implementation of inherited method

  1. Abstraction: Hiding complex implementation details; exposing only necessary interface.

Pseudocode example:

~~~

CLASS Animal

PRIVATE Name : STRING

PUBLIC PROCEDURE SetName(N : STRING)

Name ← N

ENDPROCEDURE

PUBLIC FUNCTION GetName() RETURNS STRING

RETURN Name

ENDFUNCTION

PUBLIC PROCEDURE Speak()

OUTPUT "..."

ENDPROCEDURE

ENDCLASS


CLASS Dog INHERITS Animal

PUBLIC PROCEDURE Speak() // method overriding

OUTPUT "Woof!"

ENDPROCEDURE

ENDCLASS

~~~


UML class diagram: Shows classes, attributes (+public, −private), methods, and relationships (inheritance arrow, association lines).

Key Points to Remember

  • 1Data types: INTEGER, REAL, CHAR, STRING, BOOLEAN — declare explicitly in 9618 pseudocode
  • 2Selection: IF-THEN-ELSEIF-ELSE-ENDIF; CASE-OF for multiple discrete values
  • 3Loops: FOR (known iterations), WHILE (test before), REPEAT-UNTIL (test after, runs at least once)
  • 4Recursion: needs base case + recursive case; elegant but stack-intensive; risk of stack overflow
  • 5Procedure: no return value; Function: returns value; pass by value vs pass by reference
  • 6OOP four pillars: Encapsulation (data hiding), Inheritance (code reuse), Polymorphism (overriding), Abstraction

Pakistan Example

OOP in Pakistan: University Management System

Pakistan's universities (LUMS, NUST, UET) build Student Management Systems using OOP. A base class `Person` has attributes Name, CNIC, Email and methods GetName(), SetEmail(). Two subclasses inherit from Person: `Student` adds RegNumber, CGPA, Semester and methods Enroll(), CheckFees(); `Faculty` adds EmployeeID, Department, Designation and methods TeachCourse(), SubmitGrades(). This is textbook inheritance — code for Person is written once and reused in both Student and Faculty. The `Speak()` equivalent would be `GenerateReport()` — a faculty generates a teaching report, a student generates a transcript — polymorphism. NADRA's ID system uses classes for Citizen, Passport, CNIC — all inheriting from a base IdentityDocument class. These are real-world Pakistani applications of 9618 OOP concepts.

Quick Revision Infographic

Computer Science — Quick Revision

Programming Fundamentals

Key Concepts

1Data types: INTEGER, REAL, CHAR, STRING, BOOLEAN — declare explicitly in 9618 pseudocode
2Selection: IF-THEN-ELSEIF-ELSE-ENDIF; CASE-OF for multiple discrete values
3Loops: FOR (known iterations), WHILE (test before), REPEAT-UNTIL (test after, runs at least once)
4Recursion: needs base case + recursive case; elegant but stack-intensive; risk of stack overflow
5Procedure: no return value; Function: returns value; pass by value vs pass by reference
6OOP four pillars: Encapsulation (data hiding), Inheritance (code reuse), Polymorphism (overriding), Abstraction
Pakistan Example

OOP in Pakistan: University Management System

Pakistan's universities (LUMS, NUST, UET) build Student Management Systems using OOP. A base class `Person` has attributes Name, CNIC, Email and methods GetName(), SetEmail(). Two subclasses inherit from Person: `Student` adds RegNumber, CGPA, Semester and methods Enroll(), CheckFees(); `Faculty` adds EmployeeID, Department, Designation and methods TeachCourse(), SubmitGrades(). This is textbook inheritance — code for Person is written once and reused in both Student and Faculty. The `Speak()` equivalent would be `GenerateReport()` — a faculty generates a teaching report, a student generates a transcript — polymorphism. NADRA's ID system uses classes for Citizen, Passport, CNIC — all inheriting from a base IdentityDocument class. These are real-world Pakistani applications of 9618 OOP concepts.

SeekhoAsaan.com — Free RevisionProgramming Fundamentals Infographic

Stage 3: End-of-Topic Summary Video

End the topic with a concise recap of key takeaways, formulas, and revision reminders.

Summary

30-60 sec

Provide a concise revision recap with key formulas/definitions and next steps.

Placed near the end of the topic journey.

Dry-run assets generated

Written lesson and quiz remain available while this stage video is being prepared.

Branding: seekhoasaan-default-2026Narration: neutral-friendly-urdu-englishSubtitles: burned-in-dual-language

Test Your Knowledge!

5 questions to test your understanding.

Start Quiz