Function Replace() will: 1. take three parameters: • a string (the original string) • a char (the original character) • a char (the new character) 2. form a new string from the original string where all instances of the original character are replaced by the new character 3. return the new string. Write pseudocode for function Replace().
- Function Replace() will: 1. take three parameters: • a string (the original string) • a char (the original character) • a char (the new character) 2. form a new string from the original string where all instances of the original character are replaced by the new character 3. return the new string. Write pseudocode for function Replace().[6]
Mark scheme
Marking points from the official mark scheme (May/June 2023). The mark or mark type is shown in brackets.
- [6] FUNCTION Replace(OldString : STRING, Char1, Char2 : CHAR) RETURNS : STRING DECLARE NewString : STRING DECLARE ThisChar : CHAR DECLARE Index : INTEGER NewString ← "" FOR Index ← 1 TO LENGTH(OldString) ThisChar ← MID(OldString, Index, 1) IF ThisChar = Char1 THEN ThisChar ← Char2 ENDIF NewString ← NewString & ThisChar NEXT Index RETURN NewString ENDFUNCTION Mark as follows: 1 Function heading and ending, including parameters and return type 2 Declaration of local variables used including loop counter 3 Loop for length of OldString 4 Extract char and test in a loop 5 Use of concatenate to build NewString replace char if necessary, in a loop 6 Return NewString after reasonable attempt
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 →