7.2

7.2 Sub-Systems & Decomposition

Understanding that computer systems are made of sub-systems, which are made of further sub-systems — and how to decompose a problem into inputs, processes, outputs and storage.

Learning Objectives

By the end of this lesson, you will be able to:

  • Understandthat every computer system is made up of sub-systems, which are made up of further sub-systems
  • Identifythe five main sub-systems of a computer: CPU, memory, storage, input devices and output devices
  • Explainthe advantages of using sub-systems, including troubleshooting, software development and system design
  • Understandhow a problem can be decomposed into its component parts
  • Identifythe inputs, processes, outputs and storage requirements of a given problem
  • Usestructure diagrams and step-wise refinement to design a solution to a problem
  • Create, interpret, correct and refinealgorithms using flowcharts and CIE pseudocode

Key Terms

Sub-system

A smaller part of a computer system that works together with other sub-systems to create a fully functional computer system.

Hierarchical structure

A system composed of sub-systems, which are themselves composed of smaller sub-systems. Each level represents a different level of abstraction and functionality.

Central Processing Unit (CPU)

The primary sub-system that executes instructions. Its own sub-systems include the Control Unit, registers and the Arithmetic Logic Unit (ALU).

Memory (RAM)

A primary sub-system that stores data and instructions temporarily for the CPU. Its sub-systems include cache memory and main memory.

Storage

A primary sub-system that stores data and software permanently (HDD, SSD). Its sub-systems include the file system and disk controller.

Input devices

Primary sub-systems that allow a user to enter information (keyboard, mouse). Sub-systems include the keyboard controller and mouse interface.

Output devices

Primary sub-systems that display information or create a physical output (monitor, printer). Sub-systems include the graphics controller and printer interface.

Decomposition

Breaking a complex problem down into smaller, more manageable parts, each of which can be solved, tested and combined to solve the full problem.

Inputs

The data or information provided to the system for processing — the raw materials needed to solve the problem.

Processes

The operations or actions performed on the inputs to produce the desired outputs, including algorithms, calculations and transformations.

Outputs

The results or outcomes produced by processing the inputs. They represent the solution to the problem.

Storage

The temporary or permanent holding of data during the problem-solving process, such as intermediate results or historical records.

Structure diagram

A method of designing a solution to a problem by decomposing it into sub-problems, produced using step-wise refinement.

Step-wise refinement

The approach used to create structure diagrams — repeatedly breaking down each stage that is still too complex into smaller, more manageable chunks.

Flowchart

A method of representing the sequence of steps in an algorithm in the form of a diagram, using standard symbols.

Pseudocode

A text-based way of representing the sequence of steps in an algorithm — a simplified form of programming code that does not worry about the rules and syntax of a particular language.

1. Computer Sub-Systems (7.2a)

Computer systems range fromsmall and simpletolarge and complex. Almost all computer systems can bebroken down into sub-systems. These sub-systems can typically be broken down intofurther sub-systems. Eventually, each sub-system performs asingle task or action.

What is a sub-system?

Asub-systemis a smaller part of a computer system that works together with other sub-systems to create a fully functional computer system.

1.1 The Car Analogy

A car is a great example of using sub-systems. A car will only function if its sub-systems all work together:

Engine

Sub-systems: spark plugs, sensors, pistons

Brakes

Sub-systems: brake pads, discs, fluid lines

Wheels

Sub-systems: tyres, rims, valves

Sub-systems can be broken down intoeven smaller sub-systems. For example, the engine can be broken down into spark plugs, sensors and pistons. Each of those could be broken down further until each part performs a single task.

1.2 The Five Main Computer Sub-Systems

Sub-systemFunctionExamples of further sub-systems
Central Processing Unit (CPU)Executes instructionsControl unit, registers, Arithmetic Logic Unit (ALU)
Memory (RAM)Stores data & instructions temporarily for the CPUCache memory, main memory
StorageStores data and software permanentlyHDD, SSD, file system, disk controller
Input devicesAllows a user to enter informationKeyboard, mouse, keyboard controller, mouse interface
Output devicesDisplays information or creates a physical outputMonitor, printer, graphics controller, printer interface

Interactive: Personal Computer Sub-System Hierarchy

A personal computer is a computer system composed of several primary sub-systems. Each primary sub-system contains further sub-systems, creating a hierarchical structure.Click any nodeto see details.

Personal Computer
CPU
Memory (RAM)
Storage
Input Devices
Output Devices

Click a sub-system aboveto explore its further sub-systems.

Hierarchical structure:Each level of this hierarchy represents a different level of abstraction and functionality. The CPU itself can be broken down into the Control Unit, registers and the ALU.

1.3 Example: Space Invaders

Take the example of the classic shooterSpace Invaders. Analysis reveals many different sub-systems in the game:

Gameplay sub-systems

  • Move player
  • Fire missile
  • Move player missile
  • Move aliens
  • Aliens fire
  • Move alien missile

Collision & end-game sub-systems

  • Player collision
  • Aliens collision
  • Missile collision
  • Alien missile collision
  • UFO collision
  • Check win/lose, Game over, Title screen, Settings

The structure diagram below shows how the arcade shooter can be broken down into its various sub-problems. This is one example of applying the analysis and design skill ofdecomposition.

Arcade Shooter
Title Screen
Game
End Game
Settings
Swarm
Player Ship
Player Missile
Enemy Missiles
UFO
Game Over

1.4 Advantages of Sub-Systems

Troubleshooting

Can help troubleshoot problems in a computer system. The ability toisolate a sub-systemmakes it easier to identify and fix issues, as each sub-system can be examined separately.

Software development

Developing software relies on the use of different sub-systems to ensure they operate efficiently.

Clear picture

Gives developers and designers a clear picture of how sub-systems help build complex systems.

Activity 1: Sub-System Hunt

A tablet computer is a computer system. Its primary sub-systems include the CPU, memory, storage, input devices and output devices. However, this tablet also has atouchscreen, abatteryand acamera.

  1. Classify the touchscreen, battery and camera into the most appropriate primary sub-system (or explain why they might be considered sub-systems of their own).
  2. The CPU of the tablet can be broken down into three further sub-systems. Name them.
  3. Explain how the idea of sub-systems helps a technician who is repairing a broken tablet.
Solution:
  1. Classification:
    • Touchscreen— acts as both an input device (touch input) and an output device (display). It combines two primary sub-systems.
    • Battery— provides power. It is not one of the five listed primary sub-systems, so it can be treated as a separate sub-system of the tablet.
    • Camera— an input device (captures images) but also produces an output (the image file), so it can be considered an input sub-system (or a sub-system of its own).
  2. CPU sub-systems:Control Unit, registers, Arithmetic Logic Unit (ALU).
  3. Troubleshooting benefit:The technician can isolate each sub-system and test it separately. For example, if the tablet does not charge, the technician can check the battery sub-system first, then the charging port, then the power control circuit — rather than having to test the whole tablet at once. This makes it faster and easier to identify and fix the faulty part.

Check Your Understanding: Computer Sub-Systems

Answer
  • [1 mark]A smaller part of a computer system
  • [1 mark]That works together with other sub-systems to create a fully functional computer system
Answer
  • [2 marks]Central Processing Unit (CPU)— executes instructions
  • [2 marks]Memory— stores data & instructions temporarily for the CPU (RAM)
  • [2 marks]Storage— stores data and software permanently (HDD, SSD)
  • [2 marks]Input devices— allow a user to enter information (keyboard, mouse)
  • [2 marks]Output devices— display information or create a physical output (monitor, printer)
Answer
  • [1 mark]CPU sub-system: Arithmetic Logic Unit (ALU) / Control Unit / registers
  • [1 mark]Storage sub-system: File system / disk controller
Answer
  • [1 mark]The ability to isolate a sub-system makes it easier to identify issues
  • [1 mark]Each sub-system can be examined separately, rather than having to test the whole system at once
  • [1 mark]This makes it easier and faster to fix the problem — once the faulty sub-system is found, it can be repaired or replaced
Answer
  • [1 mark]Cache memory
  • [1 mark]Main memory
Answer
  • [1 mark]It gives developers and designers a clear picture of how sub-systems help build complex systems
  • [1 mark]Software development relies on the use of different sub-systems to ensure they operate efficiently, so designers can plan each part separately

2. Problem Decomposition (7.2b)

Decompositionis the process ofbreaking down a large problem into a set of smaller problems. Dealing with many different stages of a large problem at once is much more difficult than breaking it down into a number of smaller problems and solving them one at a time.

2.1 Benefits of Decomposition

Easier to solve

Smaller problems are easier to solve than one big problem.

Independent solutions

Each smaller problem can be solved independently of the others.

Independent testing

Smaller problems can be tested independently.

Combined solution

Smaller problems can be combined to produce a solution to the full problem.

Advantages of problem decomposition
  • Makes problems easier to solve.
  • Different people can work on different parts of a problem at the same time, reducing development time.
  • Program components developed in one program can easily be used in other programs.

2.2 Decomposition in Daily Life

You do many complex tasks on a daily basis, and you break them down into steps without even thinking about it:

Getting up in the morning

Brushing your teeth

Travelling to school

Doing your homework

Example: Crossing the Road

Even an everyday problem like crossing the road can be broken down into sub-problems:

  1. Stop before crossing.
  2. Look left and right.
  3. Is the road clear?
  4. If not, press the button.
  5. Wait for the lights to turn red.
  6. Cross the road when it's safe.

Example: A Complex Game

Modern computer games are a good example of using decomposition to break down the complexity of the problem into more manageable chunks. Creating an entire game at once would be challenging and inefficient, so it could be decomposed into:

  • Levels— Levels can be designed/created/tested independently of other levels.
  • Characters— The mechanics of characters in the game can be designed and created by a separate team.
  • Landscape— The art team can work on the visual aspects of the game without needing to understand how the game is programmed.

Once all of the smaller problems are completed and joined together, a complex game has been created.

2.3 Decomposition Example: Breakout Clone

How the game works:The player controls the paddle at the bottom of the screen. The paddle can be moved left and right. When the ball bounces off the paddle, it is redirected towards the blocks above. If the ball hits a block, that block is removed. The aim is to remove all the blocks. If the ball leaves the bottom of the screen, the player loses a life.

How could we use decomposition to help us break down the process of programming this game?

Interactive: Decomposing the Breakout Clone

Click each button to build up the game piece by piece. Each click reveals one more sub-problem that must be solved.

Click "Next Sub-Problem"to see how the Breakout clone is broken down.

Decomposition in action:By breaking the game down into these sub-problems, each one can be solved, tested and coded independently. Once all parts work, they are combined to produce the full game.

2.4 Decomposition Tree

When we decompose a problem, we can show the structure using a tree diagram. The "Big problem" at the top is broken down into main components, and each main component is broken down into sub-problems.

Big problem
Main component 1
Main component 2
Sub-problem 1
Sub-problem 2
Sub-problem 3
Sub-problem 4

Activity 2: Decompose a School Event

Your school is organising a charity fun run. The "big problem" is to run the event successfully.

  1. Decompose this problem into at least three main components.
  2. Decompose one of those main components into at least three sub-problems.
  3. Explain how one of these sub-problems could be tested independently before the event.
Solution:
  1. Main components (example):
    • Organising the route
    • Managing participants (registration, numbers, safety)
    • Fundraising and sponsorship
    • Health, safety and first aid
  2. Sub-problems of "Managing participants":
    • Design a registration form (paper or online)
    • Collect entry fees and record payments
    • Assign each runner a race number
    • Check that each participant has returned a signed consent form
  3. Independent testing:The registration form sub-problem could be tested independently by giving it to a small group of students first. If they can fill it in easily and the organisers get all the information they need (name, age, emergency contact, consent), the form is ready to use with everyone else.

Check Your Understanding: Decomposition

Answer
  • [1 mark]Decomposition is breaking a complex problem down into smaller, more manageable parts
  • [1 mark]Smaller problems are easier to solve, can be solved independently, and can be tested independently
  • [1 mark]The smaller problems can be combined to produce a solution to the full problem, and different people can work on different parts at the same time
Answer
  • [1 mark]Smaller problems are easier to solve / each smaller problem can be solved independently
  • [1 mark]Smaller problems can be tested independently
  • [1 mark]Smaller problems can be combined to produce a solution to the full problem; components developed in one program can easily be used in other programs
  • [Additional]Different people can work on different parts of a problem at the same time, reducing development time
Answer
  • [1 mark]Display the paddle on-screen
  • [1 mark]Allow the paddle to move left and right, preventing it from moving off the left or right edge of the screen
  • [1 mark]Display the ball on-screen and program its movement
  • [1 mark]Display the blocks on-screen and program collision detection
  • [1 mark]Implement winning and losing / Add extras: sounds, effects, graphics, background
Answer
  • [1 mark]Different people can work on different parts of the problem at the same time
  • [1 mark]This reduces development time because the work is shared
  • [1 mark]For example, the art team can work on the landscape while another team designs the character mechanics, and a third team works on game levels
Answer
  • [1 mark]Decide what to eat
  • [1 mark]Gather the ingredients and equipment
  • [1 mark]Prepare the food (e.g. pour cereal, boil water, toast bread)
  • [1 mark]Serve the food and clean up afterwards

3. Inputs, Processes, Outputs and Storage (7.2b)

Decomposing a problem requires developers to think about four component parts:inputs,processes,outputsandstorage. An electronic device takes input, processes data, delivers output and may store data for later use.

The Input-Process-Output-Storage Model

INPUT
e.g. 5
PROCESS
e.g. Multiply by 2
STORAGE
Saved for later
OUTPUT
e.g. 10

How it works:The input (5) is processed (multiplied by 2) to produce an output (10). Storage may be used to hold data during processing or to save results for future retrieval.

3.1 Definitions of the Four Components

Inputs

The data or information provided to the system for processing. They are the raw materials needed to solve the problem.

  • Can come from user input, sensors, files or databases
  • Anything that needs to be supplied to the program so it can meet its goals
  • Consider an appropriate variable name and data type for inputs

Processes

The operations or actions performed on the inputs to produce the desired outputs. They involve algorithms, calculations, manipulations and transformations.

  • Calculations that need to be performed while the program is running
  • Consider whether any data need to change format or data type

Outputs

The results or outcomes produced by processing the inputs. They represent the solution to the problem.

  • Can take various forms: visual displays, reports, files or signals
  • Consider what the program needs to output, what form it should take, and an appropriate variable name and data type

Storage

The temporary or permanent holding of data during the problem-solving process.

  • Data may need to be stored for intermediate results, user preferences, or historical records
  • Consider any data that needs to be stored in files on an appropriate medium for use or retrieval in the future
  • Proper storage management ensures data is accessible, accurate and secure when needed

3.2 Example: Area of a Rectangle Program

ComponentDetails
InputsWidth of the rectangle
Height of the rectangle
ProcessesWidth × height
OutputsCalculated area of the rectangle
StorageMemory: width, height and area stored temporarily

3.3 Example: Fish Tank Volume

"Write a program to calculate the volume of a fish tank based on its dimensions, and report the result to the user."

InputProcessOutputStorage
Length: Real/float
Height: Real/float
Depth: Real/float
Length × Height × DepthVolume: Real/float

"Write a program to calculate the volume of a fish tank based on its dimensions, report the result to the userand write the results to a text file."

InputProcessOutputStorage
Length: Real/float
Height: Real/float
Depth: Real/float
Length × Height × DepthVolume: Real/floatVolume: Real/float (written to a text file)

3.4 Example: Student Test Scores

"Write a program that asks the user for the number of students in their class and then prompts the user to enter each student's test score within a range of 0–100. The program should then output the highest, lowest and average score to the user as well as saving the highest score to a file for future retrieval."

InputProcessOutputStorage
NumOfStudents: Integer
CurrentScore: Integer
TotalScore = TotalScore + CurrentScore
AverageScore = TotalScore / NumOfStudents
Store the list of scores in an array:
• Loop through and return the lowest score
• Loop through and return the highest score
LowScore: Integer
HighScore: Integer
AverageScore: Real/float
HighScore: Integer (saved to file)

3.5 Example: Shopping Total

Consider the problem of calculating and displaying the total price of items purchased by a customer in a store.

Inputs

  • Item prices (from a database or input by the cashier)
  • Quantities of items purchased (entered by the cashier or scanned from barcodes)

Processes

  • Calculate the total price for each item by multiplying its price by the quantity purchased
  • Sum up the individual item totals to compute the overall total price

Outputs

  • Display the total price to the customer (output on the cash register display)
  • Generate a receipt with itemised details and total price (physical or digital output)

Storage

  • Temporary storage of intermediate results (individual item totals) in variables during calculations
  • Optionally, store transaction details in a database for record-bookkeeping purposes

Interactive: Identify the Inputs, Processes, Outputs and Storage

Read each scenario below and click the button to check your understanding of the four components.

Click a scenario aboveto see its inputs, processes, outputs and storage.

Activity 3: IPO & Storage Analysis

A school library wants a program to keep track of which books are on loan. When a student borrows a book, the librarian scans the student's ID card and the book's barcode. The program checks the student has fewer than three books on loan, then records the loan. When a book is returned, the librarian scans it and the program records the return. At the end of each day, the program saves a list of all books still on loan to a file.

Complete the table:

InputProcessOutputStorage
????
Solution:
InputProcessOutputStorage
Student ID (from scanned card)
Book barcode (from scanned book)
Check the student has fewer than three books on loan
Record the loan
Record the return
Count books still on loan
Message to librarian confirming loan / return
(Optional) message refusing a fourth book
List of all books still on loan, saved to a file at the end of each day

Check Your Understanding: IPO & Storage

Answer
  • [2 marks]Inputs— the data or information provided to the system for processing; the raw materials needed to solve the problem
  • [2 marks]Processes— the operations or actions performed on the inputs to produce the desired outputs, including algorithms, calculations and transformations
  • [2 marks]Outputs— the results or outcomes produced by processing the inputs; they represent the solution to the problem
  • [2 marks]Storage— the temporary or permanent holding of data during the problem-solving process, such as intermediate results or historical records
Answer
  • [1 mark]Input:the radius of the circle (Real/float)
  • [1 mark]Process:Area = π × radius × radius
  • [1 mark]Output:the area of the circle (Real/float)
Answer
  • [1 mark]Output is data produced by the system to be shown to the user now (on screen, on paper)
  • [1 mark]Storage is data kept (temporarily or permanently) for later retrieval or for use as intermediate results during processing — it may never be shown directly to the user
Answer
  • [1 mark]The high score isstorage— it is written to a file so it can be retrieved in the future
  • [1 mark]However, the high score may also beoutputto the screen when it is displayed to the player. The act of saving it is storage; the act of showing it is output. The same data item can appear in both categories.
Answer
  • [1 mark]It helps the programmer understand exactly what data the program needs and where it comes from
  • [1 mark]It clarifies what processing is required and what the user should see as a result
  • [1 mark]It also identifies any data that must be saved for later, so the programmer can plan the file handling or database work
Answer
  • [1 mark]Proper storage management ensures that data is accessible, accurate and secure when needed (or: allows data to be retrieved in the future, such as a saved high score or transaction record)

4. Design Methods: Structure Diagrams (7.2c)

Usingstructure diagrams,flowchartsandpseudocodeare effective methods for designing and constructing solutions to problems.

4.1 Decomposition Recap

Decomposition means breaking a complex problem down into smaller, more manageable parts. Dealing with many different stages of a problem at once is much more difficult than breaking it down into a number of smaller problems and solving them one at a time.

Big problem
Main component 1
Main component 2
Sub-problem 1
Sub-problem 2
Sub-problem 3
Sub-problem 4

4.2 Step-Wise Refinement

We can use structure diagrams to help decompose a problem. We create structure diagrams using an approach known asstep-wise refinement.

How step-wise refinement works
  • At thetop level, we have the name of the program.
  • After some initial analysis, we break the program down into themain tasksit needs to perform (Level 1).
  • Some Level 1 modules may not need breaking down any further.
  • Some may still be quite complex and need breaking down further into Level 2, Level 3, Level 4, and so on.
  • Different sections of the program will be broken down to varying degrees depending on how complex they are.
  • The end result should always be the same: each node at thelowest level achieves one taskand can be coded as a single module or sub-program.

Worked Example: Company Wage Program

Top level:Company wage program.

After initial analysis, we break the program down into the main tasks:

Input employee details
Calculate pay
Produce pay slips

Calculate paycould be broken down again into: Gross pay and Total deductions.

Carry this process on, breaking down any stage that is still too complex into smaller, more manageable chunks.Calculate deductionscould be broken down into:

  • Income tax
  • National Insurance
  • Non-paid sick days
  • Pension contributions

Interactive: Company Wage Program Structure Diagram

Click each level button to reveal the next stage of the step-wise refinement.

Level 0:The top level is the name of the program — "Company wage program".

4.3 Structure Diagrams Summary

What is a structure diagram?

  • A method of designing a solution to a problem
  • Produced using a method known as step-wise refinement
  • Breaks a problem down into smaller sub-problems using decomposition
  • Some areas of the program will need to be broken down more than others
  • Lowest-level nodes should achieve one task — and therefore be coded as a single module or sub-program

Structure diagram for Space Invaders

The PDF shows the structure diagram for the classic shooter. The top level is "Arcade shooter", broken down into:

  • Title screen → Settings
  • Game → Swarm, Player ship, Player missile, Enemy missiles, UFO
  • End game → Game over

Each of these modules is then broken down further until each node performs a single task (e.g. Move player, Fire missile, Check win/lose).

Activity 4: Build a Structure Diagram

A program is being written to manage a school's lunch ordering system. Students can choose a meal, pay for it using their lunch card, and receive a receipt. The system also needs to update the student's balance and save the transaction.

  1. Draw (or describe) a structure diagram for this program using step-wise refinement. Break it down to at least three levels.
  2. Which nodes would be at the lowest level, and what makes them suitable for coding as single modules?
  3. Why might the "Payment" branch need more levels than the "Receipt" branch?
Solution:
  1. Structure diagram (described):
    Lunch Ordering System (Top level)
      ├── Choose Meal (Level 1)
      │   ├── Display Menu (Level 2)
      │   └── Record Selection (Level 2)
      ├── Payment (Level 1)
      │   ├── Read Lunch Card (Level 2)
      │   ├── Check Balance (Level 2)
      │   │   └── Confirm Sufficient Funds (Level 3)
      │   ├── Deduct Cost (Level 2)
      │   └── Update Balance (Level 2)
      ├── Receipt (Level 1)
      │   └── Print Receipt (Level 2)
      └── Save Transaction (Level 1)
          └── Write to File (Level 2)
  2. Lowest-level nodes:"Confirm Sufficient Funds", "Deduct Cost", "Update Balance", "Print Receipt" and "Write to File" are all lowest-level nodes. Each one performs a single task, so each can be coded as a single module or sub-program.
  3. Why Payment needs more levels:The payment branch is more complex. It must read the card, check there is enough money, work out the new balance, and update the stored balance. Each of these steps may need further refinement. The receipt branch, by contrast, is simple — it just prints a receipt — so it needs fewer levels.

Check Your Understanding: Structure Diagrams

Answer
  • [1 mark]A structure diagram is a method of designing a solution to a problem
  • [1 mark]It is produced using a method known as step-wise refinement
  • [1 mark]It breaks a problem down into smaller sub-problems using decomposition
Answer
  • [1 mark]Carrying the process of breaking a problem down into smaller, more manageable chunks, level by level
  • [1 mark]At each step, any stage that is still too complex is broken down again, until the lowest-level nodes each achieve one task and can be coded as a single module
Answer
  • [1 mark]Calculate income tax
  • [1 mark]Calculate National Insurance
  • [1 mark]Calculate non-paid sick days
  • [1 mark]Calculate pension contributions
Answer
  • [1 mark]Because some sections of the program are more complex than others and need more decomposition to reach a set of single-task modules
  • [1 mark]Simpler sections may only need one or two levels, while a complex calculation may need three or four levels before each node performs a single task
Answer
  • [1 mark]It should achieve one task only
  • [1 mark]This means it can be coded as a single module or sub-program
Answer
  • [1 mark]It gives a clear visual overview of the whole program and how the parts fit together
  • [1 mark]It identifies individual modules that can be coded, tested and even assigned to different team members independently

5. Design Methods: Flowcharts and Pseudocode (7.2c)

In the exam you need to be able tocreate, interpret, correct and refine algorithmsusingpseudocodeandflowcharts.

5.1 Flowcharts

Aflowchartis a method of representing the sequences of steps in an algorithm in the form of a diagram.

Standard Flowchart Symbols

Terminal
Terminal
Start or Stop (oval / rounded rectangle)
Process
Process
A process or action (rectangle)
Decision
Decision
A Yes/No question (diamond)
Input / Output
Input / Output
Input or output (parallelogram)
Subroutine
Subroutine
A call to a sub-program (rectangle with double side lines)
Line
Shows the direction of flow (arrow)

Example Flowchart: Largest of Two Numbers

StartInput number1 from the keyboardInput number2 from the keyboardIs number1greater thannumber2?YESNOOutput "The largestnumber is…" number1Output "The largestnumber is…" number2Stop

Reading the flowchart:Theovalshows the start. Theparallelogramsare input boxes. Thediamondis a decision — the flow leaves by the YES side or the NO side. Therectangles with slanted sides(output) show messages. Arrows show the direction of flow.

5.2 Pseudocode

Pseudocodeis an alternative,text-basedway of representing the sequence of steps in an algorithm. The prefixpseudomeansfalseornot genuine. Pseudocode can be thought of as asimplified form of programming code. It allows us to lay down the logic of a problem in an almost-like-real-code way without worrying about the actual rules and syntax of a particular language.

Same Algorithm in CIE Pseudocode

//Program to output the largest of the two numbers
DECLARE number1 : INTEGER
DECLARE number2 : INTEGER
INPUT number1
INPUT number2
IF number1 > number2 THEN
OUTPUT "The largest number is ", number1
ELSE
OUTPUT "The largest number is ", number2
ENDIF
Cambridge IGCSE Pseudocode

The pseudocode in these lessons follows the exact style which will be used in your exams. The full set of pseudocode is defined in the syllabus forCambridge IGCSE (9–1) Computer Science 0984andCambridge IGCSE (A*–G) Computer Science 0478.

5.3 Key CIE Pseudocode Conventions

ConceptCIE PseudocodeExample
Declaring a variableDECLARE name : typeDECLARE Score : INTEGER
InputINPUTINPUT Score
OutputOUTPUTOUTPUT "Hello ", Name
AssignmentTotal ← Total + Score
SelectionIF … THEN … ELSE … ENDIFIF Score >= 50 THEN
Iteration (count-controlled)FOR … TO … NEXTFOR Count ← 1 TO 60
Iteration (condition-controlled)WHILE … DO … ENDWHILE / REPEAT … UNTILWHILE Score < 0 OR Score > 100 DO

Activity 5: From Flowchart to Pseudocode

A flowchart shows an algorithm that allows 60 test results to be entered. Each test result is checked to see if it is 50 or more. If it is, the test result is assigned to the Pass array. Otherwise, it is assigned to the Fail array.

  1. Write the CIE pseudocode for this algorithm.
  2. Write a pseudocode routine that checks each test result is between 0 and 100 inclusive.
Solution:
  1. CIE pseudocode:
    DECLARE PassCount : INTEGER
    DECLARE FailCount : INTEGER
    DECLARE Count : INTEGER
    DECLARE Score : INTEGER
    DECLARE Pass : ARRAY [1:60] OF INTEGER
    DECLARE Fail : ARRAY [1:60] OF INTEGER
    PassCount ← 0
    FailCount ← 0
    FOR Count ← 1 TO 60
    INPUT Score
    IF Score >= 50 THEN
    Pass[PassCount] ← Score
    PassCount ← PassCount + 1
    ELSE
    Fail[FailCount] ← Score
    FailCount ← FailCount + 1
    ENDIF
    NEXT Count
  2. Validation routine (0–100 inclusive):

    Using WHILE … DO … ENDWHILE:

    WHILE Score < 0 OR Score > 100 DO
    OUTPUT "Your entry must be between 0 and 100, inclusive, please try again "
    INPUT Score
    ENDWHILE

    Or using REPEAT … UNTIL:

    REPEAT
    IF Score < 0 OR Score > 100 THEN
    OUTPUT "Your entry must be between 0 and 100, inclusive, please try again "
    INPUT Score
    ENDIF
    UNTIL Score >= 0 AND Score <= 100

Check Your Understanding: Flowcharts & Pseudocode

Answer
  • [1 mark]A flowchart represents the steps of an algorithm as a diagram using standard symbols
  • [1 mark]Pseudocode represents the steps as text using a simplified form of programming code
  • [1 mark]Both can be used to create, interpret, correct and refine algorithms; pseudocode does not worry about the rules and syntax of a particular language
Answer
  • [1 mark]A diamond shape is used for a decision
  • [1 mark]Because a decision has two possible outcomes (typically Yes/No or True/False), and the diamond allows two exit arrows to be drawn from its left and right points
Answer
DECLARE number1 : INTEGER
DECLARE number2 : INTEGER
INPUT number1
INPUT number2
IF number1 > number2 THEN
OUTPUT "The largest number is ", number1
ELSE
OUTPUT "The largest number is ", number2
ENDIF

Marking:DECLARE with data types (2), INPUT and OUTPUT (1), correct IF … THEN … ELSE … ENDIF structure (1), correct comparison and assignment (1).

Answer
  • [1 mark]The YES path is followed if Score is 50 or more, and leads to the instructions for assigning the score to the Pass array
  • [1 mark]The NO path is followed if Score is less than 50, and leads to the instructions for assigning the score to the Fail array
Answer
DECLARE Total : INTEGER
DECLARE Counter : INTEGER
DECLARE Number : INTEGER
Total ← 0
FOR Counter ← 1 TO 100
INPUT Number
Total ← Total + Number
NEXT Counter
OUTPUT "The total is ", Total

Marking:Correct FOR … TO … NEXT loop (2), total accumulation (2), output (1).

Answer
  • [1 mark]It allows the logic of a problem to be laid out in an almost-like-real-code way without worrying about the actual rules and syntax of a particular language
  • [1 mark]This makes the algorithm easier to check, correct and refine before real code is written, and it can be translated into any programming language afterwards

6. Past Paper Practice (7.2c)

Question 1 — Ages of 100 Students

An algorithm has been written to:

  • Input the ages of 100 students
  • Count and output the number of students aged 7 and under 12
  • Count and output the number of students aged 12 and under 18
  • Count and output the number of students aged 18 and over

Complete the pseudocode algorithm:

01 Count7to12 ← 0
02 Count12to18 ← 0
03 CountOver18 ← 0
04 FOR Student ← 1 TO ................
05 OUTPUT "Please enter student's age in years "
06 INPUT Age
07 IF Age >= 7 ................ THEN
08 Count7to12 ← Count7to12 + 1
09 ENDIF
10 IF Age >= 12 AND Age < 18
11 THEN
12 Count12to18 ← ................
13 ENDIF
14 IF Age >= 18
15 THEN
16 CountOver18 ← CountOver18 + 1
17 ENDIF
18 NEXT Student
19 OUTPUT "There are ", Count7to12, " students aged 7 and under 12."
20 OUTPUT "There are ", Count12to18, " students aged 12 and under 18."
21 OUTPUT "There are ", ................, " students aged 18 and over."

Show Mark Scheme

Mark Scheme (max 4):
  • [1 mark]Line 04:100
  • [1 mark]Line 07:AND Age < 12
  • [1 mark]Line 12:Count12to18 + 1
  • [1 mark]Line 21:CountOver18

Question 2 — Under 7s Extension

The algorithm is extended to also count and output the number of students aged under 7.

  1. Write an IF construct to count the students aged under 7.
  2. Write an OUTPUT statement that uses the counter variable to display the number of students aged under 7.

Show Mark Scheme

Mark Scheme (max 4):

(a)

IF Age < 7 THEN
CountUnder7 ← CountUnder7 + 1
ENDIF
  • [1 mark]Suitable IF construct
  • [1 mark]Correct assignment statement

(b)

OUTPUT "There are ", CountUnder7, " students aged under 7."
  • [1 mark]Suitable message
  • [1 mark]Correct use of the counter variable

Question 3 — Totalling 100 Numbers

The flowchart shows an algorithm that should:

  • Allow 100 numbers to be entered into the variable Number
  • Total the numbers as they are entered
  • Output the total and average of the numbers after they have all been entered

Show Mark Scheme

CIE Pseudocode Version:
DECLARE Total : INTEGER
DECLARE Counter : INTEGER
DECLARE Number : INTEGER
DECLARE Average : REAL
Total ← 0
FOR Counter ← 1 TO 100
INPUT Number
Total ← Total + Number
NEXT Counter
Average ← Total / 100
OUTPUT "Total: ", Total
OUTPUT "Average: ", Average
Mark Scheme (max 6):
  • MP1Input box
  • MP2Correct totalling using Total
  • MP3Correct counting using Counter
  • MP4Correct conditional statement for Counter (Is Counter = 100?)
  • MP5Correct calculation of Average
  • MP6Correct outputs of Total and Average

Key Takeaways

  • Every computer system is made up ofsub-systems, which are made up offurther sub-systems, forming a hierarchical structure.
  • Asub-systemis a smaller part of a computer system that works together with other sub-systems to create a fully functional system.
  • The five main computer sub-systems are:CPU, Memory, Storage, Input Devices and Output Devices.
  • The CPU can be broken down into theControl Unit, registers and ALU; memory intocache and main memory; storage into thefile system and disk controller.
  • Sub-systems helptroubleshoot problems, support efficientsoftware development, and give designers a clear picture of how a complex system is built.
  • Decompositionmeans breaking a complex problem into smaller, more manageable parts that can be solved, tested and combined independently.
  • Decomposing a problem requires identifying itsinputs, processes, outputs and storage.
  • Inputsare the raw materials (data);processesare the operations on the data;outputsare the results;storageis data held temporarily or permanently for later use.
  • Structure diagramsare produced usingstep-wise refinement, breaking each still-complex stage into smaller chunks until every lowest-level node performs a single task.
  • Flowchartsrepresent algorithms as diagrams using standard symbols: terminal (oval), process (rectangle), decision (diamond), input/output (parallelogram) and subroutine.
  • Pseudocodeis a text-based, simplified form of program code that lays out an algorithm's logic without worrying about a specific language's syntax.
  • CIE pseudocode usesDECLARE,INPUT,OUTPUT, theassignment arrow,IF … THEN … ELSE … ENDIF,FOR … TO … NEXTandWHILE … DO … ENDWHILE.
  • In the exam you must be able tocreate, interpret, correct and refinealgorithms using both flowcharts and pseudocode.

Question Bank

Answer
  • [1 mark]A sub-system is a smaller part of a computer system
  • [1 mark]That works together with other sub-systems to create a fully functional computer system
  • [1 mark]Computer example: CPU / memory / storage / input devices / output devices
  • [1 mark]Car example: engine / brakes / wheels
Answer
  • [1 mark]Control Unit
  • [1 mark]Registers
  • [1 mark]Arithmetic Logic Unit (ALU)
  • [1 mark]Function of the CPU: executes instructions
Answer
  • [2 marks]Sub-systems help troubleshoot problems: the ability to isolate a sub-system makes it easier to identify and fix issues, as each sub-system can be examined separately
  • [2 marks]Sub-systems give developers and designers a clear picture of how sub-systems help build complex systems, and software development relies on different sub-systems to operate efficiently
Answer
  • [1 mark]Decomposition is breaking a complex problem down into smaller, more manageable parts
  • [1 mark]Smaller problems are easier to solve
  • [1 mark]Each smaller problem can be solved and tested independently
  • [1 mark]Smaller problems can be combined to produce a solution to the full problem / different people can work on different parts at the same time
Answer
ComponentDetailsMarks
InputsLength: Real/float
Height: Real/float
Depth: Real/float
[2]
ProcessesLength × Height × Depth[2]
OutputsVolume: Real/float[2]
StorageVolume: Real/float — written to a text file[2]
Answer
  • [1 mark]Step-wise refinement means carrying the process of breaking the problem down into smaller, more manageable chunks, level by level
  • [1 mark]At each step, any stage that is still too complex is broken down again
  • [1 mark]The lowest-level nodes should each achieve one task only
  • [1 mark]This means each lowest-level node can be coded as a single module or sub-program
Answer
IF Score >= 50 THEN
Pass[PassCount] ← Score
PassCount ← PassCount + 1
ELSE
Fail[FailCount] ← Score
FailCount ← FailCount + 1
ENDIF

Marking:Correct IF … THEN … ELSE … ENDIF structure (2), correct assignment to Pass array (1), correct assignment to Fail array (1), correct incrementing of counters (1).

Answer

Using WHILE:

WHILE Score < 0 OR Score > 100 DO
OUTPUT "Your entry must be between 0 and 100, inclusive, please try again "
INPUT Score
ENDWHILE

Using REPEAT…UNTIL:

REPEAT
IF Score < 0 OR Score > 100 THEN
OUTPUT "Your entry must be between 0 and 100, inclusive, please try again "
INPUT Score
ENDIF
UNTIL Score >= 0 AND Score <= 100

Marking:Appropriate conditional loop structure (1), correct identification of invalid input (1), appropriate error message (1), repeated input of score until correct (1).