Define and use procedures and functions, with or without parameters

IGCSE Computer Science (0478) – Complete Revision Notes

1. Introduction

These notes cover every high‑weight topic of the Cambridge IGCSE Computer Science syllabus, with a special focus on defining and using procedures and functions (with or without parameters). Use them to revise, practise exam questions and build a solid mental model of how hardware, software and data interact.


2. Data Representation

2.1 Number Systems

  • Binary (base‑2) – each digit is a bit (0 or 1). 8‑bit byte = 2⁸ = 256 values.
  • Denary (base‑10) – the system we use in everyday life.
  • Hexadecimal (base‑16) – groups 4 bits; digits 0‑9 and A‑F.
  • Two’s‑complement (signed integers)
    • Positive numbers: normal binary.
    • Negative number: invert all bits, add 1.
    • Range for 8‑bit: –128 … +127.
  • Logical shifts
    • Left shift (<<) – moves bits towards more significant positions, inserting 0s on the right; multiplies by 2ⁿ.
    • Right shift (>> ) – moves bits towards less significant positions, inserting 0s on the left; divides by 2ⁿ (floor).

Worked Example – Binary ↔ Decimal ↔ Hex

Decimal 156 → binary:
156 ÷ 2 = 78 r0
78 ÷ 2 = 39 r0
39 ÷ 2 = 19 r1
19 ÷ 2 = 9  r1
9  ÷ 2 = 4  r1
4  ÷ 2 = 2  r0
2  ÷ 2 = 1  r0
1  ÷ 2 = 0  r1
Binary = 10011100₂
Hex = 9C₁₆

2.2 Text, Sound & Images

DomainKey ConceptsTypical Exam Task
ASCII / Unicode ASCII = 7‑bit (0‑127). Unicode extends to 16‑bit/32‑bit, allowing many world scripts. Give the binary code for ‘A’ (ASCII) and for ‘Ω’ (Unicode, 16‑bit).
Image resolution & colour depth Pixels = width × height.
File size = pixels × colour‑depth ÷ 8 (bytes).
Calculate the size of a 640 × 480 image at 24‑bit colour.
Sound sampling & resolution File size = sampling‑rate × bit‑depth × duration ÷ 8. Size of a 3‑minute mono audio at 44.1 kHz, 16‑bit.
Compression Lossless – original data can be perfectly restored (e.g., ZIP).
Lossy – some data discarded for smaller size (e.g., MP3, JPEG).
Explain why a JPEG image may look fuzzy after repeated saves.

Worked Example – Image File Size

Image: 640 × 480 pixels, colour depth = 24 bits.

pixels = 640 × 480 = 307 200
bits   = 307 200 × 24 = 7 372 800
bytes  = 7 372 800 ÷ 8 = 921 600 B ≈ 900 KB

Worked Example – Sound File Size

Audio: 3 min = 180 s, mono, 44.1 kHz, 16‑bit.

bits = 44 100 samples/s × 16 bits × 180 s = 127 008 000 bits
bytes = 127 008 000 ÷ 8 = 15 876 000 B ≈ 15.2 MB

3. Data Transmission

3.1 Packet Structure & Switching

  • Header – source/destination address, control information.
  • Payload – the actual data being transferred.
  • Trailer – error‑checking bits (e.g., CRC).
  • Circuit‑switched – a dedicated path is established for the whole session (e.g., old telephone networks).
  • Packet‑switched – data is broken into packets; each packet may travel a different route via routers.
  • Routers examine the destination address in each packet’s header and forward it toward the next hop.
  • Packet loss / re‑ordering can occur on congested networks; protocols such as TCP detect loss and request retransmission.

3.2 Error‑Detection Methods

MethodHow it worksTypical use
Parity bit Even or odd count of 1‑bits; a single‑bit error flips the parity. Simple serial links.
Checksum Add all data bytes, keep low‑order byte; complement may be sent. IP, UDP.
CRC (Cyclic Redundancy Check) Polynomial division on the bit stream; remainder is appended. Ethernet, storage devices – detects burst errors.
Check digit (mod‑10) Sum of digits modulo 10; used for barcodes, ISBN. Manual data entry validation.
ARQ (Automatic Repeat Request) Receiver asks sender to resend a packet if error detected. TCP reliability.

3.3 Encryption (Symmetric & Asymmetric)

  • Symmetric encryption – same secret key for encryption and decryption.
    • Example: Caesar cipher (shift each letter by 3).
      Plaintext “HELLO” → Ciphertext “KHOOR”.
  • Asymmetric encryption – a pair of keys: public (encrypt) and private (decrypt).
    • Example: “Alice publishes a public key; Bob encrypts a message with it; only Alice’s private key can decrypt.”

4. Hardware

4.1 Computer Architecture

  • Von Neumann architecture – single memory for data & instructions.
  • Fetch‑Decode‑Execute (FDE) cycle
    1. Fetch the next instruction from memory.
    2. Decode the instruction to determine the operation.
    3. Execute – ALU performs the operation or transfers data.
  • CPU components
    • Control Unit – directs the FDE cycle.
    • ALU – arithmetic and logical operations.
    • Registers – small, fast storage inside the CPU.
  • Cache – fast memory close to the CPU; a cache hit reduces access time dramatically.
  • Multi‑core – each core can execute its own instruction stream, improving parallel performance.
  • Clock speed – measured in MHz or GHz; determines how many cycles per second.
  • Instruction set – the set of operations a CPU understands (e.g., RISC vs. CISC).

4.2 Input/Output Devices & Sensors/Actuators

  • Input devices – keyboard, mouse, scanner, microphone, touch screen.
  • Sensors – convert a physical quantity to an electrical signal (e.g., temperature sensor, light sensor).
  • Actuators – convert an electrical signal into physical action (e.g., motor, speaker, LED).

4.3 Data Storage

TypeCharacteristics
Primary (volatile) RAM – fast, loses data when power is removed.
Secondary (non‑volatile) Magnetic (HDD), Optical (CD/DVD), Flash (SSD, USB).
Virtual memory Part of secondary storage used as an extension of RAM; managed by the OS.
Cloud storage Data stored on remote servers accessed via the Internet.

Advantages & Disadvantages of Cloud vs. Local Storage

  • Advantages of cloud
    • Access from any device with Internet.
    • Automatic backup and scalability.
    • Reduced need for local hardware.
  • Disadvantages of cloud
    • Requires reliable Internet connection.
    • Potential security & privacy concerns.
    • Ongoing subscription costs.
  • Advantages of local storage
    • Fast access, no Internet needed.
    • Full control over data security.
  • Disadvantages of local storage
    • Risk of loss from hardware failure.
    • Limited capacity unless upgraded.

4.4 Network Hardware

DeviceFunction
NIC (Network Interface Card)Provides a physical connection to a network; handles framing.
HubRepeats incoming signals to all ports; no intelligence, can cause collisions.
SwitchForwards frames only to the destination port using MAC addresses; reduces collisions.
RouterRoutes packets between different networks; uses IP addresses.
FirewallFilters traffic based on rules; can be hardware or software.

5. Software

  • System software: Operating system, device drivers, utility programs.
  • Application software: Word processors, browsers, games, database systems.
  • Operating system functions
    • Resource management (CPU, memory, I/O).
    • File system control.
    • Multitasking & process scheduling.
    • Security & user authentication.
  • Interrupts
    • Hardware interrupt – generated by an external device (e.g., keyboard press).
    • Software interrupt – generated by a program (e.g., system call).
  • Language levels: Machine → Assembly → High‑level → Natural‑language.
  • Compilers vs. Interpreters
    • Compiler – translates the whole program to machine code before execution.
    • Interpreter – translates and executes line‑by‑line at run‑time.
  • Integrated Development Environment (IDE) – editor, debugger, auto‑complete, version‑control integration.

Match‑the‑Definition

TermDefinition
DriverSoftware that allows the OS to communicate with hardware.
MultitaskingRunning more than one process at the same time.
Garbage collectionAutomatic reclamation of memory that is no longer referenced.

6. Internet & Its Uses

  • Internet vs. World Wide Web – Internet = global network of networks; WWW = collection of web pages accessed via HTTP/HTTPS.
  • URL structureprotocol://domain[:port]/path?query#fragment.
  • HTTP/HTTPS – request‑response protocol; HTTPS adds TLS encryption.
  • Cookies – small pieces of data stored on the client to maintain state.
  • Digital currency (e.g., Bitcoin) – uses cryptographic hashing and a public ledger (blockchain).
  • Cyber‑security basics
    • Phishing – deceptive e‑mail or website.
    • Malware – viruses, worms, ransomware.
    • Firewalls – filter incoming/outgoing traffic.

Web‑Request Flow (simplified)

Client → HTTP GET → Router → Server
Server processes request → HTTP RESPONSE → Router → Client → Browser renders page

7. Automated & Emerging Technologies

  • Sensors & Actuators – convert physical quantities to digital signals and vice‑versa.
  • Robotics – integration of sensors, actuators, control software; often driven by a microcontroller.
  • Artificial Intelligence
    • Expert system – rule‑based decision making.
    • Machine learning – algorithms improve from data (e.g., linear regression, decision trees).

Rule‑Based AI Example (Pseudocode)

PROCEDURE DiagnosePlant(temp, wilting)
    IF temp > 30 AND wilting = TRUE THEN
        RETURN "Water stress"
    ELSE IF temp < 10 THEN
        RETURN "Cold stress"
    ELSE
        RETURN "Healthy"
    END IF
END PROCEDURE

8. Algorithm Design & Problem Solving

  1. Problem‑solving cycle (PDLC): Analyse → Design → Implement → Test → Evaluate.
  2. Decomposition – break a problem into smaller sub‑problems.
  3. Flowcharts – standard symbols: process, decision, input/output, loop.
  4. Validation & Verification
    • Validation – does the program meet user needs?
    • Verification – does the code do what the design specifies?
  5. Trace tables – track variable values step‑by‑step.

Linear Search – Flowchart to Pseudocode

PROCEDURE LinearSearch(list, key)   // list = array, key = value to find
    index ← 0
    WHILE index < LENGTH(list) DO
        IF list[index] = key THEN
            RETURN index          // found
        END IF
        index ← index + 1
    END WHILE
    RETURN -1                     // not found
END PROCEDURE

9. Core Programming Concepts

ConceptWhat you must know
Variables & Data Types Integer, Real, Boolean, Character, String, Array. Scope (local vs. global).
Input / Output READ/INPUT, PRINT/OUTPUT statements; formatting of numbers and strings.
Selection If‑Then‑Else, nested if, (optional) switch‑case.
Iteration FOR, WHILE, REPEAT‑UNTIL loops; loop counters and termination conditions.
Arrays One‑dimensional; indexing starts at 0 or 1 (specify). Bounds checking.
File handling OPEN, READ, WRITE, CLOSE; text vs. binary files; sequential access.

Mini‑Project – Read, Sort & Write Scores

PROCEDURE Main()
    OPEN "scores.txt" FOR READ AS inFile
    scores ← []
    WHILE NOT EOF(inFile) DO
        line ← READLINE(inFile)
        scores ← scores + [INTEGER(line)]
    END WHILE
    CLOSE inFile

    CALL BubbleSort(scores)          // procedure – no return value

    OPEN "sorted.txt" FOR WRITE AS outFile
    FOR i FROM 0 TO LENGTH(scores)-1 DO
        WRITELINE(outFile, STRING(scores[i]))
    END FOR
    CLOSE outFile
END PROCEDURE

PROCEDURE BubbleSort(arr)
    n ← LENGTH(arr)
    REPEAT
        swapped ← FALSE
        FOR i FROM 0 TO n-2 DO
            IF arr[i] > arr[i+1] THEN
                temp ← arr[i]
                arr[i] ← arr[i+1]
                arr[i+1] ← temp
                swapped ← TRUE
            END IF
        END FOR
        n ← n - 1
    UNTIL NOT swapped
END PROCEDURE

CALL Main()

10. Procedures and Functions (with or without Parameters)

10.1 Definitions

  • Procedure – a named block of code that performs an action. May accept parameters but does not return a value. Called with CALL (or simply the name in some languages).
  • Function – a named block that performs a calculation and returns exactly one value. May also accept parameters. The returned value is assigned with the assignment operator ( or =).

10.2 Key Differences

AspectProcedureFunction
PurposeCarry out a task (e.g., display, modify data)Compute and return a value
Return valueNone (uses CALL)Single value (assigned to a variable)
Typical useI/O, updating structures, calling other sub‑programsMathematical calculations, data conversion
Invocation syntaxCALL ProcName(arg1, arg2)result ← FuncName(arg1, arg2)
Scope of parametersPassed by value (original unchanged) or by reference (original can be changed).Usually passed by value; the function cannot alter the caller’s variables unless reference is allowed.

10.3 Parameter Types

  • No parameters – useful for actions that always behave the same (e.g., display a welcome message).
  • Input parameters – values supplied by the caller; read‑only inside the sub‑program.
  • Output parameters – variables whose values are set by the sub‑program and returned to the caller (common in some languages).
  • Input‑output parameters – both read and modified by the sub‑program.

10.4 Example – Procedure without Parameters

PROCEDURE ShowHeader()
    PRINT "=== Student Scores ==="
END PROCEDURE

CALL ShowHeader()

10.5 Example – Procedure with Parameters (by value)

PROCEDURE Increment(val)
    val ← val + 1          // local copy only
END PROCEDURE

x ← 5
CALL Increment(x)
PRINT x    // still 5

10.6 Example – Procedure with Parameters (by reference)

PROCEDURE IncrementRef(REF val)
    val ← val + 1          // modifies caller's variable
END PROCEDURE

x ← 5
CALL IncrementRef(x)
PRINT x    // now 6

10.7 Example – Function without Parameters

FUNCTION GetRandomNumber()
    RETURN 42               // placeholder for a real RNG
END FUNCTION

num ← GetRandomNumber()
PRINT num

10.8 Example – Function with Input Parameters

FUNCTION AreaRectangle(width, height)
    RETURN width * height
END FUNCTION

area ← AreaRectangle(7, 3)
PRINT "Area =", area

10.9 Example – Function Returning a Value Used Directly

PRINT "The maximum is", MAX(12, 27)   // MAX is a built‑in function

10.10 Recursion (Function calling itself)

FUNCTION Factorial(n)
    IF n = 0 THEN
        RETURN 1
    ELSE
        RETURN n * Factorial(n-1)
    END IF
END FUNCTION

PRINT Factorial(5)   // outputs 120

10.11 Common Pitfalls for the Exam

  • Confusing procedure with function – remember only functions return a value.
  • Omitting parentheses when a function has no parameters (e.g., NOW()).
  • Mixing up call syntax: CALL for procedures, assignment for functions.
  • For parameters passed by reference, the original variable is changed; this is often tested.
  • Recursive functions must have a clear base case to avoid infinite recursion.

10.12 Quick Revision Checklist

  1. Can you write the syntax for a procedure and a function?
  2. Do you know the difference between input, output and input‑output parameters?
  3. Can you explain why a function must return exactly one value?
  4. Are you comfortable tracing a call where a procedure modifies a variable by reference?
  5. Can you recognise a recursive function and identify its base case?

11. Summary of High‑Weight Topics for the Exam

  • Number systems, logical shift, two’s‑complement.
  • ASCII vs. Unicode, image & sound file‑size calculations, compression.
  • Packet structure, routers, packet loss, CRC, ARQ.
  • Symmetric & asymmetric encryption (simple examples).
  • Von Neumann architecture, FDE cycle, cache, multi‑core, instruction set.
  • Sensors & actuators, cloud vs. local storage.
  • Network devices – NIC, hub, switch, router, firewall.
  • Procedures vs. functions, parameter passing, recursion.
  • Algorithm design – flowcharts, trace tables, validation/verification.

Use these notes to practise past‑paper questions, write your own pseudocode, and test yourself with the quick‑check questions at the end of each section. Good luck!

Create an account or Login to take a Quiz

42 views
0 improvement suggestions

Log in to suggest improvements to this note.