Skip to main content
A-LevelComputer ScienceProgramming9618/21 · May/June 2023 · Q46 Marks

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().

  1. 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.

  1. [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 →

About this question

Topic
Programming, A-Level Computer Science (syllabus 9618). Structured question, 6 marks.
Source
A-Level Computer Science, May/June 2023 Paper 2 Variant 1, question 4.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep