EEasy IGCSELabTracker

On a phone the notes, quizzes and tracker work fine. The 3D models and the practice lab are made for a laptop.

Specification points 7.1–7.9 ·

the program development life cycle, decomposition and design methods, standard algorithms, validation and verification, test data, trace tables, finding errors, and writing and amending algorithms.

1The program development life cycle (7.1)

A program is developed in four stages.

1 Analysis 2 Design 3 Coding 4 Testing • identify the problem • identify the requirements • abstraction • decomposition of the problem • decomposition into sub-systems • structure diagrams • flowcharts • pseudocode • write the program code • iterative testing: test each part as it is written, amend it and re-test until it works • run the completed program with test data • check that it all works together as required
Figure 1. The program development life cycle.
  • Identify the problem and the requirements — state exactly what the program must do (the requirements specification used in every later stage).
  • Abstraction — keeping only the details needed to solve the problem and discarding the rest.
  • Decomposition — breaking a complex problem into smaller parts that are easier to solve.
  • Iterative testing — each part (module) is tested as soon as it is coded, then amended and re-tested, repeatedly, until it works.

2Systems, sub-systems and decomposition (7.2)

Every computer system is made up of sub-systems, and each sub-system is made up of further sub-systems, until each one performs a single task. Designing like this is top-down design: each small sub-system is easier to write and test, can become one module (subroutine), and different programmers can develop different sub-systems at the same time.

To decompose a problem, identify its four component parts:

Component What it is Example: class results system
Inputs data entered into the system each student's mark
Processes tasks performed on the inputs and stored data validate each mark; total, average, highest, lowest; count passes
Outputs information displayed or printed average, highest and lowest marks, number of passes
Storage data kept for future use marks saved to a file

3Designing a solution: three methods (7.2, 7.9)

Structure diagrams

Class results Enter marks Calculate results Output results Save marks Inputmark Validatemark Total andaverage Highest andlowest Countpasses
Figure 2. A structure diagram shows top-down design as a hierarchy: the whole system at the top, each level below breaking a sub-system into smaller sub-systems.

Flowcharts

A flowchart shows the steps of an algorithm and their order using the standard symbols below. Every decision has two exits, each labelled Yes/No; a loop is a flow line going back to an earlier step.

START INPUT X Total ← 0 X > 9? Sort Terminator Input/Output Process Decision Subroutine Flow line START or STOP of the flowchart INPUT a value or OUTPUT a value an action, e.g. an assignment a question with two exits: Yes/No calls a separate, non-linked flowchart shows the order in which steps are done
Figure 3. The standard flowchart symbols (syllabus section 4).

Name the flowchart symbol

Loading the interactive…

Pseudocode

Pseudocode writes an algorithm with keywords in UPPER CASE and identifiers in PascalCase (PassCount). Paper 2 algorithms are built from these statements (each construct is taught fully in Topic 8):

Pseudocode statements used in Paper 2
Total ← 0                          // assignment
INPUT Mark                         // input into a variable
OUTPUT "Total is ", Total          // commas join the values output
IF Mark >= 50                      // selection
  THEN
    OUTPUT "Pass"
  ELSE
    OUTPUT "Fail"
ENDIF
FOR Index ← 1 TO 30                // count-controlled loop
    Total ← Total + Mark[Index]    // Mark[Index]: item Index of a list (array)
NEXT Index
REPEAT                             // post-condition loop: runs at least once
    INPUT Mark
UNTIL Mark >= 0
WHILE Mark <> -1 DO                // pre-condition loop: may run zero times
    INPUT Mark
ENDWHILE

Operators: arithmetic + - * / ^; comparison = < <= > >= <>; logical AND OR NOT. Indent statements inside a structure by four spaces (THEN/ELSE by two).

The same algorithm as pseudocode and as a flowchart — it inputs 30 marks and outputs how many are 50 or more:

Pseudocode
PassCount ← 0
FOR Student ← 1 TO 30
    OUTPUT "Enter mark"
    INPUT Mark
    IF Mark >= 50
      THEN
        PassCount ← PassCount + 1
    ENDIF
NEXT Student
OUTPUT PassCount, " passed"

The flowchart has no FOR statement, so it sets its own counter (Student ← 0), adds 1 each time round and uses a decision to loop back.

START PassCount ← 0 Student ← 0 OUTPUT "Enter mark" INPUT Mark Mark >= 50? PassCount ← PassCount + 1 Student ← Student + 1 Student < 30? OUTPUT PassCount, " passed" STOP Yes No Yes No
Figure 4. The same algorithm as a flowchart.

Trace the flowchart

Loading the interactive…

4Explaining the purpose of an algorithm (7.3)

Dry-run it with a few values if needed (section 8), then give two things:

  1. the purpose — one sentence saying what the algorithm does overall;
  2. the processes — the steps it uses, in order, in words.
Pseudocode
C ← 0
FOR X ← 1 TO 20
    INPUT N
    IF N < 0
      THEN
        C ← C + 1
    ENDIF
NEXT X
OUTPUT C

Purpose: counts how many of 20 numbers input are negative and outputs that count. Processes: sets a counter to 0; inputs 20 numbers using a loop; checks whether each number is less than 0 and, if so, adds 1 to the counter; outputs the counter after the loop.

5Standard methods of solution (7.4)

In these examples Mark[1] to Mark[30] hold 30 marks and Name[1] to Name[30] hold 30 names.

Totalling, counting, maximum, minimum and average

  • Totalling keeps a running total by adding each value; counting adds 1 each time something happens. Both variables start at 0.
  • Maximum and minimum start at the first value; every other value is compared with them. (If the range is known, e.g. 0 to 100, the maximum can instead start at the lowest possible value, 0, and the minimum at the highest, 100.)
  • Average (mean) — the total divided by the number of values, calculated after the loop: Average ← Total / 30.
Totalling and counting
Total ← 0
PassCount ← 0
FOR Index ← 1 TO 30
    Total ← Total + Mark[Index]
    IF Mark[Index] >= 50
      THEN
        PassCount ← PassCount + 1
    ENDIF
NEXT Index
Maximum and minimum
Highest ← Mark[1]
Lowest ← Mark[1]
FOR Index ← 2 TO 30
    IF Mark[Index] > Highest
      THEN
        Highest ← Mark[Index]
    ENDIF
    IF Mark[Index] < Lowest
      THEN
        Lowest ← Mark[Index]
    ENDIF
NEXT Index

Linear search

Checks each item in the list in turn, from the first, until the item is found or the end of the list is reached. A Boolean flag (Found) records whether it was found.

Linear search
OUTPUT "Enter the name to find"
INPUT SearchName
Found ← FALSE
Index ← 1
REPEAT
    IF Name[Index] = SearchName
      THEN
        Found ← TRUE
      ELSE
        Index ← Index + 1
    ENDIF
UNTIL Found = TRUE OR Index > 30
IF Found = TRUE
  THEN
    OUTPUT SearchName, " found at position ", Index
  ELSE
    OUTPUT SearchName, " not found"
ENDIF

Bubble sort

Sorts a list by comparing each pair of adjacent items and swapping them if they are in the wrong order. One pass through the list moves the largest remaining item to the end, so each pass can stop one place earlier. Passes repeat until a pass makes no swaps.

Pass 1 — compare each adjacent pair 5 1 4 2 8 5 > 1 → swap 1 5 4 2 8 5 > 4 → swap 1 4 5 2 8 5 > 2 → swap 1 4 2 5 8 5 < 8 → no swap 1 4 2 5 8 8 is now in its final place The whole sort Start 5 1 4 2 8 After pass 1 1 4 2 5 8 After pass 2 1 2 4 5 8 After pass 3 1 2 4 5 8 Pass 3 makes no swaps, so the list is sorted and the algorithm stops.
Figure 5. Sorting 5, 1, 4, 2, 8 into ascending order. Amber: the pair being compared. Teal: items already in their final place.

Bubble sort, pass by pass

Loading the interactive…

Bubble sort (ascending)
Last ← 30
REPEAT
    Swapped ← FALSE
    FOR Index ← 1 TO Last - 1
        IF Mark[Index] > Mark[Index + 1]
          THEN
            Temp ← Mark[Index]          // swap, using Temp
            Mark[Index] ← Mark[Index + 1]
            Mark[Index + 1] ← Temp
            Swapped ← TRUE
        ENDIF
    NEXT Index
    Last ← Last - 1
UNTIL Swapped = FALSE OR Last = 1

For descending order, change > to < in the comparison.

6Validation and verification (7.5)

Definition

Validation — automatic checking by the program that input data is reasonable (sensible) before it is accepted. Rejected data produces an error message and must be re-entered.

Validation is needed because unreasonable data (a mark of 150, a blank name) would make the program produce wrong results or fail.

Check What it checks Example: rejected if…
Range check a value lies between a lower and an upper limit Mark < 0 OR Mark > 100
Length check the number of characters is exact, or within limits LENGTH(Password) <> 8
Type check the data is of the required data type ten is entered for a whole number
Presence check data has been entered, not left blank Email = ""
Format check the characters follow a set pattern a code that must be two letters then four digits is entered as 12AB34
Check digit the final digit of a code, calculated from the other digits, is recalculated and compared (→ Topic 2) a barcode or ISBN digit is mistyped or two digits are swapped
A range check written as a validation loop (repeats until the data is acceptable)
REPEAT
    OUTPUT "Enter a mark from 0 to 100"
    INPUT Mark
    IF Mark < 0 OR Mark > 100
      THEN
        OUTPUT "Invalid mark, please re-enter"
    ENDIF
UNTIL Mark >= 0 AND Mark <= 100
Definition

Verification — checking that data has been entered accurately, i.e. it matches the original.

Verification is needed because validation only checks that data is reasonable: a mark of 65 typed as 56 passes a range check but is wrong.

  • Visual check — the user reads the data shown on the screen, compares it with the original (e.g. the paper form) and confirms it is correct.
  • Double entry check — the data is entered twice; the computer compares the two entries and, if they differ, outputs an error and asks for the data again (e.g. "re-enter your password").

7Test data (7.6)

  • Normal data — data the program should accept and process.
  • Abnormal data — data the program should reject (outside the limits, or the wrong type).
  • Extreme data — the largest and smallest acceptable values.
  • Boundary data — the largest/smallest acceptable value and the corresponding smallest/largest rejected value, i.e. a pair at each end of the range.
accepted: 0 to 100 rejected rejected −20 −1 0 57 100 101 150 abnormal extreme normal extreme abnormal boundary boundary −1 rejected, 0 accepted 100 accepted, 101 rejected "ten": abnormal
Figure 6. Test data for a whole-number mark from 0 to 100.

To suggest test data, give the value, its type and the expected result (accepted or rejected).

8Trace tables (7.7)

A dry run is working through an algorithm by hand, step by step, with test data. A trace table records it: one column for each variable and one for output.

  • Work through the algorithm one statement at a time.
  • Write a variable's new value each time it changes (leave the cell blank if it does not).
  • Every output, including user prompts, goes in the OUTPUT column, in order.
  • Start a new row when a column that already has a value in the current row changes again.
Algorithm — test data 35, 72, 50, 64
Highest ← -1
Count ← 0
FOR Index ← 1 TO 4
    OUTPUT "Enter score"
    INPUT Score
    IF Score > Highest
      THEN
        Highest ← Score
    ENDIF
    IF Score >= 50
      THEN
        Count ← Count + 1
    ENDIF
NEXT Index
OUTPUT "Highest ", Highest
OUTPUT "Passes ", Count
Index Score Highest Count OUTPUT
-1 0
1 35 35 Enter score
2 72 72 1 Enter score
3 50 2 Enter score
4 64 3 Enter score
Highest 72
Passes 3

9Finding and correcting errors (7.8)

Dry-run the algorithm with test data whose correct result you know; where the trace table differs from the expected result, look for:

  • wrong starting values (a total not set to 0; a maximum/minimum started at the wrong value);
  • wrong loop limits or conditions (< instead of <=, TO 9 instead of TO 10);
  • a reversed comparison (< instead of >) or the wrong variable;
  • totalling or counting written as a plain assignment (Total ← Mark);
  • a statement inside the loop that belongs outside it, or the reverse.

Example — this algorithm should input 10 numbers from 1 to 1000 and output their average and the largest:

Algorithm with errors
01  Total ← 0
02  Largest ← 1000
03  FOR Count ← 1 TO 10
04      INPUT Number
05      Total ← Number
06      IF Number < Largest
07        THEN
08          Largest ← Number
09      ENDIF
10  NEXT Count
11  Average ← Total / 9
12  OUTPUT Average, " ", Largest
Line Error Correction
02 the largest starts at the highest possible value, so no number is ever bigger Largest ← 0
05 the number replaces the total instead of being added to it Total ← Total + Number
06 the comparison finds the smallest, not the largest IF Number > Largest
11 divides by the wrong number of values Average ← Total / 10

10Writing and amending algorithms (7.9)

Precision is required: write conditions and statements exactly, with operators and identifiers — Mark > 50, never "mark is more than 50". Use the identifiers the question gives.

Program code earns marks only in the 15-mark scenario question (pseudocode, Python, Visual Basic or Java). Everywhere else in Paper 2, solutions in program code score nothing — write pseudocode.

Writing an algorithm from a scenario:

  1. List the inputs, processes, outputs and storage (section 2).
  2. Initialise every total and counter.
  3. Use a loop for repeated inputs or for working through a list.
  4. Validate each input as it is entered (section 6).
  5. Process with the standard methods (section 5).
  6. Output the results with a message.

Amending means changing only what the new requirement needs and keeping the rest. The algorithm from Figure 4, amended so that each mark must be 0 to 100 and the average is also output:

Amended algorithm
PassCount ← 0
Total ← 0                                       // added
FOR Student ← 1 TO 30
    REPEAT                                      // added: range check
        OUTPUT "Enter mark (0 to 100)"
        INPUT Mark
    UNTIL Mark >= 0 AND Mark <= 100
    Total ← Total + Mark                        // added
    IF Mark >= 50
      THEN
        PassCount ← PassCount + 1
    ENDIF
NEXT Student
OUTPUT PassCount, " passed"
OUTPUT "Average mark: ", Total / 30             // added
Traps
  • Extreme vs boundary: extreme data is only the largest/smallest accepted value; boundary data is that value plus the rejected value just beyond it.
  • Validation vs verification: validation checks data is reasonable; verification checks it was entered correctly.
  • Counting adds 1, totalling adds the value. An average is calculated once, after the loop.
  • A maximum started at 0 fails if every value is negative; starting at the first value always works.

Quick check

14 multiple-choice questions. Pick an answer to see whether it is right and why.

  1. The designer of a bus timetable program stores only stop names and departure times and ignores the colour of each bus. What is this an example of?

  2. A library system displays a list of overdue books on the screen. Which component of the decomposed problem is this?

  3. How many times are the statements inside FOR Index ← 3 TO 9 … NEXT Index executed?

  4. An algorithm sets T ← 0, then a loop FOR X ← 1 TO 5 inputs N and executes T ← T + N; after the loop it executes OUTPUT T / 5. What is the purpose of the algorithm?

  5. Total ← 0 and Count ← 0 are set, then a loop inputs 4, 9, 2 and 7 into Value; each time it executes Total ← Total + Value and, only if Value > 3, Count ← Count + 1. What are the final values?

  6. An algorithm starts with Highest ← 0, then for each of the values -5, -2 and -9 executes IF Value > Highest THEN Highest ← Value. What is Highest at the end?

  7. A linear search looks for 17 in the list 4, 17, 9, 17, 3. How many items does it check before it stops?

  8. A bubble sort puts the list 6, 2, 9, 4 into ascending order. What is the list after the first pass?

  9. A product code must be three letters followed by two digits. Which validation check rejects the entry 12ABC?

  10. A parcel weight from 1 to 100 is accepted. A user types 81 instead of 18. Which check could detect this mistake?

  11. A program accepts whole numbers from 5 to 20 inclusive. Which is boundary data for the upper end of the range?

  12. A program accepts a whole-number quantity from 1 to 12 inclusive. Which value is extreme data?

  13. X ← 2 is followed by a loop FOR I ← 1 TO 3 that contains only X ← X * 2. What does OUTPUT X after the loop output?

  14. Total ← 0 is followed by a loop that inputs 3, 5 and 8 into Number and each time executes Total ← Number. What is the final value of Total?

Exam-style questions

Write your answer, then show the answer and compare. Nothing here is marked for you: you decide how close you were. What you write is saved in this browser.

Questions

1

(7.1) Name the stage of the program development life cycle in which each task is done:
(a) drawing a structure diagram; (b) identifying the requirements; (c) testing a module as soon as it is written; (d) running the finished program with normal, abnormal and boundary data.

4 marks
2

(7.1) Define abstraction and decomposition.

2 marks
3

(7.2) A smart thermostat keeps a room at a temperature chosen by the user. Decompose the system into its inputs, processes, outputs and storage.

4 marks
4

(7.2) Draw a structure diagram for a quiz program that asks 10 questions, marks each answer, keeps a score and displays the final score.

3 marks
5

(7.3, 7.7) Complete a trace table for this algorithm using the test data 4, −2, 6, 0, then state its purpose.

Count ← 0
Total ← 0
REPEAT
    OUTPUT "Enter value"
    INPUT Value
    IF Value > 0
      THEN
        Total ← Total + Value
        Count ← Count + 1
    ENDIF
UNTIL Value = 0
OUTPUT Total / Count
6 marks
6

(7.4) Show the list after each pass when a bubble sort puts 7, 3, 9, 2 into ascending order. Explain how the algorithm knows it has finished.

4 marks
7

(7.4) Describe how a linear search finds a value in a list.

3 marks
8

(7.5) Name a suitable validation check for each input and give a reason:
(a) a percentage; (b) a product code of the form AB1234; (c) a surname that must be entered;
(d) a 13-digit barcode.

4 marks
9

(7.5) Write pseudocode that makes the user enter a password of 8 to 12 characters inclusive, outputting an error message and asking again until it is valid.

4 marks
10

(7.5) Explain why data that has passed validation may still need verification, and describe a double entry check.

3 marks
11

(7.6) A program accepts a whole-number age from 11 to 16 inclusive. Give one example each of normal, abnormal and extreme test data, and a pair of boundary data, with the expected result.

5 marks
12

(7.8) This algorithm should count how many of 20 daily temperatures are above 30. Identify three errors and give corrections.

01  Count ← 1
02  FOR Day ← 1 TO 19
03      INPUT Temp
04      IF Temp >= 30
05        THEN
06          Count ← Count + 1
07      ENDIF
08  NEXT Day
09  OUTPUT Count
6 marks
13

(7.9) Draw a flowchart for the algorithm in question 12 (corrected).

5 marks
14

(7.9) The array Reading[1:7] holds seven temperatures. Write pseudocode to output the highest, the lowest and the average reading, and how many readings are below 0.

7 marks
15

(7.9) Amend the bubble sort in the notes section 5 so that it sorts into descending order.

1 mark

How well do you know this?

Rate each specification point. It is saved to your tracker as a new revision round.

All points:
  • 7.1Understand the program development life cycle, limited to: analysis, design, coding and testing
  • 7.2
    • Understand that every computer system is made up of sub-systems, which are made up of further sub-systems
    • Understand how a problem can be decomposed into its component parts
    • Use different methods to design and construct a solution to a problem
  • 7.3Explain the purpose of a given algorithm
  • 7.4Understand standard methods of solution
  • 7.5
    • Understand the need for validation checks to be made on input data and the different types of validation check
    • Understand the need for verification checks to be made on input data and the different types of verification check
  • 7.6Suggest and apply suitable test data
  • 7.7Complete a trace table to document a dry-run of an algorithm
  • 7.8Identify errors in given algorithms and suggest ways of correcting these errors
  • 7.9Write and amend algorithms for given problems or scenarios, using: pseudocode, program code and flowcharts

Settings

Your subjects

Untick the subjects you don't take. They leave the menu, the home page and the tracker. Your ratings are kept, so you can bring a subject back at any time.

Page style

Colours