9618/22 · May/June 2022 · Worked solutions

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

Question 0

Part 0 — solution

Answer: 4

4 Marks as follows: One mark per outlined group If no marks per group then mark by columns (columns 3 to 6) for max 4

Mark points

  • Correct result: 4

Question 1

Paper page 2 for Q1
Original paper page 2

Part 1(a) — solution

Correct answer only: 1 Breakpoint

Mark points

  • Include the ideas shown in the solution above.

Part 1(b) — solution

One mark per row 4 Activity Life cycle stage An identifier table is produced. Design Syntax errors can occur. Coding The developer discusses the program requirements with the Analysis customer. A trace table is produced. Testing

Mark points

  • Include the ideas shown in the solution above.

Part 1(c) — solution

  1. A description of what the identifier is used for / the purpose of the identifier
  2. The data type of the identifier
  3. The number of elements of an array // the length of a string
  4. An example data value
  5. Value of any constants used
  6. The scope of the variable (local or global)

Mark points

  • A description of what the identifier is used for / the purpose of the identifier
  • The data type of the identifier
  • The number of elements of an array // the length of a string
  • An example data value
  • Value of any constants used
  • The scope of the variable (local or global)

Part 1(d) — solution

One mark per row 4 Statement Error Status  TRUE AND FALSE NO ERROR IF LENGTH("Password") < "10" shouldn’t be a string // must be an "10" THEN integer Code  Parameter must be a char // cannot be a LCASE("Electrical") string Alternative: LCASE should be TO_LOWER Result  IS_NUM(-27.3) Parameter must be a string / char // cannot be a number 2022 Page 3 of 14 9618/22 Cambridge International AS & A Level – Mark Scheme May/June 2022

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Initialise Count before loop AND Input NextNum in a loop

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Procedure heading (including parameter) and ending

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Procedure heading (including parameter) and ending

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Change the procedure header to include a (numeric) parameter (as well as the filename)

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Change the procedure header to include a numeric parameter (as well as the filename)

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Declare and initialise Count, Total and NumString

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Function heading and ending including parameters and return type

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Conditional loop while character not found and not end of string

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Loop for length of ThisString (allow from 0 or 1)

Mark points

  • Include the ideas shown in the solution above.

Part 1 — solution

Initialise password to empty string at the start and return (attempted) password at the end of the function

Mark points

  • Include the ideas shown in the solution above.

Question 2

Paper page 3 for Q2
Original paper page 3

Part 2 — solution

Loop until NextNum < 0 AND OUTPUT statement including Count plus a message

Mark points

  • Include the ideas shown in the solution above.

Part 2 — solution

Declaration of local variables for three lines AND File OPEN in READ mode AND CLOSE

Mark points

  • Include the ideas shown in the solution above.

Part 2 — solution

Declaration of local variables for three lines AND (at least one) File OPEN in READ mode AND CLOSE

Mark points

  • Include the ideas shown in the solution above.

Part 2 — solution

A loop to count the total number of lines in the file

Mark points

  • Include the ideas shown in the solution above.

Part 2 — solution

Loop for number of characters in InString

Mark points

  • Include the ideas shown in the solution above.

Part 2 — solution

Two loops to generate 3 groups of 4 characters // One loop to generate 12 / 14 characters

Mark points

  • Include the ideas shown in the solution above.

Question 3

Paper page 4 for Q3
Original paper page 4

Part 3 — solution

Use of IsPrime(NextNum)as a function (must return a value)

Mark points

  • Include the ideas shown in the solution above.

Part 3(a)(i) — solution

One mark per red annotation 3

Mark points

  • Include the ideas shown in the solution above.

Part 3(a)(ii) — solution

Answer: 3

  1. Two rows correct – one mark
  2. Four rows correct – two marks
  3. All rows correct – three marks

Mark points

  • Two rows correct – one mark
  • Four rows correct – two marks
  • All rows correct – three marks

Part 3(b) — solution

  1. Breaking a complex problem down makes it easier to understand / solve //
  2. Smaller problems are easier to program / test / maintain
  3. Sub-problems can be given to different teams / programmers with different

Mark points

  • Breaking a complex problem down makes it easier to understand / solve //
  • Smaller problems are easier to program / test / maintain
  • Sub-problems can be given to different teams / programmers with different

Part 3 — solution

Ref use of single variable rather than LineX, LineY and LineZ

Mark points

  • Include the ideas shown in the solution above.

Part 3 — solution

Extract a character and test for comma in a loop

Mark points

  • Include the ideas shown in the solution above.

Part 3 — solution

Correct use of both substring functions (in correct sequence)

Mark points

  • Include the ideas shown in the solution above.

Part 3 — solution

Compare with parameter without case conversion in a loop

Mark points

  • Include the ideas shown in the solution above.

Part 3 — solution

Compare with parameter without case conversion in a loop

Mark points

  • Include the ideas shown in the solution above.

Part 3 — solution

Use of RandomChar()to generate a character in a loop

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

PROCEDURE LastLines(ThisFile : STRING) 6 DECLARE ThisLine, LineX, LineY, LineZ : STRING OPENFILE ThisFile FOR READ LineY  "" LineZ  "" WHILE NOT EOF(ThisFile) READFILE Thisfile, ThisLine // read a line LineX  LineY LineY  LineZ LineZ  ThisLine ENDWHILE CLOSEFILE ThisFile OUTPUT LineX OUTPUT LineY OUTPUT LineZ ENDPROCEDURE Marks as follows to Max 6:

Mark points

  • Include the ideas shown in the solution above.

Part 4(a) — solution

Alternative (using two loops): PROCEDURE LastLines(ThisFile : STRING) DECLARE ThisLine, LineX, LineY, LineZ : STRING DECLARE Count, Count2 : INTEGER Count  0 OPENFILE ThisFile FOR READ WHILE NOT EOF(ThisFile) READFILE Thisfile, ThisLine // read a line Count  Count + 1 ENDWHILE CLOSEFILE ThisFile OPENFILE ThisFile FOR READ FOR Count2  1 TO Count - 3 READFILE Thisfile, ThisLine // read a line NEXT Count2 READFILE Thisfile, LineX READFILE Thisfile, LineY READFILE Thisfile, LineZ OUTPUT LineX OUTPUT LineY OUTPUT LineZ CLOSEFILE ThisFile ENDPROCEDURE Marks as follows to Max 6:

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

Read line from file and increment Count in a loop

Mark points

  • Include the ideas shown in the solution above.

Part 4(b) — solution

One mark per point to Max 3: 3

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

Use new parameter to determine first line to output

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

If comma, convert NumString to integer and update Total and Count

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

Return substring after a reasonable attempt

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

If match found, set termination logic in a loop

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

If match found, immediate RETURN of TRUE

Mark points

  • Include the ideas shown in the solution above.

Part 4 — solution

Reject character if Exists()returns TRUE, otherwise form string in a loop

Mark points

  • Include the ideas shown in the solution above.

Question 5

Paper page 8 for Q5
Original paper page 8

Part 5 — solution

Two separate loops, closing and re-opening the file between loops

Mark points

  • Include the ideas shown in the solution above.

Part 5 — solution

Output the lines in a loop Alternative 'two loop' solution to Max 3:

Mark points

  • Include the ideas shown in the solution above.

Part 5 — solution

Use the new parameter value to determine first line to output

Mark points

  • Include the ideas shown in the solution above.

Part 5(a) — solution

One mark for type and one mark for condition: 2 Independent marks Type: pre-condition Condition: when the value of ThisNum / the input value is equal to zero

Mark points

  • Include the ideas shown in the solution above.

Part 5(b) — solution

Answer: 6

6 ThisNum ThisChar CountA CountB Flag OUTPUT

Mark points

  • Correct result: 6

Part 5(c) — solution

  1. Modules that have already been tested individually
  2. are combined into a single (sub) program which is then tested as a whole

Mark points

  • Modules that have already been tested individually
  • are combined into a single (sub) program which is then tested as a whole

Part 5 — solution

  1. IF MID(ThisString, Index, 1) = Search THEN

Mark points

  • IF MID(ThisString, Index, 1) = Search THEN

Part 5 — solution

(Attempt to) use hyphens to link three groups

Mark points

  • Include the ideas shown in the solution above.

Question 6

Paper page 10 for Q6
Original paper page 10

Part 6 — solution

Correctly shuffle LineX, LineY and LineZ in a loop

Mark points

  • Include the ideas shown in the solution above.

Part 6 — solution

  1. CONSTANT COMMA = ','
  2. IF ThisChar = COMMA THEN

Mark points

  • CONSTANT COMMA = ','
  • IF ThisChar = COMMA THEN

Part 6 — solution

Three groups of four characters generated correctly with hyphens and without duplication (completely working algorithm) 2022 Page 14 of 14

Mark points

  • Include the ideas shown in the solution above.

Question 7

Paper page 12 for Q7
Original paper page 12

Part 7(a) — solution

FUNCTION MID(InString : STRING, Start, Num : INTEGER) 4 RETURNS STRING DECLARE MidString : STRING DECLARE InStringLen : INTEGER InStringLen  LENGTH(InString) // solution for RIGHT() then LEFT() MidString  RIGHT(InString, InStringLen – Start + 1) MidString  LEFT(MidString, Num) // alternative solution for LEFT() then RIGHT() MidString  LEFT(InString, Start + Num - 1) MidString  RIGHT(MidString, Num) RETURN MidString ENDFUNCTION Marks as follows:

Mark points

  • Include the ideas shown in the solution above.

Part 7(b) — solution

  1. Start and/or Num are >= 1 // positive
  2. Length of InString is "sufficient" for required operation

Mark points

  • Start and/or Num are >= 1 // positive
  • Length of InString is "sufficient" for required operation

Question 8

Paper page 14 for Q8
Original paper page 14

Part 8(a) — solution

  1. WHILE Found = FALSE AND Index <= LENGTH(ThisString)
  2. IF MID(ThisString, Index, 1) = Search THEN

Mark points

  • WHILE Found = FALSE AND Index <= LENGTH(ThisString)
  • IF MID(ThisString, Index, 1) = Search THEN

Part 8(b) — solution

  1. WHILE Duplicates = FALSE AND IndexA < 500
  2. IF Decrypt(Secret[IndexB, 2]) = ThisPassword
  3. IF Duplicates = FALSE THEN

Mark points

  • WHILE Duplicates = FALSE AND IndexA < 500
  • IF Decrypt(Secret[IndexB, 2]) = ThisPassword
  • IF Duplicates = FALSE THEN

Part 8(c) — solution

One mark for each point that is referenced: 6

Mark points

  • Include the ideas shown in the solution above.

Question 22

Part 22 — solution

'2' TRUE "Flip"

Mark points

  • Include the ideas shown in the solution above.

Question 43

Part 43 — solution

'4' 9 FALSE

Mark points

  • Include the ideas shown in the solution above.

Question 47

Part 47 — solution

'4' 6 FALSE

Mark points

  • Include the ideas shown in the solution above.

Question 57

Part 57 — solution

'5' "Ignored"

Mark points

  • Include the ideas shown in the solution above.

Question 99

Part 99 — solution

'9' TRUE "Flip"

Mark points

  • Include the ideas shown in the solution above.