A procedure Square() will take an integer value in the range 1 to 9 as a parameter and output a number square. The boundary of a number square is made up of the character representing the parameter value. The inside of the number square is made up of the asterisk character (*). Parameter value 1 2 3 4 ... 9 Output 1 22 22 333 3*3 333 4444 4**4 4**4 4444 ... 999999999 9*******9 9*******9 9*******9 9*******9 9*******9 9*******9 9*******9 999999999 The pseudocode OUTPUT command starts each output on a new line. For example, the following three OUTPUT statements would result in the outputs as shown: OUTPUT "Hello" OUTPUT "ginger" OUTPUT "cat" Resulting output: Hello ginger cat
- Write pseudocode for procedure Square(). Parameter validation is not required.[6]
Mark scheme
Marking points from the official mark scheme (May/June 2023). The mark or mark type is shown in brackets.
- [6] Example of iterative solution: PROCEDURE Square(Dim : INTEGER) DECLARE Count : INTEGER DECLARE ThisChar : CHAR DECLARE StringA, StringB : STRING CONSTANT FILLER = '*' StringA ← "" ThisChar ← NUM_TO_STR(Dim) FOR Count ← 1 TO Dim StringA ← StringA & ThisChar //build up first & last line NEXT Count StringB ← ThisChar FOR Count ← 1 TO Dim – 2 StringB ← StringB & FILLER //build up intermediate line NEXT Count StringB ← StringB & ThisChar // add final digit OUTPUT StringA FOR Count ← 1 TO Dim – 2 OUTPUT StringB NEXT Count IF Dim <> 1 THEN OUTPUT StringA ENDIF ENDPROCEDURE For loop-based solutions, mark as follows: 1 Procedure heading and ending including parameter 2 Loop using parameter, containing attempt to construct first line / last line 3 Construct first line / last line 4 Attempt at loop to construct intermediate line 5 Output first / last line of square when Dim > 2 6 Output all intermediate lines in a loop 7 Correct output of first two squares Note: Max 6 marks
- [6] Example of selection-based solution: PROCEDURE Square(Dim : INTEGER) DECLARE Count : INTEGER CASE OF Dim 1 : OUTPUT "1" 2 : OUTPUT "22" OUTPUT "22" 3 : OUTPUT "333" OUTPUT "3*3" OUTPUT "333" 4 : OUTPUT "4444" FOR Count ← 1 TO 2 OUTPUT "4**4" NEXT Count OUTPUT "4444" 5 : OUTPUT "55555" FOR Count ← 1 TO 3 OUTPUT "5***5" NEXT Count OUTPUT "55555" 6 : OUTPUT "666666" FOR Count ← 1 TO 4 OUTPUT "6****6" NEXT Count OUTPUT "666666" 7 : OUTPUT "7777777" FOR Count ← 1 TO 5 OUTPUT "7*****7" NEXT Count OUTPUT "7777777" 8 : OUTPUT "88888888" FOR Count ← 1 TO 6 OUTPUT "8******8" NEXT Count OUTPUT "88888888" 9 : OUTPUT "999999999" FOR Count ← 1 TO 7 OUTPUT "9*******9" NEXT Count OUTPUT "999999999" ENDCASE ENDPROCEDURE For in-line / selection-based solutions, mark as follows: 1 Procedure heading and ending including parameter 2 Correct use of parameter to select all required squares 3 Correct output of first two squares 4 At least six squares correctly output 5 At least one loop to output lines with multiple asterisks 6 All number squares output correctly
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 →