A program is being designed in pseudocode. The program contains the following declaration: DECLARE Data : ARRAY[1:1000] OF STRING A procedure ArrayInitialise() is written to initialise the values in the array: PROCEDURE ArrayInitialise(Label : STRING) DECLARE Index : INTEGER Index ← 1 WHILE Index <= 1000 CASE OF (Index MOD 2) 0 : Data[Index] ← FormatA(Label) Index ← Index + 1 1 : Data[Index] ← FormatB(Label) Index ← Index + 1 ENDCASE ENDWHILE ENDPROCEDURE Functions FormatA() and FormatB() apply fixed format case changes to the parameter string.
- (a)The design of the procedure does not use the most appropriate loop construct. Suggest a more appropriate construct that could be used and explain your choice. Construct Explanation[2]
- (b)The algorithm calls one of the functions FormatA() and FormatB() each time within the loop. Explain why this is not efficient and suggest a more efficient solution.[4]
Mark scheme
Marking points from the official mark scheme (May/June 2024). The mark or mark type is shown in brackets.
- [1] (a) Construct: Count-controlled loop
- [1] (a) Explanation: the number of iterations is known
- [1] (b) The functions will return the same value every time they are called
- [1] (b) ... because Label / the parameter value does not change within the loop
- [1] (b) Assign FormatA(Label) and FormatB(Label) to two (local) variables before the loop
- [1] (b) Use the (new) variables in place of the function calls / in the loop // Replace the references to FormatA() and FormatB() in the CASE clauses with the new variable names
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →