💻 Year 8 Computer Science

Functions, databases, Boolean logic, operating systems, and cybersecurity — advancing from Year 7.

Functions & Procedures

Why Use Subprograms?

  • Break complex programs into smaller, manageable chunks
  • Avoid repeating code (DRY: Don't Repeat Yourself)
  • Easier to test, debug, and maintain
  • Can be reused in different parts of the same program or in other programs

Procedures vs Functions

  • Procedure: a named block of code that performs an action; does NOT return a value
  • Function: a named block of code that performs an action AND returns a value
Python Examples # Procedure (no return value) def greet(name): print("Hello, " + name) greet("Alice") # Output: Hello, Alice # Function (returns a value) def add(a, b): return a + b result = add(3, 5) # result = 8

Parameters and Arguments

  • Parameter: the variable in the function definition that receives a value
  • Argument: the actual value passed in when the function is called
  • A function can have multiple parameters separated by commas
  • Default parameter values: def greet(name="World") — if no argument given, "World" is used

Scope

  • Local variable: defined inside a function; can only be used inside that function
  • Global variable: defined outside any function; accessible throughout the program
  • Using global variables inside functions: use the global keyword in Python, or pass variables as parameters (preferred approach)

Lists, Files & String Manipulation

Lists (Arrays)

  • A list (called an array in most languages) stores multiple values in a single variable
  • Created with square brackets: fruits = ["apple", "banana", "cherry"]
  • Indexing: starts at 0. fruits[0] = "apple"; fruits[2] = "cherry"
  • Negative indexing: fruits[−1] = the last item ("cherry")
  • Key operations: append (add to end), remove, insert, sort, len (length), range
  • Iterating: for fruit in fruits: print(fruit)
  • List slicing: fruits[1:3] = ["banana", "cherry"] (from index 1 up to but not including index 3)

String Manipulation

  • Strings are sequences of characters; accessed like lists using indices
  • Concatenation: "Hello" + " " + "World" = "Hello World"
  • String methods: .upper(), .lower(), .strip() (remove whitespace), .replace(), .split()
  • .find() returns the index of a substring; returns −1 if not found
  • len("Hello") = 5 (number of characters)
  • f-strings: name = "Alice"; print(f"Hello, {name}!") → "Hello, Alice!"

File Handling

  • Programs can read and write data to text files for persistence
  • Open a file: file = open("data.txt", "r") — "r" = read; "w" = write (overwrites); "a" = append
  • Read: content = file.read() or for line in file: print(line)
  • Write: file.write("Hello World\n")
  • Always close: file.close() — or use the safer with statement:
Safe File Handling with open("data.txt", "r") as file: for line in file: print(line.strip()) # File closes automatically when the with block exits

Databases & SQL

What Is a Database?

  • An organised collection of data that can be easily accessed, managed, and updated
  • More powerful than a spreadsheet for large datasets: faster searching, relationships between data, multiple users
  • Relational database: data stored in tables (relations); tables are linked by relationships
  • Each row is a record; each column is a field; each table has a primary key (unique identifier for each record)

Key Database Terms

  • Primary key: a field that uniquely identifies each record (e.g. StudentID)
  • Foreign key: a field in one table that references the primary key of another table (creates a relationship between tables)
  • Attribute / Field: a category of information (column) — e.g. Name, DOB, Address
  • Record: a single row of data — all the information about one item
  • Query: a question asked of the database to retrieve specific data
  • DBMS (Database Management System): software for creating and managing databases (e.g. MySQL, SQLite, Microsoft Access)

SQL Basics

  • SQL (Structured Query Language) is the standard language for managing relational databases
  • Case insensitive, but convention is to write keywords in uppercase
Key SQL Commands SELECT name, age FROM Students WHERE age > 13; -- Retrieves name and age columns from Students table where age is over 13 SELECT * FROM Students ORDER BY name ASC; -- Retrieves all columns, sorted alphabetically by name SELECT * FROM Students WHERE name LIKE 'A%'; -- All students whose name starts with A INSERT INTO Students (name, age) VALUES ('Alice', 13); UPDATE Students SET age = 14 WHERE name = 'Alice'; DELETE FROM Students WHERE name = 'Alice';

Boolean Logic & Logic Gates

Boolean Values and Operations

  • Boolean: can be only True (1) or False (0)
  • AND: True only if BOTH inputs are True. Truth table: 0∧0=0, 0∧1=0, 1∧0=0, 1∧1=1
  • OR: True if AT LEAST ONE input is True. 0∨0=0, 0∨1=1, 1∨0=1, 1∨1=1
  • NOT: inverts the input. NOT 0 = 1; NOT 1 = 0
  • XOR (exclusive OR): True if inputs are DIFFERENT. 0⊕0=0, 0⊕1=1, 1⊕0=1, 1⊕1=0
  • NAND: NOT AND — opposite of AND. All True except when both inputs are 1.
  • NOR: NOT OR — opposite of OR. Only True when both inputs are 0.

Logic Gates

  • Logic gates are electronic circuits that implement Boolean operations
  • Each gate has standard symbol diagrams used in circuit drawings
  • AND gate: D-shaped body with flat left side
  • OR gate: curved body, arrow-shaped right side
  • NOT gate: triangle with a circle (bubble) at the output
  • NAND gate: AND with a bubble at the output
  • NOR gate: OR with a bubble at the output
  • XOR gate: OR gate with an extra curved line on the input side

Boolean Algebra

  • Simplifying Boolean expressions reduces the number of logic gates needed → cheaper circuits
  • Key laws: A AND 1 = A | A AND 0 = 0 | A OR 0 = A | A OR 1 = 1
  • NOT NOT A = A (double negation) | A AND A = A | A OR A = A
  • De Morgan's Laws: NOT(A AND B) = NOT A OR NOT B; NOT(A OR B) = NOT A AND NOT B
  • Applications: CPU design, memory addressing, search engines (Boolean search queries: "cats AND dogs", "cats NOT dogs")

Operating Systems

What Does an OS Do?

  • An operating system is system software that manages hardware and provides services to application software
  • Key functions: process management, memory management, file management, device management, user interface, security
  • Examples: Windows 11, macOS Sequoia, Ubuntu Linux, Android, iOS

Process Management

  • A process is a program that is currently being executed
  • The OS manages multiple processes simultaneously (multitasking) using the CPU scheduler
  • Process states: New → Ready → Running → Waiting → Terminated
  • CPU scheduling: decides which process runs next (Round Robin, Priority, First Come First Served)
  • Virtual memory: using part of the hard disk as if it were RAM when RAM is full — slower but prevents crashes

Memory Management

  • The OS allocates RAM to running processes and ensures they do not interfere with each other
  • Cache memory: faster than RAM, stores recently used data and instructions. L1 cache (fastest, smallest, inside CPU), L2 cache, L3 cache.
  • Paging: divides memory into fixed-size blocks (pages) for efficient allocation

File Systems

  • The OS manages how files are stored and retrieved on secondary storage
  • File systems: FAT32, NTFS (Windows), ext4 (Linux), APFS (macOS)
  • Files are organised in a hierarchical directory (folder) structure — a tree starting at the root
  • File permissions: read, write, execute — control who can access files
  • Fragmentation: files become split across non-contiguous disk sectors over time → slower access. Defragmentation reorganises files.

Cybersecurity In Depth

Social Engineering

  • Manipulating people into revealing confidential information rather than attacking systems directly
  • Phishing: fake emails from apparent trusted sources (banks, HMRC) requesting login details
  • Spear phishing: targeted phishing using personal information to appear genuine
  • Vishing: voice phishing — fake phone calls (e.g. "Your bank account has been compromised")
  • Smishing: SMS phishing — fake text messages with malicious links
  • Baiting: leaving infected USB drives in public places for curious people to pick up and plug in
  • Pretexting: creating a fabricated scenario to extract information (e.g. pretending to be IT support)

Malware In Depth

  • Virus: self-replicating code that attaches to legitimate programs; spread by human action (sharing files)
  • Worm: self-replicating; spreads independently across networks without human action
  • Trojan horse: disguises itself as legitimate software; does not self-replicate; opens a backdoor
  • Ransomware: encrypts victim's files; demands payment for decryption key. WannaCry (2017) affected the NHS.
  • Rootkit: hides its presence in the OS; gives attackers administrative access; very hard to detect
  • Keylogger: records every keystroke → captures passwords and private data
  • Adware: displays unwanted advertisements; often bundled with free software

Network Attacks

  • DDoS (Distributed Denial of Service): floods a server with requests from many infected machines (a botnet), making it unavailable to legitimate users
  • Man-in-the-middle (MITM): attacker secretly intercepts and possibly alters communications between two parties; often on unsecured public Wi-Fi
  • SQL injection: inserting malicious SQL code into a web form input to manipulate the database (e.g. logging in without a password, or extracting all user data)
  • Packet sniffing: capturing data packets as they travel across a network to steal unencrypted information
  • Brute force attack: systematically trying every possible password combination until one works

Protection Strategies

  • Encryption: data encrypted in transit (HTTPS/TLS) and at rest. Even if intercepted, data is unreadable without the key.
  • Firewall: monitors traffic using rules; can be hardware or software based
  • Intrusion Detection System (IDS): monitors for unusual network activity and alerts administrators
  • Two-factor / Multi-factor authentication (2FA/MFA): requires two forms of ID (password + SMS code / authenticator app / fingerprint)
  • Penetration testing: authorised simulated attacks by security professionals to identify weaknesses
  • Security policies: rules governing acceptable use, password policies, update schedules, incident response procedures
  • Software updates and patches: close known vulnerabilities; WannaCry exploited a Windows vulnerability for which a patch was available but many organisations hadn't applied