9618/21 · May/June 2022 · Worked solutions

Step-by-step solutions based on the mark scheme (not a mark-scheme dump).

Question 1

Paper page 2 for Q1
Original paper page 2

Part 1(a) — solution

An algorithm 1

Mark points

  • Include the ideas shown in the solution above.

Part 1(b)(i) — solution

Answer: 4

4 Variable Use of variable Data type Temp Stores the average temperature REAL PetName Stores the name of my pet STRING MyDOB To calculate how many days until my DATE next birthday LightOn Stores state of light; light is only on or off BOOLEAN One mark for each data type

Mark points

  • Correct result: 4

Part 1(b)(ii) — solution

One mark for variable name, and one for reason 2 Variable: Temp Reason: Name does not indicate what the variable is used for

Mark points

  • Include the ideas shown in the solution above.

Part 1(c) — solution

Answer: 4

4 Expression Evaluation INT((31 / 3) + 1) 11 MID(TO_UPPER("Version"), 4, 2) "SI" TRUE AND (NOT FALSE) TRUE NUM_TO_STR(27 MOD 3) "0" One mark per row

Mark points

  • Correct result: 4

Part 1 — solution

Declare loop variable and counter as integers, counter initialised

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Declare loop variable and counter as integers, , counter initialised

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Functions header including parameter, ending and return type

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Declare all local variables used, attempted solution has to be reasonable

Mark points

  • Include the ideas shown in the solution above.

Question 2

Paper page 3 for Q2
Original paper page 3

Part 2(a) — solution

  1. The single input value that could result in S4 Button-Y

Mark points

  • The single input value that could result in S4 Button-Y

Part 2(b) — solution

One mark per row 4 Example answer Note: Accept other valid answers

Mark points

  • Include the ideas shown in the solution above.

Part 2 — solution

Set up a conditional loop, repeating until the value is found or the EOF() is reached

Mark points

  • Include the ideas shown in the solution above.

Part 2 — solution

Calculation of number of pairs to match (length or half length)

Mark points

  • Include the ideas shown in the solution above.

Part 2 — solution

Randomly decide which of the three ranges to select

Mark points

  • Include the ideas shown in the solution above.

Part 2 — solution

Conditional loop while not found and not end of array

Mark points

  • Include the ideas shown in the solution above.

Question 3

Paper page 4 for Q3
Original paper page 4

Part 3(a) — solution

  1. Allows the user to search for films being shown // input name of film they
  2. Allows the user to search for available seats
  3. Calculate cost of booking
  4. Book a given number of seats for a particular screening

Mark points

  • Allows the user to search for films being shown // input name of film they
  • Allows the user to search for available seats
  • Calculate cost of booking
  • Book a given number of seats for a particular screening

Part 3(b) — solution

Function 1

Mark points

  • Include the ideas shown in the solution above.

Part 3 — solution

STEP 10 or explicit increment if conditional loop used

Mark points

  • Include the ideas shown in the solution above.

Part 3 — solution

Compare value of element in column 1 with parameter passed into function

Mark points

  • Include the ideas shown in the solution above.

Question 4

Paper page 6 for Q4
Original paper page 6

Part 4(a) — solution

Answer: 206

One mark per row 2 Answer The value that has been on the stack for the longest time. 'H' The memory location pointed to by TopOfStack if three 206 POP operations are performed. 2022 Page 4 of 12 9618/21 Cambridge International AS & A Level – Mark Scheme May/June 2022

Mark points

  • Correct result: 206

Part 4(b) — solution

Answer: 4 · 200

4 Stack Pointer Memory Value location 200 201 'D'  TopOfStack 202 'C' 203 'A' 204 'X' 205 'Z' 206 'N' 207 'P' One mark for:

Mark points

  • Correct result: 4
  • Correct result: 200

Part 4 — solution

Values 'X' to 'P' unchanged (204 to 207)

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

Output selected value and incrementing a counter in a loop

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

Output each value and incrementing a counter in a loop

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

…Extracting characters to compare // create reverse string

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

One alphanumeric character range correct

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

...and use Decrypt() with element in column 2 as parameter

Mark points

  • Include the ideas shown in the solution above.

Question 5

Paper page 8 for Q5
Original paper page 8

Part 5 — solution

One mark per point to Max 6 6

Mark points

  • Include the ideas shown in the solution above.

Part 5 — solution

Description of how Field 2 could be extracted e.g. using substring function and lengths of Field 1 and Field 2

Mark points

  • Include the ideas shown in the solution above.

Part 5 — solution

Output the counter, following a reasonable attempt, after the loop Alternative Solution: DECLARE ThisInt, Count : INTEGER Count  0 FOR ThisInt  107 TO 197 STEP 10 OUTPUT ThisInt Count  Count + 1 NEXT ThisInt OUTPUT Count Mark as follows:

Mark points

  • Include the ideas shown in the solution above.

Part 5 — solution

All alphanumeric character ranges correct

Mark points

  • Include the ideas shown in the solution above.

Question 6

Paper page 9 for Q6
Original paper page 9

Part 6 — solution

Compare extracted field with search value

Mark points

  • Include the ideas shown in the solution above.

Part 6(a) — solution

  1. IF ThisInt MOD 10 = 7 THEN

Mark points

  • IF ThisInt MOD 10 = 7 THEN

Part 6(b) — solution

  1. IF MySwitch = 1 THEN 4
  2. IF MySwitch = 2 THEN
  3. IF MySwitch = 3 THEN
  4. 1. ANY test of MySwitch = 1, 2 or 3

Mark points

  • IF MySwitch = 1 THEN 4
  • IF MySwitch = 2 THEN
  • IF MySwitch = 3 THEN
  • 1. ANY test of MySwitch = 1, 2 or 3

Part 6 — solution

Check for mismatch of characters inside loop / test for mismatch after loop for reversed string

Mark points

  • Include the ideas shown in the solution above.

Part 6 — solution

Output warning message if parameter not found

Mark points

  • Include the ideas shown in the solution above.

Question 7

Paper page 11 for Q7
Original paper page 11

Part 7 — solution

If search value found, extract Field 1and Field 3 and output them

Mark points

  • Include the ideas shown in the solution above.

Part 7(a) — solution

  1. WHILE Index <= Num AND IsPal = TRUE

Mark points

  • WHILE Index <= Num AND IsPal = TRUE

Part 7(b) — solution

Answer: 4 · D

  1. B
  2. D
  3. C
  4. ...F and G

Mark points

  • B
  • D
  • C
  • ...F and G

Question 8

Paper page 14 for Q8
Original paper page 14

Part 8(a) — solution

FUNCTION RandomChar() RETURNS CHAR 6 DECLARE ThisRange : INTEGER DECLARE ThisChar : CHAR //First select the range ThisRange  INT(RAND(3)) + 1 // 1 to 3 CASE OF ThisRange 1: ThisChar  CHR(INT(RAND(26) + 65)) // 65 to 90: 'A' to 'Z' ThisChar  LCASE(ThisChar) // 'a' to 'z' 2: ThisChar  CHR(INT(RAND(26) + 65)) // 65 to 90: A to Z 3: ThisChar  NUM_TO_STR(INT(RAND(10)) // '0' to '9' ENDCASE RETURN ThisChar ENDFUNCTION Mark as follows:

Mark points

  • Include the ideas shown in the solution above.

Part 8(b) — solution

  1. WHILE Password = "" AND Index <= 500
  2. IF Secret[Index, 1] = Name THEN
  3. IF Password = "" THEN

Mark points

  • WHILE Password = "" AND Index <= 500
  • IF Secret[Index, 1] = Name THEN
  • IF Password = "" THEN

Part 8(c) — solution

  1. Stub testing
  2. A simple module is written to replace each of the modules
  3. The simple module will return an expected value // will output a message

Mark points

  • Stub testing
  • A simple module is written to replace each of the modules
  • The simple module will return an expected value // will output a message

Part 8(d) — solution

  1. Length too long // length too short
  2. Invalid character
  3. Incorrect grouping (including number of hyphens)
  4. Duplicated characters

Mark points

  • Length too long // length too short
  • Invalid character
  • Incorrect grouping (including number of hyphens)
  • Duplicated characters

Part 8(e) — solution

  1. Generate a random integer divisible by 3
  2. Split range into 1/3 and set as numeric
  3. Else alphabetic character

Mark points

  • Generate a random integer divisible by 3
  • Split range into 1/3 and set as numeric
  • Else alphabetic character