Learn Like a GEM
Unit 7 & 8. Algorithms
Topic : Revision
Date: June 7, 2026
Do Now Unit 7 & 8 Topics Overview
In this unit you will learn about:
★Unit 7: Problem Solving & Algorithm Design
- Program development life cycle (Analysis, Design, Coding, Testing)
- Abstraction, decomposition and structure diagrams
- Flowcharts and pseudocode
- Linear search algorithm
★Unit 8: Programming Concepts
- Variables, constants, data types, assignments
- Input/Output, arithmetic & logical operators
- Sequence, selection (IF/CASE), iteration (FOR, WHILE, REPEAT)
- Arrays, maintainable programs
I Do
PROGRAM DEVELOPMENT LIFE CYCLE
There are four main stages in the program development life cycle:
1. Analysis
Identify the problem and requirements. Use abstraction and decomposition. Define what inputs, processes, outputs and storage are
needed.
2. Design
Plan the solution using decomposition, structure diagrams, flowcharts and pseudocode. Break the problem into manageable sub-
problems.
3. Coding
Write the program code based on the design. Use iterative testing — test each section as it is written rather than waiting until the entire
program is complete.
4. Testing
Test the complete program with carefully chosen test data including normal, boundary and erroneous data to ensure it works correctly
for all cases.
Abstraction
Abstraction involves identifying the key parts of a problem and removing any unnecessary detail so that it becomes easier to solve.
For example: if a program simulates a card game, the task "shuffle cards" is an abstraction — we refer to it throughout the program
without specifying how it will be done (randomising 52 values).
Decomposition
Breaking down a complex problem into smaller, manageable parts which are easier to solve:
✓ Identify the main problem
✓ Identify the component parts: inputs, processes, outputs and storage
✓ List main sub-problems, sub-systems, functions or tasks
✓ Break these down into smaller sub-problems that can be completed separately
You Do Everybody writes
(a) State the FOUR stages of the program development life cycle. [4]
1. _______________ 2. _______________ 3. _______________ 4. _______________
(b) A self-driving car is being developed. The software must distinguish between an animal and a person
crossing the road.
(i) Define what is meant by abstraction. [2]
_____________________________________________________________
_____________________________________________________________
(ii) Give ONE example of how abstraction could be used in developing this software. [1]
_____________________________________________________________
You Do Marking Scheme
(a) Four stages: [1 mark each]
✓ 1. Analysis 2. Design 3. Coding 4. Testing
(b)(i) Define abstraction: [2 marks]
✓ Removing / hiding details of a problem that are not relevant to a solution
✓ Identifying the key parts of the problem so that it becomes easier to solve
(b)(ii) Example of abstraction for self-driving car: [1 mark — any one]
✓ Size/height of the person or animal can be removed/ignored
✓ Number of legs visible
✓ Speed at which the person/animal is moving
✓ Whether it is on a pedestrian crossing
✓ Colour of clothing
I Do
STRUCTURE DIAGRAMS
Identifying inputs, processing, outputs and storage is the first stage in the decomposition of a problem. Each
stage may then be broken down further.
What is a Structure Diagram?
A structure diagram shows the structure of a problem, its sub-sections and links to other sub-sections. It is used to
represent decomposition visually as a hierarchy.
Stages in Decomposition
✓ Identify the main problem (top of diagram)
✓ Identify the component parts: inputs, processes, outputs and storage
✓ List the main sub-problems, sub-systems, functions or tasks (second level)
✓ Break these down further into smaller sub-problems or sub-tasks (lower levels)
Example: Card Game Structure Diagram
Top level: Card Game
Second level: Shuffle Cards | Deal Cards | Play Game
Third level (under Play Game): Player Plays a Card | Score Updated
Pseudocode and Structure Diagrams
Each box in a structure diagram can be turned into a procedure or function in the final program. This supports
decomposition into subprograms, making the program easier to test, maintain and reuse.
You Do Everybody writes
A school is developing software to manage a library system. Books can be borrowed, returned and searched.
Members can register and their borrowing history is stored.
(a) Draw a structure diagram to show the decomposition of the library system. Your diagram should have
at least THREE levels. [5]
Draw your structure diagram in the space below:
(b) State ONE benefit of using a structure diagram in the design stage. [1]
_____________________________________________________________
You Do Marking Scheme
(a) Structure diagram for Library System: [5 marks]
✓ [1 mark] Top level: Library System (1 box at top)
✓ [1 mark] Second level — at least 3 subsystems, e.g.: Borrow Books | Return Books | Search Books | Manage
Members
✓ [1 mark] Third level under Borrow Books — e.g.: Check Availability | Record Borrowing | Update Member Record
✓ [1 mark] Third level under Manage Members — e.g.: Register Member | View Borrowing History | Update Details
✓ [1 mark] All boxes at the same level connected correctly to their parent
Example Structure Diagram:
Library System
┌──────────┬──────────┬──────────┐
Borrow Return Search Manage
Books Books Books Members
┌──┬──┐ ┌──┬──┐ ┌──┬──┐
Check Record Title Author Reg History
(b) ONE benefit of structure diagram: [1 mark]
✓ Shows clearly how the problem is broken down / shows the hierarchy of sub-tasks
✓ Helps plan which modules/subprograms need to be written
✓ Makes it easy to see all sub-problems and their relationships at a glance
I Do
FLOWCHARTS & PSEUDOCODE
Flowchart Symbols
Flow line (arrow): Shows direction of flow between steps
Parallelogram (Input/Output): Used for INPUT and OUTPUT operations
Rectangle (Process): Any calculation or assignment operation
Diamond (Decision): A YES/NO question — creates branches in the flow
Rectangle with double sides (Subroutine): Calls a named subroutine/procedure
Rounded rectangle (Terminator): START or STOP of the algorithm
Pseudocode
Pseudocode is useful for developing an algorithm using programming-style constructs, but it is NOT an actual
programming language. The programmer concentrates on solving the problem without worrying about the exact
syntax of a language.
IGCSE Standard Pseudocode Rules
✓ Comments start with // and continue to the end of the line
✓ Identifiers contain only letters and digits 0-9, starting with an uppercase letter
✓ Assignment operator is ← (e.g. Count ← Count + 1)
✓ Strings delimited by double quotes; characters by single quotes
✓ DECLARE StartNumber : INTEGER / DECLARE Total : REAL
✓ CONSTANT VAT ← 0.2
You Do Everybody writes
A flowchart shows an algorithm that inputs StartNumber, EndNumber and Step, assigns Number ← StartNumber, then
outputs numbers while Number <= EndNumber, incrementing by Step each time.
(a) What will be output if the user enters 7, 50, 10 for the three input values? [2]
_____________________________________________________________
(b) What will be output if the user enters an end number which is less than the start number? [1]
_____________________________________________________________
(c) Write pseudocode to ask the user to enter their first name and last name, then output the last name followed by
the first name on one line. [4]
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
You Do Marking Scheme
(a) Output when inputs are 7, 50, 10: [2 marks]
✓ 7, 17, 27, 37, 47 [1 mark each for correct sequence and stopping correctly]
(b) End number less than start number: [1 mark]
✓ Nothing will be output (the condition Number <= EndNumber is immediately FALSE)
(c) Pseudocode for first/last name: [4 marks]
OUTPUT "Enter your first name"
INPUT FirstName
OUTPUT "Enter your last name"
INPUT LastName
OUTPUT LastName, FirstName
Award: 1 mark OUTPUT prompt, 1 mark INPUT FirstName, 1 mark INPUT LastName, 1 mark OUTPUT
LastName, FirstName
I Do
LINEAR SEARCH
Using a linear search, each item is checked one by one in the list until the item is found, or the whole list has been searched
without success.
How Linear Search Works
✓ Start at the first element (index 1)
✓ Compare the current element with the search item
✓ If they match: item is found — record position and stop
✓ If they do not match: move to the next element
✓ If the end of the list is reached without a match: item is not found
Linear Search Algorithm (Pseudocode)
//Perform a linear search of an array
DECLARE AList : ARRAY[1:10] OF INTEGER
AList ← [14, 2, 3, 11, 1, 9, 5, 8, 10, 6]
Found ← FALSE
Index ← 1
INPUT SearchItem
WHILE Found = FALSE AND Index <= LENGTH(AList) DO
IF AList[Index] = SearchItem
THEN
Found ← TRUE
ELSE
Index ← Index + 1
ENDIF
ENDWHILE
IF Found = TRUE
THEN OUTPUT SearchItem, "in position", Index
ELSE OUTPUT "Item not found"
ENDIF
You Do Everybody writes
A list of 10 names is shown below:
Harry | Jo | Anne | Zoe | Peter | Ken | Steve | Geri | Fiona | Bob
(a) State which items are examined when looking for Zoe using a linear search. [1]
_____________________________________________________________
(b) State how many items will be examined when looking for Dave using a linear search. [1]
_____________________________________________________________
The algorithm below is used to search for a value in an array.
AList ← [14, 2, 3, 11, 1, 9, 5, 8, 10, 6]
X ← AList[1]
FOR i ← 2 TO LENGTH(AList)
IF AList[i] < X
THEN X ← AList[i]
ENDIF
NEXT i
OUTPUT X
(c) State the purpose of the algorithm above. [1]
_____________________________________________________________
(d) State TWO ways of making the algorithm easier to understand. [2]
1. ________________________________ 2. ________________________________
You Do Marking Scheme
(a) Items examined for Zoe: [1 mark]
✓ Harry, Jo, Anne, Zoe (search stops at position 4 when Zoe is found)
(b) Items examined for Dave: [1 mark]
✓ 10 items (Dave is not in the list — the entire list must be searched)
(c) Purpose of algorithm: [1 mark]
✓ To find and output the minimum (smallest) integer in the array
(d) TWO ways to make algorithm easier to understand: [1 each]
✓ Add a comment explaining the purpose e.g. // Find the minimum value in the array
✓ Replace X with a more meaningful variable name e.g. MinValue
I Do
VARIABLES, CONSTANTS & DATA TYPES
Variables
A variable is a data item held in memory which may change value during program execution. It is referred to by its identifier
(variable name). Variable names (identifiers) can be a mixture of letters and numbers but must start with a letter.
Constants
A constant cannot change during program execution. Declared in pseudocode as:
CONSTANT VAT ← 0.2
Pascal Case / Naming Conventions
Pascal case separates words in a variable name using uppercase letters, e.g. TotalCost, StudentName, HighScore. Using a
consistent naming convention helps reduce errors and aids other programmers.
Data Types
INTEGER: A whole number — e.g. 5, -267, 153489
REAL: A number with a decimal point — e.g. 3.142, 56.0, -0.75
CHAR: A single character in single quotes — e.g. 'A', '#', '6'
STRING: Zero or more characters in double quotes — e.g. "Yes", "Hi", "John"
BOOLEAN: The logical values TRUE or FALSE
Assignments
A variable is assigned a value using the ← sign:
CostPrice ← 15.65
Count ← Count + 3
Under12 ← True
StudentName ← "Higgins, P"
Response ← 'Y'
You Do Everybody writes
(a) A game is being programmed.
(i) Choose a meaningful variable name for the highest score in the game.
_____________________________________________________________
(ii) Write pseudocode to set the highest score to 25.
_____________________________________________________________
(b) State the data type for each of the following: [3]
152 → ________________ 3.14 → ________________ TRUE → ________________
(c) Evaluate the following Boolean expressions (TRUE or FALSE): [3]
(i) (2 + 5 * 3) > (2 + 5) * 3 → ________
(ii) 25 DIV 4 >= 25/4 → ________
(iii) "Fred" <> "fred" → ________
You Do Marking Scheme
(a) Variable name and assignment:
✓ (i) Any meaningful name e.g. HighScore, MaxScore, TopScore [1 mark]
✓ (ii) HighScore ← 25 (using correct assignment operator) [1 mark]
(b) Data types: [1 mark each]
✓ 152 → INTEGER
✓ 3.14 → REAL
✓ TRUE → BOOLEAN
(c) Boolean expressions: [1 mark each]
✓ (i) (2 + 15) > (7) * 3 → 17 > 21 → FALSE
✓ (ii) 25 DIV 4 = 6 and 25/4 = 6.25 → 6 >= 6.25 → FALSE
✓ (iii) "Fred" <> "fred" → TRUE (strings are case-sensitive)
I Do
INPUT / OUTPUT & OPERATORS
INPUT / OUTPUT
When data needs to be input, the user is prompted to type something, and whatever they type is assigned to a variable:
OUTPUT "Please enter your name: "
INPUT Name
Arithmetic Operators
+ Addition
- Subtraction
/ Division
* Multiplication
^ Raised to the power of (exponent)
MOD Modulus — returns the REMAINDER when one integer is divided by another. e.g. 22 MOD 5 = 2
DIV Quotient — returns the whole number result of division. e.g. 22 DIV 5 = 4
Logical / Comparison Operators
= Equal to
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
<> Not equal to
Boolean Operators & Expressions
A Boolean expression uses one or more logical operators and evaluates to TRUE or FALSE.
AND: Both conditions must be TRUE
OR: At least one condition must be TRUE
NOT: Reverses the Boolean value (NOT TRUE = FALSE)
Order of Precedence (BODMAS/PEMDAS)
Parentheses → Exponents → Multiplication & Division → Addition & Subtraction
Example: 10 + 3 * (18 - 2) / 2 ^ 3 = 10 + 3 * 16 / 8 = 10 + 6 = 16
You Do Everybody writes
(a) Write pseudocode to input Length and Width of a rectangle and output the area. [3]
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
(b) Given A=3, B=3, C=7, D=8, what will be output by: [1]
X ← NOT (A = B AND C <> D)
OUTPUT X
Answer: _____________________________________________________________
(c) Write a Boolean condition to test whether Result is between 1 and 10 (inclusive). [2]
_____________________________________________________________
(d) Write pseudocode to output "X is valid" if X is divisible by 7 but NOT divisible by 3, otherwise print "X
is invalid". [3]
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
You Do Marking Scheme
(a) Rectangle area pseudocode: [3 marks]
INPUT Length
INPUT Width
OUTPUT "Area = ", Length * Width
(b) Value of X when A=3, B=3, C=7, D=8: [1 mark]
✓ A = B is TRUE and C <> D is TRUE → TRUE AND TRUE = TRUE → NOT TRUE = FALSE
✓ OUTPUT X → FALSE
(c) Boolean condition for Result between 1 and 10: [2 marks]
IF Result >= 1 AND Result <= 10
[1 mark each comparison, both needed for full marks]
(d) X divisible by 7 but not 3: [3 marks]
IF X MOD 7 = 0 AND X MOD 3 <> 0
THEN
OUTPUT "X is valid"
ELSE
OUTPUT "X is invalid"
ENDIF
I Do
SEQUENCE AND SELECTION
There are three basic control structures in all high-level imperative languages: sequence, selection and iteration.
Sequence
Two or more statements written and executed one after the other in order. The simplest control structure.
Selection — IF Statements
A selection statement uses IF or CASE with a logical (Boolean) expression. Variables of Boolean type can only be TRUE or FALSE.
IF condition
THEN
// statements if TRUE
ELSE
// statements if FALSE
ENDIF
Nested IF Statements
An IF statement may be nested inside another IF. Example: output the largest of three numbers:
IF Num1 >= Num2 AND Num1 >= Num3
THEN OUTPUT Num1
ELSE
IF Num2 >= Num1 AND Num2 >= Num3
THEN OUTPUT Num2
ELSE OUTPUT Num3
ENDIF
ENDIF
CASE Statement
CASE statements allow one of several branches to be executed depending on the value of a variable:
INPUT MemberType
CASE OF MemberType
"Junior" : EntryFee ← 2.0
"Senior" : EntryFee ← 3.0
"Special" : EntryFee ← 0.0
OTHERWISE OUTPUT "Invalid member type"
ENDCASE
You Do Everybody writes
(a) Write a selection statement to test integer variable Mark. If Mark is 75 or over, output "Distinction". If Mark is
between 60 and 74, output "Pass". Otherwise, output "Fail". [4]
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
(b) Given A=5, B=10, C=15, what will be output by the following? [1]
IF A = B OR B <= C
THEN OUTPUT "True"
ELSE OUTPUT "False"
ENDIF
Answer: _____________________________________________________________
You Do Marking Scheme
(a) Mark grading with nested IF: [4 marks]
IF Mark >= 75
THEN
OUTPUT "Distinction"
ELSE
IF Mark >= 60
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
ENDIF
(b) Output when A=5, B=10, C=15: [1 mark]
✓ A = B → 5 = 10 → FALSE
✓ B <= C → 10 <= 15 → TRUE
✓ FALSE OR TRUE → TRUE → OUTPUT "True"
I Do
COUNT-CONTROLLED LOOPS — FOR ... NEXT
Iteration means repetition. Statements to be repeated are placed inside a loop structure. A FOR...NEXT loop is a count-
controlled loop — the counter is automatically incremented each time the loop is performed.
FOR ... NEXT Loop Syntax
FOR Count ← 1 TO 10
OUTPUT Count
NEXT Count
This prints all numbers between 1 and 10. An increment (STEP) can be specified:
FOR Count ← 2 TO 10 STEP 3
OUTPUT Count
NEXT Count
This outputs: 2, 5, 8 (starts at 2, increments by 3 each time, stops before exceeding 10)
Nested FOR Loops
You can have one loop nested inside another. Example: display all multiplication tables between 2 and 10:
FOR Table ← 2 TO 10
FOR N ← 1 TO 10
Answer ← Table * N
OUTPUT Answer
NEXT N
NEXT Table
The outer FOR loop executes 9 times. Each time, the inner loop executes 10 times. Total OUTPUT executions: 9 x 10 = 90 times.
Count-Controlled vs Condition-Controlled
Use FOR...NEXT when you know exactly how many times the loop should run. Use WHILE or REPEAT when the number of
repetitions depends on a condition.
You Do Everybody writes
(a) Complete the pseudocode which inputs a start number and an end number, and outputs all numbers
in between which are divisible by either 3 or 7 (or both): [4]
INPUT StartNum
INPUT EndNum
FOR N ← ........................
IF ........................
THEN
........................
ENDIF
........................
(b) In the multiplication table code above, how many times will the OUTPUT statement be executed?
Explain your answer. [2]
_____________________________________________________________
_____________________________________________________________
You Do Marking Scheme
(a) Complete FOR loop: [4 marks — 1 each]
INPUT StartNum
INPUT EndNum
FOR N ← StartNum TO EndNum
IF N MOD 3 = 0 OR N MOD 7 = 0
THEN
OUTPUT N
ENDIF
NEXT N
(b) How many times is OUTPUT executed: [2 marks]
✓ 90 times [1 mark]
✓ The outer FOR loop (Table 2 to 10) is executed 9 times. Each time the outer loop runs, the inner loop (N 1 to 10)
is executed 10 times. So total = 9 × 10 = 90 [1 mark]
I Do
CONDITION-CONTROLLED LOOPS
WHILE...DO...ENDWHILE and REPEAT...UNTIL are examples of indefinite (condition-controlled) iteration.
WHILE ... DO ... ENDWHILE (Pre-condition loop)
The condition is checked BEFORE the loop is entered. If the condition is FALSE from the start, the loop body is never executed.
WHILE Visitors <> -1 DO
Total ← Total + Visitors
Days ← Days + 1
INPUT Visitors
ENDWHILE
Average ← Total / Days
If Visitors = -1 before entering the loop, none of the statements execute (risk of runtime error if Days = 0).
REPEAT ... UNTIL (Post-condition loop)
The condition is checked at the END of the loop. The loop body is ALWAYS executed at least once.
Number ← 1
REPEAT
Number ← Number * 2
OUTPUT Number
UNTIL Number > 1000
This loop always runs at least once, doubling Number each time until it exceeds 1000.
Comparing the Three Loop Types
✓ FOR...NEXT: use when the exact number of repetitions is known in advance
✓ WHILE...DO...ENDWHILE: use when the number is unknown and the loop may not execute at all (pre-condition)
✓ REPEAT...UNTIL: use when the loop must execute at least once (post-condition)
You Do Everybody writes
(a) Explain what will happen when the following pseudocode is coded and executed: [2]
Total ← 0
X ← 0
WHILE X <> 100 DO
X ← X + 3
Total ← Total + X
ENDWHILE
OUTPUT "Total = ", X
_____________________________________________________________
_____________________________________________________________
(b) The REPEAT loop below doubles Number until it exceeds 1000. How many times is the loop
performed? [1]
Number ← 1
REPEAT
Number ← Number * 2
OUTPUT Number
UNTIL Number > 1000
A: 9 B: 10 C: 500
Answer: _____________
You Do Marking Scheme
(a) WHILE loop with X += 3: [2 marks]
✓ X will never equal exactly 100 (X goes 0, 3, 6, ... 99, 102, 105...) [1 mark]
✓ The program will result in an infinite loop / will never terminate [1 mark]
(b) How many times does REPEAT loop run: [1 mark]
✓ Answer: B (10 times)
✓ Number: 1 → 2 → 4 → 8 → 16 → 32 → 64 → 128 → 256 → 512 → 1024
✓ Loop runs 10 times before Number (1024) exceeds 1000
Rewriting as WHILE loop:
Number ← 1
WHILE Number <= 1000 DO
Number ← Number * 2
OUTPUT Number
ENDWHILE
I Do
ARRAYS
An array is a data structure used to hold several elements of the same data type. Each element is accessed by
its index number. In IGCSE pseudocode, the index of the first element is 1.
Declaring an Array
Arrays are declared with a name, size range and data type:
DECLARE StudentName : ARRAY[1:10] OF STRING
Assigning a value to the third element:
StudentName[3] ← "Morris, J"
You Do Everybody writes
Using pseudocode, an array named StudentName which will hold the names of 10 students could be declared like this:
DECLARE StudentName : ARRAY[1:10] OF STRING
(1) What will be output at line 06 the third time the FOR...NEXT loop is executed? [1]
01 DECLARE Day : ARRAY[1:7] OF STRING
02 DECLARE Customers : ARRAY[1:7] OF INTEGER
03 Day ← ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]
04 TotalCustomers ← 0
05 FOR N ← 1 TO 7
06 OUTPUT(Day[N])
07 INPUT Customers[N]
08 TotalCustomers ← TotalCustomers + Customers[N]
09 NEXT N
(2) Define an array called numbers holding the numbers 37, 76, 55, 91, 23. Write pseudocode to reverse the order, storing them in a
second array called ReverseNumbers. Print out the contents of ReverseNumbers. [5]
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
You Do Marking Scheme
(1) Output at line 06, third time loop executes: [1 mark]
✓ Tue (N=3, Day[3] = "Tue")
(2) Reverse array pseudocode: [5 marks, 1 each]
DECLARE numbers : ARRAY[1:5] OF INTEGER
numbers ← [37, 76, 55, 91, 23]
DECLARE ReverseNumbers : ARRAY[1:5] OF INTEGER
FOR Index ← 1 TO 5
ReverseNumbers[Index] ← numbers[6 - Index]
NEXT Index
OUTPUT(ReverseNumbers)
I Do
CREATING A MAINTAINABLE PROGRAM
Whether a program has a few lines or tens of thousands, it is important to make it as easy to read and understand as
possible. This helps create a maintainable program that can be amended if necessary and used over and over again.
Meaningful Identifiers
Meaningful identifiers should be used for variables, constants, arrays, procedures and functions. Using a consistent format (e.g.
Pascal case) helps readability and maintainability.
✓ Good examples: GrandTotal, YearJoined, ConvertToCelsius, NumMarks, Average
✓ Poor examples: X, Y, Z, N, Temp (not self-explanatory)
Commenting
Comments should be used to document the program. In IGCSE pseudocode, comments begin with //. They should include:
✓ Program name and purpose
✓ The purpose of each section / complex area of code
✓ The purpose of each procedure and function
✓ Who wrote the program and when
This ensures the program can still be understood long after it was written.
Decomposition into Subprograms (Procedures & Functions)
Decomposing a long, complex program into subprograms (procedures and functions) makes debugging and maintaining it
easier:
✓ Subprograms are usually no more than one page of code
✓ Each subprogram can be tested separately and shown to be correct
✓ A particular subprogram can be used several times in the same program
✓ Subprograms can be saved in a subroutine library to be used in other programs
You Do Everybody writes
(a) The pseudocode below uses poor identifiers. Rewrite it with meaningful identifiers, assuming the
values entered represent exam marks between 0 and 100. Add a comment and use better variable names.
[4]
X ← 0
INPUT Y
N ← 1
WHILE Y <> -1 DO
X ← X + Y
N ← N + 1
INPUT Y
ENDWHILE
Z ← X / N
OUTPUT Z
(b) Give TWO reasons why using meaningful identifiers is important when writing a program. [2]
1. _____________________________________________________________
2. _____________________________________________________________
You Do Marking Scheme
(a) Rewritten with meaningful identifiers: [4 marks]
// Find average of a set of marks
Total ← 0
INPUT Mark
NumMarks ← 1
WHILE Mark <> -1 DO
Total ← Total + Mark
NumMarks ← NumMarks + 1
OUTPUT "Enter next mark, -1 to end"
INPUT Mark
ENDWHILE
Average ← Total / NumMarks
OUTPUT "Average mark: ", Average
[1 mark: comment; 1 mark: Total/Mark/NumMarks/Average used; 1 mark: logic preserved; 1 mark: white
space/formatting]
(b) Why meaningful identifiers matter: [1 each]
✓ Makes the program easier to read and understand for yourself and others
✓ Makes it easier to maintain and update the program — you know what each variable represents without having
to trace through the code
✓ Helps reduce errors when writing or modifying the program
Thank you