Question 16

From Computer Science HL Paper 1 (May 2024, TZ2)

  1. String manipulation is a useful programming concept.
    Strings are zero-indexed: the index of a string’s first character is 0, and the index of a string’s last character is the length of the string minus 1.
    A set of string manipulation sub-programs is given in Figure 4.

Figure 4: String manipulation sub-programs

Table showing the name, description, and example usage of string manipulation sub-programs like subString, lenString, revString, and joinString.
Table showing the name, description, and example usage of string manipulation sub-programs like subString, lenString, revString, and joinString.

(a) The following section of pseudocode represents an algorithm that is intended to perform validation to check if the length of the string entered is between 10 and 25, inclusive. The algorithm is incorrect and contains two errors.

Pseudocode snippet for validating string length, intended to be between 10 and 25, inclusive.
Pseudocode snippet for validating string length, intended to be between 10 and 25, inclusive.

Construct the correct pseudocode that removes the two errors. [2]

(b) The following algorithm performs a task using the string sub-programs:

Pseudocode for an algorithm involving string manipulation, including a loop and sub-programs like subString, revString, and joinString.
Pseudocode for an algorithm involving string manipulation, including a loop and sub-programs like subString, revString, and joinString.

Copy and complete the trace table for the algorithm using the input data:
ADONUS, 3, 2, FERGUS, 0, 3, NASREEN, 1, 4, TUPPENCE, 0, 3, DAMOCLES, 2, 3
The values for columns J, C, X, Y and Z for the first row have been done for you.

A trace table with columns J, C, X, Y, Z, R, S, partially filled for the first row, to be completed based on the provided algorithm and input data.
A trace table with columns J, C, X, Y, Z, R, S, partially filled for the first row, to be completed based on the provided algorithm and input data.

[5]

(c)

A diagram showing example user interactions for password entry, including prompts, entered passwords, and feedback messages like 'Password has repeated characters, try again' and 'Your password is accepted'.
A diagram showing example user interactions for password entry, including prompts, entered passwords, and feedback messages like 'Password has repeated characters, try again' and 'Your password is accepted'.

Construct this algorithm in pseudocode, making use of the given string manipulation sub-programs. [8]