6 The pseudocode OUTPUT command starts each output on a new line. (a) A new procedure MyOutput() will take a string and a Boolean parameter. MyOutput() may be called repeatedly and will use concatenation to build a string using a global variable MyString, up to a maximum length of 255 characters. MyString will be output in either of these two cases: 1. The Boolean parameter value is TRUE 2. The resulting string (after concatenation) would be longer than 255 characters. If MyString is not output, the string is concatenated with MyString. For example, the calls to MyOutput() given below would result in the output as shown: MyOutput("Hello ", FALSE) MyOutput("ginger ", FALSE) MyOutput("cat", TRUE) MyOutput("How are you?", TRUE) Resulting output: Hello ginger cat How are you? Notes: : MyString is initialised to an empty string before MyOutput () is called for the first time. No string passed to MyOutput () will be longer than 255 characters.
- (a)Write pseudocode for MyOutput().[7]
- (b)The design of the procedure given in part (a) is modified and MyString is changed from a global to a local variable declared in MyOutput(). When the modified procedure is converted into program code, it does not work as expected. Explain why it does not work as expected.[2]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2023). The mark or mark type is shown in brackets.
- [1] Procedure heading `PROCEDURE MyOutput(NewString : STRING, EOL : BOOLEAN)` and `ENDPROCEDURE`
- [1] Calculate potential new length (e.g., `LENGTH(MyString) + LENGTH(NewString)`)
- [1] Check if potential new length > 255 (e.g., `IF LENGTH(MyString) + LENGTH(NewString) > 255 THEN`)
- [1] If length > 255, then `OUTPUT MyString` (the old `MyString`) and `MyString ← NewString`
- [1] Else (`MyString ← MyString & NewString`)
- [1] Check `EOL` parameter (e.g., `IF EOL = TRUE THEN`)
- [1] If `EOL` is TRUE, then `OUTPUT MyString` and `MyString ← ""`
- [1] A new (instance of) variable MyString is created each time the procedure is called / executed
- [1] So the previous contents are lost / MyString is re-initialised to empty string
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 →