Перейти к содержанию

Labs · 9618 AS 9.2 · 11.1–11.3 · A2 19.2

Trace Tables

Be the computer for 9618 pseudocode. Predict every value in the trace table, then run the program line by line and watch the variables change.

37 levelsFree bench

In the exam

9618/21 October/November 2022 · Question 6(b) · 6 marks

Complete the trace table for the function IsValid() when it is called with "Liz.123@big@net", and state the value returned.

Points that gain marks

  • One mark for each area of the table: Dots, Ats and Others all start at 0 and Valid at TRUE.
  • Others counts up 1, 2, 3 for 'L', 'i', 'z', then 4, 5, 6 for '1', '2', '3' and 7, 8, 9 for 'b', 'i', 'g'.
  • Dots becomes 1 at the '.'.
  • Ats becomes 1 at the first '@' and 2 at the second.
  • Valid becomes FALSE at the second '@', and the loop ends there.
  • (ii) The function returns FALSE.

In this lab: Level 'Exam: is it an email?' is this trace table, with every value checked as you type.

9618/23 May/June 2024 · Question 7(a)(ii) · 2 marks

Mod-C() calls Mod-F() and Mod-G(), both with Par3 as a parameter. Par3 is passed by value to Mod-F() and by reference to Mod-G(). Explain the effect of the two different ways of passing the parameter Par3.

Points that gain marks

  • Any change made to Par3 within Mod-G() is reflected in the value in the calling module, Mod-C(), after Mod-G() ends.
  • Any change made to Par3 within Mod-F() is NOT reflected in the value in Mod-C() after Mod-F() ends.
  • One mark for a reasonable attempt; two marks for a full explanation in context.

In this lab: Levels 'BYVAL and BYREF' and 'Fix the swap'.

9618/21 May/June 2021 · Question 5 · 8 marks

A global 2D array Result (1000 rows, 2 columns: candidate number, mark) is to be sorted into ascending order of mark using an efficient bubble sort. Write pseudocode for the procedure Sort().

Points that gain marks

  • An outer loop and an inner loop; the correct comparison of Result[Row, 2] and Result[Row + 1, 2] in the loop.
  • A correct swap of the column 1 elements, and of the column 2 elements (by a loop or separate statements).
  • A NoSwaps flag: the conditional outer loop resets it, and the inner loop sets it when there is a swap.
  • Boundary is reduced in the outer loop.

In this lab: Levels 'A 2D array' and 'Exam: sort a 2D array' (the swap of both columns).

9618/31 October/November 2023 · Question 10 · 5 marks

(a) Declare Capacity (25), BasePointer, TopPointer and the REAL array Stack. (b) Complete the pseudocode function Pop() to pop an item from Stack.

Points that gain marks

  • (a) CONSTANT Capacity = 25; DECLARE BasePointer : INTEGER; DECLARE TopPointer : INTEGER; DECLARE Stack : ARRAY[1:25] OF REAL.
  • (b) FUNCTION Pop() RETURNS REAL; IF TopPointer >= BasePointer THEN; Item ← Stack[TopPointer]; TopPointer ← TopPointer – 1; RETURN Item.

In this lab: Level 'Exam: Pop()'.

9618/31 May/June 2023 · Question 11(b) · 4 marks

Complete the pseudocode for the function Dequeue to remove the front item from the queue.

Points that gain marks

  • IF Length > 0 THEN
  • Item ← Queue[FrontPointer]
  • Length ← Length – 1
  • FrontPointer ← 1 (when FrontPointer > MaxSize)

In this lab: Level 'Exam: Dequeue' (with MaxSize 4, so the wrap-around runs).

9618/32 October/November 2022 · Question 11(b) · 5 marks

Complete the pseudocode algorithm: the flower name is input, the linked list is searched in order, a message says whether it was found, and the algorithm ends when the next pointer is 0.

Points that gain marks

  • INPUT FlowerName
  • WHILE Pointer <> 0
  • Pointer ← NextPointer[Pointer] (in the ELSE part)
  • IF Found <> 0 THEN (the mark scheme also prints IF Pointer = 0, which is true after every search)
  • OUTPUT a 'not found' message in the ELSE part

In this lab: Level 'Exam: search a linked list'.

9618/21 May/June 2021 · Question 3(b) · 5 marks

A procedure Preview() will take the name of a text file as a parameter, output a warning message if the file is empty, and otherwise output the first five lines from the file (or as many lines as there are, if fewer than five). Write pseudocode for Preview().

Points that gain marks

  • Procedure heading (with the parameter) and ending.
  • OPENFILE ThisFile FOR READ, and CLOSEFILE ThisFile at the end.
  • IF EOF(ThisFile) THEN output a warning.
  • A conditional loop: WHILE LineNum < 6 AND NOT EOF(ThisFile).
  • In the loop: READFILE ThisFile, ThisLine and OUTPUT ThisLine (blank lines too).

In this lab: Level 'Exam: Preview a file'.

9618/22 May/June 2022 · Question 4(a) · 6 marks

A procedure LastLines() will take the name of a text file as a parameter and output the last three lines from that file, in the same order as they appear in the file. Write pseudocode for LastLines().

Points that gain marks

  • Procedure heading (with the parameter) and ending.
  • Local variables for three lines; OPENFILE … FOR READ and CLOSEFILE.
  • Loop until EOF(ThisFile), reading a line each time.
  • Shuffle in the loop: LineX ← LineY, LineY ← LineZ, LineZ ← ThisLine.
  • OUTPUT the three lines in order.

In this lab: Level 'Exam: the last three lines'.

9618/31 May/June 2023 · Question 10 · 5 marks

The pseudocode copies ActiveFile.txt to ArchiveFile.txt one line at a time; blank lines are replaced with the words "Account not present". Complete this file-handling pseudocode.

Points that gain marks

  • OPENFILE "ActiveFile.txt" FOR READ
  • WHILE NOT EOF("ActiveFile.txt")
  • WRITEFILE "ArchiveFile.txt", "Account not present"
  • WRITEFILE "ArchiveFile.txt", Account
  • CLOSEFILE "ActiveFile.txt"

In this lab: Level 'Exam: copy to an archive file'.

9618/22 October/November 2021 · Question 3(a) and (b) · 12 marks

(a)(i) Write pseudocode to declare the record structure for type Student (StudentID, Email, Club_1, Club_2, Club_3). (ii) Declare the 1D array Membership of 3000 elements. (b) Write pseudocode for the procedure GetIDs(): input a club number, output the StudentID of every member of that club, then output the count.

Points that gain marks

  • (a)(i) TYPE Student … ENDTYPE; StudentID and Email as STRING; Club_1, Club_2 and Club_3 as INTEGER.
  • (a)(ii) DECLARE Membership : ARRAY[1:3000] OF Student
  • (b) Declare and set Count to 0; prompt and INPUT the club number before the loop.
  • (b) FOR Index ← 1 TO 3000; compare Club_1, Club_2 and Club_3 of Membership[Index] with the number.
  • (b) If found: OUTPUT Membership[Index].StudentID and add 1 to Count; OUTPUT the count after the loop.

In this lab: Levels 'A record type' and 'Exam: club members'.

IGCSE 0478/22 May/June 2025 · Question 6 · 8 marks

(a) Complete the trace table for the algorithm, using the input data 2, RACECAR, TREAT. (b) State the purpose of the algorithm.

Points that gain marks

  • (a) Number 2; Index 1, 2; Word RACECAR, TREAT; Continue TRUE, TRUE, FALSE.
  • (a) V1 1, 2, 3, 4 then 1, 2; V2 7, 6, 5, 4 then 5, 4.
  • (a) L1 R, A, C, T, R; L2 R, A, C, T, A.
  • (a) OUTPUT Successful, then NOT successful.
  • (b) It finds words that read the same forwards and backwards.

In this lab: Level 'IGCSE exam: read it backwards'.

IGCSE 0478/23 May/June 2025 · Question 6(a) · 5 marks

Complete the trace table for the algorithm, using input data: COMPUTER.

Points that gain marks

  • Word COMPUTER; Index 1 to 8, then 1 to 8 again; Letter C, O, M, P, U, T, E, R.
  • Store[1], [3], [4], [6], [8] hold the consonants C, M, P, T, R.
  • Store[2], [5], [7] (the vowels) are empty.
  • OUTPUT C, M, P, T, R.

In this lab: Level 'IGCSE exam: no vowels'.

IGCSE 0478/22 October/November 2024 · Question 7(a) · 5 marks

An input of -1 will terminate the algorithm. Complete the trace table for the input data: 5, 6, -1, 20, 9, 4.

Points that gain marks

  • Value 5, 6, -1 (20, 9 and 4 are never read).
  • Count 4, 3, 2, 1, then 5, 4, 3, 2, 1.
  • Answer 5, 20, 60, 120, then 6, 30, 120, 360, 720.
  • OUTPUT 120, then 720.

In this lab: Level 'IGCSE exam: count down'.

IGCSE 0478/22 May/June 2026 · Question 7 · 5 marks

(a) State one reason to store data in a file. (b) The names of the members of a club are stored in a file called Names.txt. Write the pseudocode statements to load a line of text from Names.txt and assign the line of text to an appropriately named variable.

Points that gain marks

  • (a) The data is stored permanently, so it is not lost when the program or computer is switched off; it can be used again later or shared.
  • (b) DECLARE Name : STRING
  • (b) OPENFILE "Names.txt" FOR READ
  • (b) READFILE "Names.txt", Name
  • (b) CLOSEFILE "Names.txt"

In this lab: Level 'IGCSE exam: read a file'.

IGCSE 0478/22 May/June 2024 · Question 4(b) · 4 marks

The product code is stored in the variable Product. (i) Write the pseudocode to make sure that the product code is six characters in length. (ii) Write the pseudocode to make sure that the first two characters of the product code are “PD”.

Points that gain marks

  • (i) REPEAT INPUT Product UNTIL LENGTH(Product) = 6: the LENGTH operation and a suitable test.
  • (ii) REPEAT INPUT Product UNTIL SUBSTRING(Product, 1, 2) = "PD": the SUBSTRING operation and a suitable test.

In this lab: Level 'IGCSE exam: ask again' (both checks in one loop, joined with AND).

IGCSE 0478/23 October/November 2025 · Question 5 · 6 marks

A program inputs five numbers from 1 to 900 inclusive and stores the highest and the lowest. (a) Complete the trace table using 563, 21, 376, 99, 400. (b) The algorithm does not work correctly. State the reason and explain how it could be corrected.

Points that gain marks

  • (a) Count 1 to 5; Number 563, 21, 376, 99, 400; Lowest 900, 563, 21; Highest 1, 376, 400.
  • (b) The highest value is wrong: when a number is the new lowest, it is never checked as the highest.
  • (b) Replace the ELSE with ENDIF and remove the last ENDIF (lines 08 and 13 in the paper): two separate IF statements for Lowest and Highest.

In this lab: Levels 'IGCSE exam: high and low' (the trace) and 'Fix: highest and lowest'.

More real experiments

All labs →

Войти или создать аккаунт

IGCSE, A-Level & AP