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-system | Function | Examples of further sub-systems |
|---|---|---|
| Central Processing Unit (CPU) | Executes instructions | Control unit, registers, Arithmetic Logic Unit (ALU) |
| Memory (RAM) | Stores data & instructions temporarily for the CPU | Cache memory, main memory |
| Storage | Stores data and software permanently | HDD, SSD, file system, disk controller |
| Input devices | Allows a user to enter information | Keyboard, mouse, keyboard controller, mouse interface |
| Output devices | Displays information or creates a physical output | Monitor, 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.
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.
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.
- 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).
- The CPU of the tablet can be broken down into three further sub-systems. Name them.
- Explain how the idea of sub-systems helps a technician who is repairing a broken tablet.
Solution:
- 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).
- CPU sub-systems:Control Unit, registers, Arithmetic Logic Unit (ALU).
- 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
1. Define the term "sub-system". [2 marks]
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
2. Name the five main sub-systems of a computer and give the function of each. [10 marks]
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)
3. Give one example of a sub-system of the CPU and one example of a sub-system of storage. [2 marks]
Answer
- [1 mark]CPU sub-system: Arithmetic Logic Unit (ALU) / Control Unit / registers
- [1 mark]Storage sub-system: File system / disk controller
4. Explain how the use of sub-systems helps when troubleshooting a broken computer system. [3 marks]
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
5. A computer's memory (RAM) can be broken down into further sub-systems. Give two examples. [2 marks]
Answer
- [1 mark]Cache memory
- [1 mark]Main memory
6. Why is the concept of sub-systems important when designing a new computer system? [2 marks]
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:
- Stop before crossing.
- Look left and right.
- Is the road clear?
- If not, press the button.
- Wait for the lights to turn red.
- 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.
Activity 2: Decompose a School Event
Your school is organising a charity fun run. The "big problem" is to run the event successfully.
- Decompose this problem into at least three main components.
- Decompose one of those main components into at least three sub-problems.
- Explain how one of these sub-problems could be tested independently before the event.
Solution:
- Main components (example):
- Organising the route
- Managing participants (registration, numbers, safety)
- Fundraising and sponsorship
- Health, safety and first aid
- 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
- 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
1. Define "decomposition" and explain why it is useful. [3 marks]
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
2. Give three benefits of decomposition. [3 marks]
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
3. In the Breakout clone example, list five sub-problems the game can be broken into. [5 marks]
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
4. Explain how decomposition helps a team of programmers working on a large game. [3 marks]
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
5. Decompose the task of "making breakfast" into at least four sub-problems. [4 marks]
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
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
| Component | Details |
|---|---|
| Inputs | Width of the rectangle Height of the rectangle |
| Processes | Width × height |
| Outputs | Calculated area of the rectangle |
| Storage | Memory: 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."
| Input | Process | Output | Storage |
|---|---|---|---|
| Length: Real/float Height: Real/float Depth: Real/float | Length × Height × Depth | Volume: 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."
| Input | Process | Output | Storage |
|---|---|---|---|
| Length: Real/float Height: Real/float Depth: Real/float | Length × Height × Depth | Volume: Real/float | Volume: 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."
| Input | Process | Output | Storage |
|---|---|---|---|
| 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:
| Input | Process | Output | Storage |
|---|---|---|---|
| ? | ? | ? | ? |
Solution:
| Input | Process | Output | Storage |
|---|---|---|---|
| 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
1. Define the terms "input", "process", "output" and "storage". [8 marks]
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
2. A program asks for the radius of a circle and outputs its area. Identify the inputs, processes and outputs. [3 marks]
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)
3. Explain why storage is considered separately from output. [2 marks]
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
4. A program saves a player's high score so it can be shown the next time the game is played. Is the high score an output or storage? Explain. [2 marks]
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.
5. Why is it useful for a programmer to identify the IPO & S of a problem before writing code? [3 marks]
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
6. Give one advantage of properly managing storage in a program. [1 mark]
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.
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.
- Draw (or describe) a structure diagram for this program using step-wise refinement. Break it down to at least three levels.
- Which nodes would be at the lowest level, and what makes them suitable for coding as single modules?
- Why might the "Payment" branch need more levels than the "Receipt" branch?
Solution:
- 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)
- 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.
- 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
1. What is a structure diagram and how is it produced? [3 marks]
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
2. What is meant by step-wise refinement? [2 marks]
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
3. In the Company Wage Program, "Calculate deductions" is broken down into four sub-modules. Name them. [4 marks]
Answer
- [1 mark]Calculate income tax
- [1 mark]Calculate National Insurance
- [1 mark]Calculate non-paid sick days
- [1 mark]Calculate pension contributions
4. Why do different sections of a program get broken down to different numbers of levels? [2 marks]
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
5. What property must every lowest-level node in a structure diagram have? [2 marks]
Answer
- [1 mark]It should achieve one task only
- [1 mark]This means it can be coded as a single module or sub-program
6. Give two advantages of using a structure diagram when designing a program. [2 marks]
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
Example Flowchart: Largest of Two Numbers
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
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
| Concept | CIE Pseudocode | Example |
|---|---|---|
| Declaring a variable | DECLARE name : type | DECLARE Score : INTEGER |
| Input | INPUT | INPUT Score |
| Output | OUTPUT | OUTPUT "Hello ", Name |
| Assignment | ← | Total ← Total + Score |
| Selection | IF … THEN … ELSE … ENDIF | IF Score >= 50 THEN |
| Iteration (count-controlled) | FOR … TO … NEXT | FOR Count ← 1 TO 60 |
| Iteration (condition-controlled) | WHILE … DO … ENDWHILE / REPEAT … UNTIL | WHILE 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.
- Write the CIE pseudocode for this algorithm.
- Write a pseudocode routine that checks each test result is between 0 and 100 inclusive.
Solution:
- CIE pseudocode:DECLARE PassCount : INTEGERDECLARE FailCount : INTEGERDECLARE Count : INTEGERDECLARE Score : INTEGERDECLARE Pass : ARRAY [1:60] OF INTEGERDECLARE Fail : ARRAY [1:60] OF INTEGERPassCount ← 0FailCount ← 0FOR Count ← 1 TO 60INPUT ScoreIF Score >= 50 THENPass[PassCount] ← ScorePassCount ← PassCount + 1ELSEFail[FailCount] ← ScoreFailCount ← FailCount + 1ENDIFNEXT Count
- Validation routine (0–100 inclusive):
Using WHILE … DO … ENDWHILE:
WHILE Score < 0 OR Score > 100 DOOUTPUT "Your entry must be between 0 and 100, inclusive, please try again "INPUT ScoreENDWHILEOr using REPEAT … UNTIL:
REPEATIF Score < 0 OR Score > 100 THENOUTPUT "Your entry must be between 0 and 100, inclusive, please try again "INPUT ScoreENDIFUNTIL Score >= 0 AND Score <= 100
Check Your Understanding: Flowcharts & Pseudocode
1. What is the difference between a flowchart and pseudocode? [3 marks]
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
2. Which flowchart symbol is used for a decision, and why is it shaped that way? [2 marks]
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
3. Write CIE pseudocode that declares two INTEGER variables, inputs them, and outputs the larger of the two. [5 marks]
Answer
Marking:DECLARE with data types (2), INPUT and OUTPUT (1), correct IF … THEN … ELSE … ENDIF structure (1), correct comparison and assignment (1).
4. A flowchart has a decision "Is Score >= 50?". Describe the two paths that leave this decision. [2 marks]
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
5. Write CIE pseudocode for a loop that inputs 100 numbers, totals them, and outputs the total. [5 marks]
Answer
Marking:Correct FOR … TO … NEXT loop (2), total accumulation (2), output (1).
6. Explain why pseudocode is a useful design tool, even though it is not real code. [2 marks]
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:
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.
- Write an IF construct to count the students aged under 7.
- 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)
- [1 mark]Suitable IF construct
- [1 mark]Correct assignment statement
(b)
- [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:
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, the←assignment 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
1. A computer system can be broken down into sub-systems. Explain what is meant by a sub-system and give one example from a computer and one example from a car. [4 marks]
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
2. The CPU can be broken down into further sub-systems. Name three of them and state one function of the CPU. [4 marks]
Answer
- [1 mark]Control Unit
- [1 mark]Registers
- [1 mark]Arithmetic Logic Unit (ALU)
- [1 mark]Function of the CPU: executes instructions
3. Explain two advantages of using sub-systems when designing or maintaining a computer system. [4 marks]
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
4. Explain what is meant by decomposition and state three benefits of decomposing a problem. [4 marks]
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
5. A program is being written to calculate the volume of a fish tank and save the result to a file. Identify the inputs, processes, outputs and storage. [8 marks]
Answer
| Component | Details | Marks |
|---|---|---|
| Inputs | Length: Real/float Height: Real/float Depth: Real/float | [2] |
| Processes | Length × Height × Depth | [2] |
| Outputs | Volume: Real/float | [2] |
| Storage | Volume: Real/float — written to a text file | [2] |
6. A structure diagram is produced using step-wise refinement. Explain what is meant by step-wise refinement and describe what the lowest-level nodes of a structure diagram should represent. [4 marks]
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
7. A flowchart contains a decision "Is Score >= 50?" with a YES path and a NO path. Write CIE pseudocode for this decision and its two outcomes. [5 marks]
Answer
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).
8. A program must check that each test score entered is between 0 and 100 inclusive. Write a CIE pseudocode routine to do this. [4 marks]
Answer
Using WHILE:
Using REPEAT…UNTIL:
Marking:Appropriate conditional loop structure (1), correct identification of invalid input (1), appropriate error message (1), repeated input of score until correct (1).