Ch. 1 - Programming
Ch. 1 - Programming
1 -1 Class: ________________________
Date: ________________________
Comments:
Numbers[0] ← 45
Numbers[1] ← 19
Numbers[2] ← 62
Numbers[3] ← 12
FOR X ← 1 TO 3
Y ←X−1
N ← Numbers[X]
WHILE Y > −1 AND N < Numbers[Y]
Numbers[Y + 1] ← Numbers[Y]
Y ← Y − 1
ENDWHILE
Numbers[Y + 1] ← N
ENDFOR
You may not need to use all the rows in the table below.
The first row of the table below has already been completed for you.
Numbers
X Y N
[0] [1] [2] [3]
45 19 62 12
(Total 5 marks)
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 2 marks)
Count 0 ←
WHILE Number > 1
Multi ←
FALSE
WHILE (Number MOD X) = 0
IF NOT Multi THEN
OUTPUT X
ENDIF
Count ← Count + 1
Multi ← TRUE
The table below lists the MOD and DIV operators for each of the available programming
languages. You should refer to the row for your programming language.
Task 1
Write a program to implement the algorithm in the figure above.
Task 2
Test that your program works:
___________________________________________________________________
___________________________________________________________________
(1)
(b) a user-defined subroutine that returns only one value that is an integer.
___________________________________________________________________
___________________________________________________________________
(1)
(c) a user-defined subroutine that returns only one value that is a single character.
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
(1)
(Total 4 marks)
___________________________________________________________________
___________________________________________________________________
(1)
(b) State the identifier of a data structure that stores values of only one data type.
___________________________________________________________________
___________________________________________________________________
(1)
(Total 2 marks)
Complete the table below by writing the most appropriate error code from the Skeleton Program
next to each proposed error message.
Unknown opcode
(Total 5 marks)
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 2 marks)
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(2)
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(2)
(c) Describe why a WHILE loop might have been a better choice than a FOR loop.
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(2)
(Total 6 marks)
Task 1
Amend the subroutine ExecuteSKP so that it adds 1 to the accumulator and then updates the
status register if required. The Registers data structure should be passed as a parameter.
Task 2
Amend the call to ExecuteSKP in the Execute subroutine as required.
Task 3
Test that the changes you have made work by conducting the following test:
• run your amended Skeleton Program
• enter L
• load prog2
• enter A
• enter R
(a) Your PROGRAM SOURCE CODE for the entire subroutine ExecuteSKP and the entire
subroutine Execute.
(4)
GEMS Metropole School Page 7 of 236
(b) SCREEN CAPTURE(S) showing the requested test described in Task 3.
The SCREEN CAPTURE(S) only need to show all of Frame 0 and all of the final frame.
(1)
(Total 5 marks)
This question adds validation to the Skeleton Program. The subroutine EditSourceCode asks
10. the user to enter a line number. The line number must be an integer and the number of an
existing line in the file containing the program.
Therefore, a valid line number for prog2.txt would be an integer between 1 and 11 inclusive.
Task 1
Amend the subroutine EditSourceCode to check that the line number entered by the user is a
valid existing line number. If an invalid value is entered the subroutine should output an
appropriate error message. The program must not continue until a valid line number has been
entered.
Task 2
Test that the changes you have made work by conducting the following test:
(a) Your PROGRAM SOURCE CODE for the entire subroutine EditSourceCode.
(5)
If storing a return address will overwrite an instruction or data, then an appropriate error message
should be output using the ReportRunTimeError subroutine. The original code in the
ExecuteJSR subroutine should only be carried out if there is no error.
Task 1
Amend the ExecuteJSR subroutine. If storing a return address would overwrite an instruction or
data, the ReportRunTimeError subroutine should be called with an appropriate error message.
One method of completing this task would require the addition of extra parameter(s) to the
ExecuteJSR subroutine.
Task 2
If your solution requires additional parameter(s) for the ExecuteJSR subroutine amend the call to
ExecuteJSR in the Execute subroutine.
Task 3
Test that the changes you have made work by conducting the following test:
(a) Your PROGRAM SOURCE CODE for the entire subroutine ExecuteJSR and the entire
subroutine Execute if you have made changes in Task 2.
(4)
The SCREEN CAPTURE(S) only need to show the final frame and the contents of the
stack before execution terminates.
(1)
(Total 5 marks)
This question extends the functionality of the Skeleton Program. The option to edit the source
12. code is to be extended to allow lines to be deleted or inserted within a loaded source code
program.
C – Cancel edit
Option D should delete the current line without changing the size of the data structure. The lines
after the deleted line need to be moved within the data structure so that there is no gap in the
source code.
Figure 1
You must write your own delete routine and not use any built-in delete function that might be
available in the programming language you are using.
Option I should allow the user to enter a new line to be inserted above the chosen line without
changing the size of the data structure. The lines after the inserted line need to be moved within
the data structure so they are not overwritten.
You should check that there is sufficient space in the data structure to accommodate a new line.
If there is not sufficient space, an error message should be displayed.
Figure 2 shows an example where lines 4 to 11 move and a new line 4 is inserted. The size of
the data structure does not change.
Figure 2
Task 1
Amend the EditSourceCode subroutine to include the delete line option.
Task 2
Test that the changes you have made work by conducting the following test:
Task 3
Amend the EditSourceCode subroutine to include the insert line option.
Task 4
Test that the changes you have made work by conducting the following test:
(a) Your PROGRAM SOURCE CODE for the entire subroutine EditSourceCode.
(12)
The SCREEN CAPTURE(S) only need to show the test from entering option E until after
the edited source code has been displayed.
(1)
The SCREEN CAPTURE(S) only need to show the test from entering option E until after
the edited source code has been displayed.
(1)
(Total 14 marks)
SUBROUTINE A(S, X, Y)
P ← -1
WHILE P = -1 AND X <= Y
Z ← (X + Y) DIV 2
IF List[Z] = S THEN
P ←Z
ELSE
IF List[Z] < S THEN
X ← Z + 1
ELSE
Y ← Z – 1
ENDIF
ENDIF
ENDWHILE
RETURN P
ENDSUBROUTINE
The DIV operator calculates the whole number part resulting from an integer division, for
example, 10 DIV 3 = 3
Complete Table 2 by hand-tracing the algorithm in the figure above when the following statement
is executed.
The first row of Table 2 has already been completed for you.
Table 2
S X Y P Z List[Z]
38 0 18 −1
Result:
(Total 5 marks)
D ← 0
S ← 0
T ←0
WHILE C < 3 AND D < 3
T ←T+1
N1 ← generate random integer between 1 and 6 inclusive
The DIV operator calculates the whole number part resulting from an integer division, for
example, 10 DIV 3 = 3
The table below lists the DIV operators for each of the available programming languages. You
should refer to the row for your programming language.
C# /
Java /
Pascal div
Python //
VB.NET \
Task 1
Write a program to implement the algorithm in the figure above.
Task 2
Test that your program works:
• run your program.
State the most appropriate data type to use for whole numbers.
15.
_______________________________________________________________________
_______________________________________________________________________
(Total 1 mark)
State the identifier of a variable in the Skeleton Program that can only represent whole
16. numbers.
_______________________________________________________________________
_______________________________________________________________________
(Total 1 mark)
State the identifier and data type of a variable in the Skeleton Program that can only represent
17. two different values.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 2 marks)
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(3)
(Total 4 marks)
Describe two changes that would need to be made to the subroutine DisplayGrid to enable
this.
You should not make any changes to the Skeleton Program to answer this question.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 2 marks)
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 2 marks)
State the identifier of a subroutine in the Skeleton Program that contains definite iteration.
21.
_______________________________________________________________________
_______________________________________________________________________
(Total 1 mark)
_______________________________________________________________________
(Total 1 mark)
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 2 marks)
State the identifier of a subroutine in the Skeleton Program that performs exception handling
24. and give an example of a circumstance that might cause an exception within that subroutine.
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 2 marks)
What is a subroutine?
25.
_______________________________________________________________________
_______________________________________________________________________
(Total 1 mark)
_______________________________________________________________________
_______________________________________________________________________
(Total 1 mark)
_______________________________________________________________________
(Total 1 mark)
Complete the table below by writing the labels that should appear in each of the boxes (a) to
(d) in the chart above.
Box Label
cp
(a)
(b)
(c)
(d)
(Total 2 marks)
The figure below shows the numbers in the puzzle grid cells when puzzle1 is first loaded. These
are the protected cells for this puzzle.
The Skeleton Program is to be changed so that the user cannot change the contents of any
protected cells.
The subroutine SolvePuzzle needs to be modified so that the user cannot change a digit in a
protected cell but can still enter a digit into an empty cell or change a digit that they have
previously entered.
Task 1
Amend the subroutine SolvePuzzle so that it checks every cell reference entered by the user
against the protected cell references in Puzzle and only allows the contents of the cell to be
changed if the cell referenced by CellInfo is not a protected cell.
(a) Your PROGRAM SOURCE CODE for the entire subroutine SolvePuzzle.
(7)
The SCREEN CAPTURE(S) need(s) to show the puzzle grid before and after the described
test.
(1)
(Total 8 marks)
This question adds further validation to the Skeleton Program. The subroutine SolvePuzzle
30. asks the user to enter coordinates and a digit. The Skeleton Program is to be changed so that if
the digit entered by the user already exists in the referenced row, column or sub-grid, the digit
cannot be used.
The figure below shows the numbers in the puzzle grid cells of puzzle1 when first loaded.
Task 1
Write a new subroutine, DuplicateDigit, which takes PuzzleGrid, Row, Column and Digit as
parameters. The subroutine should return True if the digit entered by the user is already present
in the row, column or sub-grid of the cell the user has entered. Otherwise, the subroutine should
return False.
Task 2
Amend the subroutine SolvePuzzle so that it uses DuplicateDigit to check the user input and
only allows the digit to be placed into the puzzle grid if the digit is not already present in the row,
column or sub-grid of the cell the user has entered. If the digit is already present, an appropriate
message should be given to the user.
Task 3
Test that the changes you have made work by conducting the following test:
• run your amended Skeleton Program
• enter L
• load puzzle1
• enter S
• enter 178
• enter 819
• enter 124
• enter 989
• enter 555
(a) Your PROGRAM SOURCE CODE for the entire subroutine DuplicateDigit and the entire
subroutine SolvePuzzle.
(8)
The SCREEN CAPTURE(S) need(s) to show the puzzle grid before and after the described
test.
(1)
(Total 9 marks)
For example, if the user enters -3, the three most recently entered digits should each be
replaced by a space in the puzzle grid and the Answer data structure should be updated.
If the number of cells to be cleared is greater than the number of entries in the Answer data
structure, all digits entered by the user should be cleared.
Task 1
Write a new subroutine, ClearEntries, that clears the required number of previously entered
digit(s) from the puzzle grid and updates the Answer data structure as described above.
Task 2
Amend the subroutine SolvePuzzle to test user input for a negative value. If the user input is a
negative integer, the subroutine should call ClearEntries with the necessary parameters and
then re-display the puzzle grid.
Task 3
Test that the changes you have made work by conducting the following test:
• run your amended Skeleton Program
• enter P
• load puzzle1
• enter S
• enter -x
• enter -1
• enter -5
(a) Your PROGRAM SOURCE CODE for the entire subroutine ClearEntries and the entire
subroutine SolvePuzzle.
(12)
The SCREEN CAPTURE(S) need(s) to show the puzzle grid before and after the described
test.
(1)
(Total 13 marks)
Graphics
32.
The Skeleton Program accompanying this Preliminary Material is a simple graphics program
that uses ASCII art.
ASCII art is a technique used to represent images using the 95 printable characters in the ASCII
character set. ASCII art is used where text can be printed but bitmapped graphics cannot, for
example in console mode programming environments. It requires monospaced fonts (such as
Courier New) which position the characters neatly in columns.
Different techniques can be used in ASCII art for different effects. Here are some examples:
Figure 1 shows an ASCII art image loaded from the image1.txt data file.
Figure 1
The Skeleton Program uses printable ASCII characters to display images. The program allows
the user to load an image from a text file. The option "S - Save image" saves the image in
such a way that it can be viewed in a text editor, such as Notepad or TextEdit.
The Skeleton Program can also load greyscale images where the shade of each pixel is
encoded by an 8-bit integer. 8-bit integer encoding allows 256 possible shades of grey. The
program changes the greyscale values into ASCII characters. Figure 2 shows the image created
when loading the greyscale.txt data file.
The data files ascii.txt, image2.txt and image3.txt available with this Preliminary Material
also contain parts of images.
A sentinel value is a special value after the end of a series of data values. It is a terminator for
33. the series of data values but is not treated as part of the series. A sentinel value is used when
you do not know how many data values are in the series.
The algorithm, represented using pseudo-code below, is an attempt at a method to add numbers
that are input as a series terminated by the sentinel value -1
X ← 0
Result ← 0
WHILE X ≠ -1
INPUT X
Result ← Result + X
ENDWHILE
OUTPUT Result
The first row of the table has already been completed for you.
X Result Output
0 0 -
(3)
(b) Comment on the result of the trace and describe how the algorithm should be modified.
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(2)
(Total 5 marks)
The algorithm, represented using pseudo-code below, outputs a series of integers or the
34. message No result. The output depends upon the value entered by the user.
FOR N ← 1 TO Factor
Product ←
Product * N
OUTPUT N
ENDFOR
ELSE
OUTPUT "No result"
ENDIF
Task 1
Write a program to implement the algorithm.
Task 2
Test that your program works:
• run your program, then enter the number 720
• run your program, then enter the number 600
(c) What is true for all valid inputs for X that output a number of numbers which is not true for
all other valid inputs that output No result?
(1)
(Total 11 marks)
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
(1)
(Total 3 marks)
This question refers to the constants set at the beginning of the Skeleton Program.
36.
It is a good programming technique to use a named constant rather than the value it represents.
State a reason why each of the following are set as constants. Your answers for part (a) and (b)
must be different.
(a) EMPTY_STRING
___________________________________________________________________
___________________________________________________________________
(1)
(b) MAX_WIDTH
___________________________________________________________________
___________________________________________________________________
(1)
(Total 2 marks)
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 2 marks)
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
(1)
(Total 3 marks)
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(3)
(Total 4 marks)
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 2 marks)
This question refers to the text file image3.txt and the subroutine LoadAsciiImage
41.
The first line of the text file image3.txt contains:
Cat,59,25,A
(a) Explain the effect of changing the first line to Cat,25,59,A and then calling
LoadAsciiImage
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(2)
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(2)
(c) Explain the effect of changing the first line to Cat,59,10,A and then calling
LoadAsciiImage
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(2)
(Total 6 marks)
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 3 marks)
Figure 1 Figure 2
Task 1
Write a new subroutine MirrorImage that produces a mirror image of the image loaded into Grid
and stores it in a new data structure. The subroutine then displays the mirror image.
Task 2
Amend subroutine DisplayMenu to include the new option:
M – Mirror image
Task 3
Amend subroutine Graphics to call MirrorImage when the user chooses option M
Task 4
Test that the changes you have made work by conducting the following test:
• run the program
• enter L
• load image1
• enter M
(a) Your PROGRAM SOURCE CODE for the entire subroutines MirrorImage, DisplayMenu
and Graphics
(6)
(b) SCREEN CAPTURE(S) showing the requested test, including the menu and the display of
the mirror image.
(1)
(Total 7 marks)
If an image contains a hidden message, the key to use is the integer value of the digit at the end
of the image title in the first line of the file. For example, if the image title is image4 then the key
is 4
When decrypting a message from an image file, each greyscale value is used in turn with the key
to produce a result. The key is subtracted from the greyscale value and the result is interpreted
according to the table below.
The table describes the rules that should be followed to determine what secret character, if any,
is hidden in the greyscale image.
> 0 AND ≤ 26 The result is the position in the alphabet of the decrypted character.
The result means that the character was not part of the message that
> 26 was encrypted, and should be represented by an underscore character,
ie the _ character.
Example 1
Greyscale value is 1 and the key is 0
1–0=1
The decrypted character is A as this is the first letter in the alphabet. This should be appended to
the hidden message.
Example 2
Greyscale value is 5 and the key is 3
5–3=2
The decrypted character is B as this is the second letter in the alphabet. This should be
appended to the hidden message.
Example 3
Greyscale value is 7 and the key is 7
7–7=0
The decrypted character is a space as the result was 0. This should be appended to the hidden
message.
Example 4
Greyscale value is 52 and the key is 1
52 – 1 = 51
The result is greater than 26 so the greyscale value was not an encrypted character and an
underscore character should be added to the hidden message.
Task 1
Write a new subroutine, FindSecretChar, which takes as parameters the PixelValue and Key,
where Key is the key used to decrypt the hidden character. The subroutine should return the
decrypted character if the pixel value was a character from the message, otherwise it should
return the underscore character.
Task 2
Amend the subroutine LoadGreyScaleImage to:
• get the key from the image title
• call the subroutine FindSecretChar in the appropriate place and build up the hidden
message from the returned characters
• output the complete hidden message.
Task 3
Test that the changes you have made work by conducting the following test:
• run the program
• enter L
• load greyscale
(a) Your PROGRAM SOURCE CODE for the entire subroutines FindSecretChar and
LoadGreyScaleImage
(9)
(b) SCREEN CAPTURE(S) showing the requested test, including the display of the message
and the image.
(1)
(Total 10 marks)
This question extends the functionality of the Skeleton Program. A new option, C, is to be added
45. to compress an existing ASCII art image file using run-length encoding and store it in a new file.
The number of symbols in a run of symbols is to be counted and this count, separated by a
comma from the symbol, is stored in the new file. Each count and symbol pair should be put on a
new line.
For example, Figure 1 shows the contents of the ascii.txt data file.
Figure 1
TestImage1,5,3,A
###@@@@@AABB!!!
Figure 2
TestImage1,5,3,C
3,#
5,@
2,A
2,B
3,!
You can assume that there are no newline characters in the ASCII art image file.
Task 1
Write a new subroutine, CompressFile
Task 2
Amend subroutine DisplayMenu to include the new option:
C – Compress file
Task 3
Amend subroutine Graphics to call CompressFile when the user chooses option C
Task 4
Test that the changes you have made work by conducting the following test:
• run the program
• enter C
• enter the file name image2
• load the file CMPimage2 into a text editor.
(a) Your PROGRAM SOURCE CODE for the entire subroutine CompressFile
(12)
(b) SCREEN CAPTURE(S) showing the requested test, including the menu and all of the
contents of the file CMPimage2 in the text editor.
(1)
(Total 13 marks)
The Skeleton Program presents the user with the current state of the board and shows the
possible moves that the player whose turn it is can make.
The player enters the ID of the piece they want to move, followed by the row and column of the
board square to which they want to move the piece.
The program confirms if the move was a jump and, if so which piece was jumped over.
When a player has no possible moves available when it is their turn, the game ends and that
player has lost the game.
State one difference between local and global variables and give two reasons why it is good
47. practice to use local variables.
_______________________________________________________________________
_______________________________________________________________________
(Total 3 marks)
Count ← 0
WHILE NumberIn > 0
Count ← Count + 1
PartValue ← PartValue * 10
ENDFOR
NumberOut ←
NumberOut + PartValue
ENDWHILE
OUTPUT "The result is: " NumberOut
The table below lists the MOD and DIV operators for each of the available programming
languages. You should refer to the row for your programming language.
C# % /
Java % /
Python % //
VB.Net Mod \
Task 1
Write a program to implement the algorithm above.
Task 2
Test that your program works:
• run your program, then enter the number 22
• run your program, then enter the number 29
• run your program, then enter the number -1
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
(1)
(Total 2 marks)
_______________________________________________________________________
_______________________________________________________________________
(Total 1 mark)
What is the specific purpose of the exception handling construct in the subroutine SetUpBoard?
51.
_______________________________________________________________________
_______________________________________________________________________
(Total 1 mark)
_______________________________________________________________________
_______________________________________________________________________
(Total 1 mark)
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
(1)
(Total 3 marks)
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 3 marks)
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(Total 5 marks)
(a) This question refers to the subroutine SelectMove. This subroutine makes three calls to the
56. subroutine DisplayErrorCode to notify the user of errors. The error codes passed as
parameters are to be made more informative for the user.
Task 1
Modify the subroutine DisplayErrorCode so that meaningful error messages are
displayed for each type of error explaining the circumstances which caused each error. The
error code should also be displayed.
(i) Your PROGRAM SOURCE CODE for the entire subroutine DisplayErrorCode
(3)
(ii) SCREEN CAPTURE(S) showing the requested test including the list of possible
moves for Player A.
(1)
(b) This question refers to the subroutine ValidJump. The rules of the game are to be
amended. Instead of jumping over their own piece, a player can only jump over an
opponent’s piece.
Task 1
Amend the subroutine ValidJump so that a jump is only possible if the middle piece
belongs to the opponent.
Task 2
Test that the changes you have made work by conducting the following test:
(i) Your PROGRAM SOURCE CODE for the entire subroutine ValidJump.
(2)
(ii) SCREEN CAPTURE(S) showing the requested test including the list of possible
moves before the jump and your test input, and then the board display after the
jump.
(1)
Task 1
Create a new subroutine CountNumberOfPieces. This subroutine is to count the number of
pieces a player has on the board.
Task 2
Amend the subroutine PrintResult to implement the formula given in the information box
above and output the score for each player and display the winner.
Task 3
• run the program
• enter Y
• load game4.txt
(ii) SCREEN CAPTURE(S) showing all the output from the requested test including the
board display.
(1)
(d) This question will further change the rules of the game.
When a piece is promoted to a dame, the player who the new dame belongs to now
chooses one of the opponent’s pieces. This piece is removed from the board and the dame
is placed in the square the removed piece was in.
(i) State the identifier of the data structure that now needs to be passed as a parameter
into the subroutine MoveDame.
(1)
Task 1
Amend the subroutine MoveDame.
• ask the player the piece ID of the opponent’s piece they want to remove
• check that the piece is an opponent’s piece and is on the board
• remove the opponent’s piece
• return the coordinates for the new dame.
Task 2
Amend the calls to MoveDame from within the subroutine MovePiece.
You will need to amend the parameter list of the subroutine heading of MovePiece
and the call to MovePiece from within the subroutine MakeMove.
Task 3
Test that the changes you have made work by conducting the following test:
Task 4
• move b5 to row 0, column 3
• take piece a6
(ii) Your PROGRAM SOURCE CODE for the entire subroutine MoveDame and the entire
subroutine MakeMove.
(9)
(iii) SCREEN CAPTURE(S) showing the requested test including the board display after
piece b1 has been taken.
(1)
(iv) SCREEN CAPTURE(S) showing the requested test including the board display after
piece a6 has been taken.
(1)
(Total 29 marks)
Samuel Morse invented a code that allowed the transmission of text using simple on-off signals.
The code differentiates between short and long signals, usually represented as dots and dashes.
For example, ships within line of sight could use a light turned on and off to communicate with
each other. Early telegraph communication used electrical pulses that were converted into
sound.
Each letter of the alphabet is represented by a unique combination of dots and dashes. Different
letters may have a different number of dots and / or dashes. For example, the letter T is
represented by a single dash and the letter H is represented by four dots.
Morse codes for each letter in the alphabet are shown in Table 1.
Table 1
A .–
B –...
C –.–.
D –..
E .
F ..–.
G ––.
H ....
I ..
J .–––
K –.–
L .–..
M ––
N –.
O –––
P .––.
Q ––.–
R .–.
S ...
T –
U ..–
V ...–
W .––
X –..–
Y –.––
Z ––..
For example, the letter D has a Morse code generated by first taking the left branch (dash), then
two right branches (dot, dot). So the code for the letter D is dash, dot, dot.
Figure 1
However, there can be confusion over where letters start and end. For example, the signals for
the letters TEA (T is dash; E is dot and A is dot, dash) are the same as for the letter X (X is dash,
dot, dot, dash).
To indicate where a letter ends when writing Morse codes, a space is placed between signals
representing letters, shown in this Preliminary Material with a ⌂ character. So TEA becomes:
Figure 2
Figure 3
When writing Morse code, each letter is separated from the next letter by one space and a word
is separated from the next word by three spaces. There are no spaces after the last letter in a
message.
Two English messages and their Morse codes are shown in Table 2.
Table 2
When using light or sound to transmit Morse code, a short pause is required between two
signals.
The rules of transmission when using light or sound are:
Table 3
Figure 4
Index Signal
0 =
1 =
2 =
3 ⌂
4 ⌂
5 ⌂
6 =
7 ⌂
8 ⌂
9 ⌂
10 =
11 ⌂
12 =
13 =
14 =
15 ⌂
16 ⌂
17 ⌂
18 ⌂
19 ⌂
20 ⌂
21 ⌂
22 =
23 =
24 =
25 ⌂
26 =
27 ⌂
28 =
29 ⌂
30 =
31 =
32 =
33 ⌂
0 SPACE SPACE
1 A .-
2 B -...
3 C -.-.
4 D -..
5 E .
6 F ..-.
7 G --.
8 H ....
9 I ..
10 J .---
11 K -.-
12 L .-..
13 M --
14 N -.
15 O ---
16 P .--.
17 Q --.-
18 R .-.
19 S ...
20 T -
21 U ..-
22 V ...-
23 W .--
24 X -..-
GEMS Metropole School Page 54 of 236
25 Y -.--
26 Z --..
The data structure Letter stores the data shown at the nodes of the tree in Figure 1. Two
further data structures, Dash and Dot, are used to represent the information on how the nodes
are connected. These connections are known as pointers.
For example, the letter A is stored at index 1 in Letter. The left branch from A goes to W, stored
at index 23, so Dash at index 1 stores the pointer value 23. The right branch from A goes to R,
stored at index 18, so Dot at index 1 stores the pointer value 18.
0 20 SPACE 5
1 23 A 18
2 0 B 0
3 0 C 0
4 24 D 2
5 1 E 9
6 0 F 0
7 17 G 26
8 0 H 0
9 21 I 19
10 0 J 0
11 25 K 3
12 0 L 0
13 15 M 7
14 11 N 4
15 0 O 0
16 0 P 0
17 0 Q 0
18 0 R 12
19 22 S 8
20 13 T 14
21 0 U 6
22 0 V 0
23 10 W 16
24 0 X 0
25 0 Y 0
26 0 Z 0
The Skeleton Program presents the user with a menu that allows the user to choose between
sending and receiving a message using Morse code.
Receiving a message involves reading a text file containing a transmission string (see Figure 4)
and converting this first into dots and dashes and then into letters of the alphabet.
Sending a message asks the user to enter a message using uppercase letters and spaces. The
program will then output the dots and dashes of the equivalent Morse code message, including
the correct number of spaces between characters and words.
INPUT Number
Root ←
1
WHILE (Root * Root) < Number
Root ← Root + 1
ENDWHILE
d ← 2
FactorFound ←
FALSE
WHILE (FactorFound = FALSE) AND (d <= Root)
r ←Number MOD d
IF r = 0 THEN
FactorFound ← TRUE
ENDIF
d ←
d + 1
ENDWHILE
IF FactorFound = FALSE THEN
OUTPUT "Prime"
ELSE
OUTPUT "Not prime"
ENDIF
The MOD operator calculates the remainder resulting from an integer division, for example, 10
MOD 3 = 1.
(a) Complete the table below by hand-tracing the algorithm. Use 5 as the input value. You may
not need to use all the rows in the table.
(3)
(3)
(Total 6 marks)
The algorithm, represented using pseudo-code below, outputs a series of numbers. The contents
59. of the series depends on the initial value entered by the user.
Number 0←
WHILE (Number < 1) OR (Number > 10)
OUTPUT “Enter a positive whole number: ”
INPUT Number
IF Number > 10 THEN
OUTPUT “Number too large.”
ELSE
IF Number < 1 THEN
OUTPUT “Not a positive number.”
ENDIF
ENDIF
ENDWHILE
c ← 1
FOR k ←
0 TO Number − 1
OUTPUT c
c ←
(c * (Number − 1 − k)) DIV (k + 1)
ENDFOR
Task 1
Write a program to implement the algorithm above.
Task 2
Test the program by showing the result of entering:
−3
then 11
then 10
___________________________________________________________________
___________________________________________________________________
(1)
___________________________________________________________________
___________________________________________________________________
(1)
(Total 2 marks)
Award a mark if the values in an area are correct regardless of which row they are on so long as
they are in the correct overall sequence in a column.
Alternative answer 1:
Local variables only use memory when the program block they are in is executing; global
variables use memory the entire time the program is executing;
Alternative answer 2:
Local variables only exist when the program block they are in is executing; global variables exist
the entire time the program is running;
A. local variables are stored on a stack / in a stack frame; global variables are generally stored
elsewhere in the memory;
[2]
Note to examiners
If a language allows variables to be used without explicit declaration (eg Python) then
this mark should be awarded if the correct variables exist in the program code and
the first value they are assigned is of the correct data type.
Alternative:
Python 3
Python 2
var
Number, X, Count : integer; // MP1
Multi : boolean;
begin
write('Enter a number greater than 1: ');
readln(Number); // MP2
X := 2;
Count := 0; // MP3
while Number > 1 do // MP4
begin
Multi := false; // MP5
while Number Mod X = 0 do // MP6
begin
if not Multi // MP7
then
writeln(X);
Count := Count + 1;
Multi := true;
Number := Number DIV X; // MP8
end;
X := X + 1; // MP9
end;
writeln(Count);
readln;
end.
C#
bool multi;
Console.Write("Enter an integer greater than 1: ");
int number = Convert.ToInt32(Console.ReadLine()); // MP2
int x = 2; // MP1
int count = 0; // MP3
while (number > 1) // MP4
{
multi = false; // MP5
while (number % x == 0) // MP6
{
if (!multi) // MP7
{
Console.WriteLine(x);
}
count++;
multi = true;
number = number / x; // MP8
}
x++; // MP9
}
Console.WriteLine(count);
ConvertToDecimal;
GetMenuOption;
LoadFile / PassTwo;
A. Memory / SymbolTable;
R. if any additional code
R. if spelt incorrectly
I. case & spacing
Max 1
1
Max 1
1
[2]
Unknown opcode 5
Max 2
[2]
Alternative answer:
If there are multiple asterisks, it finds the first one (rather than the last one);
Additional asterisks within the comment will not affect assembly;
{
int[] registers = {0, 0, 0, 0, 0} ;
setFlags(registers[ACC], registers);
registers[PC] = 0;
registers[TOS] = HI_MEM;
int frameNumber = 0;
displayFrameDelimiter(frameNumber);
displayCurrentState(sourceCode, memory, registers);
String opCode = memory[registers[PC]].opCode;
while (!opCode.equals("HLT")) {
frameNumber += 1;
Console.println();
displayFrameDelimiter(frameNumber);
int operand = memory[registers[PC]].operandValue;
Console.println("* Current instruction Register: " + opCode + " " +
operand);
registers[PC] = registers[PC] + 1;
switch (opCode) {
case "LDA":
executeLDA(memory, registers, operand); break;
case "STA":
executeSTA(memory, registers, operand); break;
case "LDA#":
executeLDAimm(registers, operand); break;
case "ADD":
executeADD(memory, registers, operand); break;
case "JMP":
executeJMP(registers, operand); break;
case "JSR":
executeJSR(memory, registers, operand); break;
case "CMP#":
executeCMPimm(registers, operand); break;
case "BEQ":
executeBEQ(registers, operand); break;
case "SUB":
executeSUB(memory, registers, operand); break;
case "SKP":
executeSKP(registers); break; // MP1
case "RTN":
executeRTN(memory, registers); break;
default:
break;
}
if (registers[ERR] == 0) {
opCode = memory[registers[PC]].opCode;
displayCurrentState(sourceCode, memory, registers);
} else {
opCode = "HLT";
}
}
Console.println("Execution terminated");
Must match code from (a), including prompts on screen capture matching those in
code.
Code for (a) must be sensible.
Console.WriteLine(SourceCode(LineNumber))
While Choice <> "C"
Choice = EMPTY_STRING
While Choice <> "E" And Choice <> "C"
Console.WriteLine("E - Edit this line")
Console.WriteLine("C - Cancel edit")
Console.Write("Enter your choice: ")
Choice = Console.ReadLine()
End While
If Choice = "E" Then
Console.Write("Enter the new line: ")
SourceCode(LineNumber) = Console.ReadLine()
End If
DisplaySourceCode(SourceCode)
End While
End Sub
Python 3
def EditSourceCode(SourceCode):
LineNumber = 0
NumberOfLines = int(SourceCode[0])
while LineNumber not in range(1, NumberOfLines + 1): # MP2, MP3, MP4
try: # MP1
LineNumber = int(input("Enter line number of code to edit: "))
if LineNumber not in range(1, NumberOfLines + 1):
print("Not a valid line number") # MP5
except:
print("Not a valid number")
print(SourceCode[LineNumber])
Choice = EMPTY_STRING
while Choice != "C":
Choice = EMPTY_STRING
while Choice != "E" and Choice != "C":
print("E - Edit this line")
print("C - Cancel edit")
Choice = input("Enter your choice: ")
if Choice == "E":
SourceCode[LineNumber] = input("Enter the new line:")
DisplaySourceCode(SourceCode)
return SourceCode
def EditSourceCode(SourceCode):
LineNumberStr = input("Enter line number of code to edit: ")
Valid = False
while not Valid:
if LineNumberStr.isdigit() and int(LineNumberStr) > 0 and
int(LineNumberStr) <= int(SourceCode[0]): # MP1, MP2, MP3, MP4
Valid = True
LineNumber = int(LineNumberStr)
else:
print("Not a valid line number") # MP5
LineNumberStr = input("Enter line number of code to edit: ")
print(SourceCode [LineNumber])
Choice = EMPTY_STRING
while Choice != "C":
Choice = EMPTY_STRING
while Choice != "E" and Choice != "C":
print("E - Edit this line")
print("C - Cancel edit")
Choice = input("Enter your choice: ")
if Choice == "E":
SourceCode[LineNumber] = input("Enter the new line:")
DisplaySourceCode(SourceCode)
return SourceCode
Python 2
def EditSourceCode(SourceCode):
LineNumber = 0
NumberOfLines = int(SourceCode[0])
while LineNumber not in range(1, NumberOfLines + 1): # MP2, MP3, MP4
try: # MP1
LineNumber = int(raw_input("Enter line number of code to edit: ")
.replace("\r", ""))
if LineNumber not in range(1, NumberOfLines + 1):
print "Not a valid line number" # MP5
except:
print "Not a valid number"
print SourceCode[LineNumber]
Choice = EMPTY_STRING
while Choice != "C":
Choice = EMPTY_STRING
while Choice != "E" and Choice != "C":
print "E - Edit this line"
print "C - Cancel edit"
Choice = raw_input("Enter your choice: ") .replace("\r", "")
if Choice == "E":
SourceCode[LineNumber] = raw_input("Enter the new line: ")
.replace("\r", "")
DisplaySourceCode(SourceCode)
return SourceCode
def EditSourceCode(SourceCode):
LineNumberStr = raw_input("Enter line number of code to edit: ")
.replace("\r", "")
Valid = False
while not Valid:
if LineNumberStr.isdigit() and int(LineNumberStr) > 0 and
int(LineNumberStr) <= int(SourceCode[0]): # MP1, MP2, MP3, MP4
Valid = True
LineNumber = int(LineNumberStr)
else:
print "Not a valid line number" # MP5
LineNumberStr = raw_input("Enter line number of code to edit: ")
.replace("\r", "")
print SourceCode [LineNumber]
Choice = EMPTY_STRING
while Choice != "C":
Choice = EMPTY_STRING
while Choice != "E" and Choice != "C":
print "E - Edit this line"
print "C - Cancel edit"
Choice = raw_input("Enter your choice: ") .replace("\r", "")
if Choice == "E":
SourceCode[LineNumber] = raw_input("Enter the new line:")
.replace("\r", "")
DisplaySourceCode(SourceCode)
return SourceCode
(a) 2 marks for AO3 (design) and 2 marks for AO3 (programming)
11.
Marking guidance:
Note: AO3 (design) points are for selecting appropriate techniques to use to solve
the problem, so should be credited whether the syntax of programming language
statements is correct or not and regardless of whether the solution works.
3) Correct value for number of program lines passed into subroutine // check that
memory location pointed to by TOS is empty;
4) ReportRunTimeError called with suitable message in appropriate place;
Must match code from (a), including prompts on screen capture matching those in
code.
Code for (a) must be sensible.
Alternative method:
Alternative method:
Alternative Answer:
Marking guidance:
Note: AO3 (design) points are for selecting appropriate techniques to use to solve
the problem, so should be credited whether the syntax of programming language
statements is correct or not and regardless of whether the solution works.
def EditSourceCode(SourceCode):
LineNumber = int(input("Enter line number of code to edit: "))
print(SourceCode[LineNumber])
Choice = EMPTY_STRING
while Choice != "C":
Choice = EMPTY_STRING
while Choice != "E" and Choice != "D" and Choice != "I" and Choice !=
"C":
print("E - Edit this line")
print("D - Delete this line") # MP4
print("I - Insert a new line above this line")
print("C - Cancel edit")
Choice = input("Enter your choice: ")
if Choice == "E":
SourceCode[LineNumber] = input("Enter the new line:")
if Choice == "D": # MP5
NumberOfLines = int(SourceCode[0]) #
NumberOfLines -= 1 #
SourceCode[0] = str(NumberOfLines) # MP1, MP7 part
for ThisLine in range(LineNumber, NumberOfLines + 1): # MP2, MP6
part
SourceCode[ThisLine] = SourceCode[ThisLine + 1] # MP3, MP8
if Choice == "I": # MP5 alt
if int(SourceCode[0]) < HI_MEM - 1: # MP11 part
print("Enter the new line:") #
NewLine = input() # MP10
NumberOfLines = int(SourceCode[0]) #
NumberOfLines += 1 #
SourceCode[0] = str(NumberOfLines) # MP1 alt./MP7 part
for ThisLine in range(NumberOfLines, LineNumber, - 1): # MP2
alt., MP6 part
SourceCode[ThisLine] = SourceCode[ThisLine - 1] # MP3 alt.,
MP9
SourceCode[LineNumber] = NewLine # MP12
else:
print("Error - can't add a new line. Program is at maximum
length") # MP11 part
DisplaySourceCode(SourceCode)
return SourceCode
def EditSourceCode(SourceCode):
LineNumber = int(raw_input("Enter line number of code to edit: ")
.replace("\r", ""))
print SourceCode[LineNumber]
Choice = EMPTY_STRING
while Choice != "C":
Choice = EMPTY_STRING
while Choice != "E" and Choice != "D" and Choice != "I" and Choice !=
"C": #
print "E - Edit this line"
print "D - Delete this line" # MP4
print "I - Insert a new line above this line" #
print "C - Cancel edit"
Choice = raw_input("Enter your choice: ") .replace("\r", "")
if Choice == "E":
SourceCode[LineNumber] = raw_input("Enter the new line:")
.replace("\r", "")
if Choice == "D": # MP5
NumberOfLines = int(SourceCode[0]) #
NumberOfLines -= 1 #
SourceCode[0] = str(NumberOfLines) # MP1, MP7 part
for ThisLine in range(LineNumber, NumberOfLines + 1): # MP2, MP6
part
SourceCode[ThisLine] = SourceCode[ThisLine + 1] # MP3, MP8
if Choice == "I": # MP5 alt.
if int(SourceCode[0]) < HI_MEM - 1: # MP11 part
print "Enter the new line:" #
NewLine = raw_input() # MP10
NumberOfLines = int(SourceCode[0]) #
NumberOfLines += 1 #
SourceCode[0] = str(NumberOfLines) # MP1 alt./MP7 part
for ThisLine in range(NumberOfLines, LineNumber, - 1): # MP2
alt., MP6 part
SourceCode[ThisLine] = SourceCode[ThisLine - 1] # MP3 alt.,
MP9
SourceCode[LineNumber] = NewLine # MP12
else:
print "Error - can't add a new line. Program is at maximum
length" # MP11 part
DisplaySourceCode(SourceCode)
return SourceCode
1 mark for each correct set of values in the correct sequence (boxed in red);
A. entries within a boxed area sharing a row (e.g. 9 and 8 on the same row).
[5]
Note to examiners:
If a language allows variables to be used without explicit declaration, (eg Python),
then this mark should be awarded if the correct variables exist in the program code
and the first value they are assigned is of the correct data type.
2) Correct WHILE loop syntax allowed by the programming language and correct
condition for termination of the loop;
3) Correct generation of two random numbers between 1 and 6 and output within
loop;
4) Correct running total assigned to S and updating of T;
5) Correct condition to increment C within the loop;
6) Correct condition to increment D with the loop;
7) Correct calculation of A outside the loop;
8) Correct output outside loop;
I. case
Sub Main()
Dim Rnd As Random = New Random()
Dim C As Integer = 0 '
Dim D As Integer = 0 '
Dim S As Integer = 0 '
Dim T As Integer = 0 ' MP1
While C < 3 And D < 3 ' MP2
T += 1
Dim N1 As Integer = Rnd.Next(1, 7) '
Dim N2 As Integer = Rnd.Next(1, 7) ' MP3
Console.WriteLine($"{N1} {N2}") '
S = S + N1 + N2 ' MP4
If N1 = 6 Or N2 = 6 Then '
C += 1 ' MP5
End If
If N1 = N2 Then '
D += 1 ' MP6
End If
End While
Dim A AS Integer = S \ (T * 2) ' MP7
Console.WriteLine($"{C} {D} {A}") ' MP8
Console.ReadLine()
End Sub
Python 3
import random
C = 0 #
D = 0 #
S = 0 #
T = 0 # MP1
while C < 3 and D < 3: # MP2
T += 1
N1 = random.randint(1,6) #
N2 = random.randint(1,6) # MP3
print(N1, N2) #
S = S + N1 + N2 # MP4
if N1 == 6 or N2 == 6: #
C += 1 # MP5
if N1 == N2: #
D += 1 # MP6
A = S // (T*2) # MP7
print(C, D, A) # MP8
import random
C = 0 #
D = 0 #
S = 0 #
T = 0 # MP1
while C < 3 and D < 3: # MP2
T += 1 #
N1 = random.randint(1,6) #
N2 = random.randint(1,6) # MP3
print N1, N2 #
S = S + N1 + N2 # MP4
if N1 == 6 or N2 == 6: #
C += 1 # MP5
if N1 == N2: #
D += 1 # MP6
A = S // (T*2) # MP7
print C, D, A # MP8
Pascal
uses SysUtils;
var A, C, D, S, T, N1, N2: integer;
begin
C := 0; //
D := 0; //
S := 0; //
T := 0; // MP1
while (C < 3) and (D < 3) do // MP2
begin
T := T + 1; //
N1 := random(6) + 1; //
N2 := random(6) + 1; // MP3
writeln(N1, N2); //
S := S + N1 + N2; // MP4
if (N1 = 6) or (N2 = 6) then //
C := C + 1; // MP5
if N1 = N2 then //
D := D + 1; // MP6
end;
A := S div (T*2); // MP7
writeln(C, D, A); // MP8
readln;
end.
Java
As this output is from a random number generator, the output from candidates will not
be the values below. However:
Output should show two digits between 1 and 6 on each line except the final line.
On the final line it should show the correct number of lines containing at least one 6,
number of doubles and another integer.
Number of lines containing at least one 6 and/or number of doubles must be 3
I. missing spaces
A. each digit on a new line
1
[9]
Max 1
Max 2
3
[4]
Max 2
[2]
Max 2
[2]
LoadPuzzleFile – file does not exist // index error if more lines in file than Puzzle can
accommodate;
LoadSolution – file does not exist // not enough lines in file;
TransferPuzzleIntoGrid – input conversion error // index error if string length < 3;
LoadPartSolvedPuzzle – file does not exist // index error if more lines in file than
Answer can accommodate;
SolvePuzzle – row/column/1st character/2nd character entered not a digit/number/integer //
input conversion error;
Max 2
[2]
A. subroutine is used to give a block of code a name (and this name can be used to
execute this group of statements)
[1]
MAX 1
[1]
(a) ResetDataStructures
(b) LoadPuzzleFile
(c) LoadSolution
(d) TransferPuzzleIntoGrid
1. Loop structure;
2. Check through each element of Puzzle // check Puzzle until end of entries
reached // check until a protected cell is found;
3. Compare first two characters of CellInfo with first two characters of Puzzle
line // compare the string values of Row and Column with the first two characters
of the Puzzle line;
4. Ifprotected cell found …;
4. If protected cell found …;
5. … give appropriate error message to user A. ‘Invalid input’ also being output;
6. Only if it is not a protected cell update content of cell; DPT. Incorrect
identification of a protected cell
7. Code in correct place in SolvePuzzle;
Python 3
displayGrid(puzzleGrid);
}
}
Console.writeLine("Enter row column digit: ");
Console.writeLine("(Press Enter to stop)");
cellInfo = Console.readLine();
}
}
}
7
(a) 2 marks for AO3 (design) and 6 marks for AO3 (programming)
30.
Marking guidance:
Note: AO3 (design) points are for selecting appropriate techniques to use to solve
the problem, so should be credited whether the syntax of programming language
statements is correct or not and regardless of whether the solution works.
VB.Net
Python 3
Python 2
Java
(a) 3 marks for AO3 (design) and 9 marks for AO3 (programming)
31.
Level Description Mark
Range
Note: AO3 (design) points are for selecting appropriate techniques to use to solve
the problem, so should be credited whether the syntax of programming language
statements is correct or not and regardless of whether the solution works.
VB.Net
Python 3
Alternative solution
Python 2
C#
1
[13]
0 0 -
4 4
6 10
3 13
2 15
−1 14 14
The result is wrong // The sentinel value should not have been used in the
calculation; Subtract the last value // input first value before the WHILE loop and swap
the instructions within the WHILE loop // add 1 to result after loop is finished;
Note to examiners
If a language allows variables to be used without explicit declaration (eg
Python) then this mark should be awarded if the correct variables exist in
the program code and the first value they are assigned is of the correct
data type.
VB.Net
Dim X As Integer '
Dim Product As Integer '
Dim Factor As Integer '1
Console.Write("Enter an integer greater than 1: ") '
X = Console.ReadLine '2
Product = 1 '
Factor = 0 '3
While Product < X '4
Factor += 1 '
Product *= Factor '5
End While
If X = Product Then '6
Product = 1 '7
For N = 1 To Factor '8
Product = Product * N '
Console.WriteLine(N) '9
Next
Else
Console.WriteLine("No result")
End If
Python 2
# X, Product, Factor are integers # 1
print "Enter an integer greater than 1: " #
X = int(raw_input()) # 2
Product = 1 #
Factor = 0 # 3
while Product < X: # 4
Factor += 1 #
Product = Product * Factor # 5
if X == Product: # 6
Product = 1 # 7
for N in range(1, Factor + 1): # 8
Product = Product * N #
print N # 9
else:
print "No result"
C#
int x, product, factor; // 1
Console.Write("Enter an integer greater than 1: "); //
x = Convert.ToInt32(Console.ReadLine()); // 2
product = 1; //
factor = 0; // 3
while (product < x) // 4
{
factor++; //
product = product * factor; // 5
}
if (x == product) // 6
{
product = 1; // 7
for (int n = 1; n < factor + 1; n++) // 8
{
product = product * n; //
Console.WriteLine(n); // 9
}
}
else
{
Console.WriteLine("No result");
}
Console.ReadLine();
ConvertChar //
GetMenuOption (Python only);
EditImage;
A. since the name is uppercase this tells the programmer not to alter it. (Python only)
Max 1
1
(These are the maximum dimensions and) may be changed easily if the program
requirements change // a change would only need to be made in one place; It is
easier to read/understand than the actual values;
The value cannot be accidentally changed elsewhere in the code (Do NOT accept
for Python);
A. since the name is uppercase this tells the programmer not to alter it. (Python only)
R. if answer is the same as (a)
Max 1
1
[2]
Max 2
[2]
Max 1
1
A subroutine/procedure/function/method; A. module
1
ConvertChar;
Max 1
1
Max 3
3
[4]
Max 2
2
Max 2
2
The lower part of the picture will not be displayed/loaded // only the upper part of the
picture will be displayed/loaded;
Only the top 10 rows are displayed/loaded // the bottom 49 rows are not
displayed/loaded // only the cat’s head is displayed/loaded // the cat’s body has been
removed;
Max 2
2
[6]
(a) 1 mark for AO3 (design) and 5 marks for AO3 (programming)
43.
Mark as follows:
Sub DisplayMenu()
Console.WriteLine()
Console.WriteLine("Main Menu")
Console.WriteLine("=========")
Console.WriteLine("L - Load graphics file")
Console.WriteLine("D - Display image")
Console.WriteLine("E - Edit image")
Console.WriteLine("S - Save image")
Console.WriteLine("X - Exit program")
Console.WriteLine("M - Mirror image") '5
End Sub
Sub Graphics()
Dim MenuOption As Char
Dim Grid(MAX_WIDTH - 1, MAX_HEIGHT - 1) As String
ClearGrid(Grid)
Dim Header As FileHeader
SetHeader(Header)
Dim ProgramEnd As Boolean = False
While Not ProgramEnd
DisplayMenu()
MenuOption = GetMenuOption()
If MenuOption = "L" Then
LoadFile(Grid, Header)
ElseIf MenuOption = "D" Then
DisplayImage(Grid, Header)
ElseIf MenuOption = "E" Then
Grid = EditImage(Grid, Header)
ElseIf MenuOption = "S" Then
SaveImage(Grid, Header)
ElseIf MenuOption = "X" Then
ProgramEnd = True
ElseIf MenuOption = "M" Then
MirrorImage(Grid, Header) '6
Else
Console.WriteLine("You did not choose a valid menu option. Try
again")
End If
End While
Console.WriteLine("You have chosen to exit the program")
Console.Write("Do you want to save the image as a graphics file? (Y/N)
")
Dim Answer As String = Console.ReadLine()
If Answer = "Y" Or Answer = "y" Then
SaveFile(Grid, Header)
End If
End Sub
Python 3
def MirrorImage(Grid, Header): # 2
NewGrid = [[EMPTY_STRING for Column in range(MAX_WIDTH)] for Row in
range(MAX_HEIGHT)]
NewGrid = ClearGrid(NewGrid) # 1
for ThisRow in range(Header.Height): #
for NewColumn in range(Header.Width): # 4
NewGrid[ThisRow][NewColumn] = Grid[ThisRow][Header.Width -NewColumn
- 1] # 3
DisplayImage(NewGrid, Header)
def DisplayMenu():
print()
print("Main Menu")
print("=========")
print("L - Load graphics file")
print("D - Display image")
print("E - Edit image")
print("S - Save image")
print("M - Mirror image") # 5
print("X - Exit program")
print()
Python 2
def MirrorImage(Grid, Header): # 2
NewGrid = [[EMPTY_STRING for Column in range(MAX_WIDTH)] for Row in
range(MAX_HEIGHT)]
NewGrid = ClearGrid(NewGrid) # 1
for ThisRow in range(Header.Height):
for NewColumn in range(Header.Width): # 4
NewGrid[ThisRow][NewColumn] = Grid[ThisRow][Header.Width -NewColumn
- 1] # 3
DisplayImage(NewGrid, Header)
def DisplayMenu():
print
print "Main Menu"
print "========="
print "L - Load graphics file"
print "D - Display image"
print "E - Edit image"
print "S - Save image"
print "M - Mirror image" # 5
print "X - Exit program"
print
Pascal
procedure MirrorImage(var Grid: TGrid; Header: FileHeader); // 2
var
NewGrid: TGrid;
ThisRow, NewColumn: integer;
begin
ClearGrid(NewGrid); // 1
for ThisRow := 0 to Header.Height - 1 do
for NewColumn := 0 to Header.Width - 1 do // 4
NewGrid[ThisRow, NewColumn] := Grid[ThisRow, Header.Width -
NewColumn - 1]; // 3
DisplayImage(NewGrid, Header) ;
Grid := NewGrid;
end;
procedure DisplayMenu();
begin
writeln;
writeln('Main Menu');
writeln('=========');
writeln('L - Load graphics file');
writeln('D - Display image');
writeln('E - Edit image');
writeln('S - Save image');
writeln('M - Mirror image'); // 5
writeln('X - Exit program');
writeln;
end;
void displayMenu() {
Console.writeLine();
Console.writeLine("Main Menu");
Console.writeLine("=========");
Console.writeLine("L - Load graphics file");
Console.writeLine("D - Display image");
Console.writeLine("M - Mirror image"); // 5
Console.writeLine("E - Edit image");
Console.writeLine("S - Save image");
Console.writeLine("X - Exit program");
Console.writeLine();
}
void graphics() {
String[][] grid = new String[MAX_HEIGHT][MAX_WIDTH];
clearGrid(grid);
FileHeader header = new FileHeader();
boolean programEnd = false;
while (!programEnd) {
displayMenu();
char menuOption = GetMenuOption();
if ( menuOption == 'L') {
loadFile(grid, header);
} else if ( menuOption == 'D') {
displayImage(grid, header);
} else if (menuOption == 'M') {
mirrorImage(grid, header); // 6
} else if ( menuOption == 'E') {
editImage(grid, header);
} else if ( menuOption == 'S') {
saveImage(grid, header);
} else if ( menuOption == 'X') {
programEnd = true;
} else {
Console.writeLine("You did not choose a valid menu option.
Try again");
}
}
Console.writeLine("You have chosen to exit the program");
Console.write("Do you want to save the image as a graphics file?
(Y/N) ");
String answer = Console.readLine();
if ( answer.equals("Y") || answer.equals("y")) {
saveFile(grid, header);
}
}
Main Menu
=========
L - Load graphics file
D - Display image
E - Edit image
S - Save image
M - Mirror image
X - Exit program
Cat
===
1
[7]
Marking guidance:
Note: AO3 (design) points are for selecting appropriate techniques to use to solve
the problem, so should be credited whether the syntax of programming language
statements is correct or not and regardless of whether the solution works.
Python 2
def FindSecretChar(PixelValue, Key): # 4
Character = '_' # 5
NewValue = PixelValue - Key
if NewValue == 0:
Character = ' ' # 6
elif NewValue in range(1, 27): # 1
Character = chr(ord('A') + NewValue - 1) # 2
return Character
TestImage2
==========
##&#.
&:#+&
####
Marking guidance:
Note: AO3 (design) points are for selecting appropriate techniques to use to solve
the problem, so should be credited whether the syntax of programming language
statements is correct or not and regardless of whether the solution works.
VB.Net
Sub CompressFile()
Console.Write("Enter the filename containing the data to compress: ")
Dim FileName As String = Console.ReadLine '4
Dim FileIn As StreamReader = New StreamReader(FileName) '5
Dim HeaderLine As String = FileIn.ReadLine()
Dim Fields() As String = HeaderLine.Split(",")
Dim Header As FileHeader
Header.Title = Fields(0)
Header.Width = CInt(Fields(1))
Header.Height = CInt(Fields(2))
Header.FileType = "C" '6
Dim FileData As String = FileIn.ReadLine()
FileIn.Close()
Dim FileOut As StreamWriter = New StreamWriter("CMP" & FileName) '1, 5
FileOut.WriteLine(Header.Title + "," + CStr(Header.Width) + "," +
CStr(Header.Height) + "," + Header.FileType) '2
Dim Count As Integer = 1 '7
Dim LastChar As Char = FileData(0)
For Pos = 1 To FileData.Length – 1 '8
If FileData(Pos) = LastChar Then '2
Count += 1 '3
Else
FileOut.WriteLine(CStr(Count) + "," + LastChar) '9, 10
Count = 1 '12
LastChar = FileData(Pos)
End If
Next
FileOut.WriteLine(CStr(Count) + "," + LastChar) '11
FileOut.Close()
End Sub
1
[13]
Reason:
memory allocated to local variables can be reused when subroutine not in use;
local variable only exists while the program block/subroutine is executing;
using local variables makes subroutines self-contained;
A. prevents accidental changes;
A. easier debugging/maintenance;
Max 2
[3]
Note to examiners
If a language allows variables to be used without explicit declaration (eg
Python) then this mark should be awarded if the correct variables exist in
the program code and the first value they are assigned is of the correct
data type.
Python 3
Python 2
Pascal
var
NumberIn, NumberOut, Count, PartValue, i: integer;
begin
write('Enter a positive whole number: ');
readln(NumberIn);
NumberOut := 0;
Count := 0;
while NumberIn > 0 do
C#
Java
/ValidMove
/ValidJump
/ListEmpty;
PrintResult;
PrintLine;
A. PrintRow / PrintMiddleRow;
Max 1
R. if any additional code
R. if spelt incorrectly
I. case & spacing
1
[3]
Note:
Messages such as “Error Code 1 – not valid” are not detailed enough and
are not creditworthy.
VB.net
def DisplayErrorCode(ErrorNumber):
print('Error Code ', ErrorNumber, ' - ', end='')
if ErrorNumber == 1:
print('not a valid piece')
elif ErrorNumber == 2:
print('not a valid move')
elif ErrorNumber == 3:
print('not a number')
elif ErrorNumber == 4:
print('file error')
Python 2
def DisplayErrorCode(ErrorNumber):
print 'Error Code ', ErrorNumber
if ErrorNumber == 1:
print 'not a valid piece'
elif ErrorNumber == 2:
print 'not a valid move'
elif ErrorNumber == 3:
print 'not a number'
elif ErrorNumber == 4:
print 'file error'
Pascal
C#
Java
(b) (i) 1 mark for AO3 (design) and 1 mark for AO3 (programming)
Mark as follows:
VB.net
Python 3
Python 2
Pascal
C#
Java
Mark
Level Description
Range
Marking guidance:
Python 3
def CountNumberOfPieces(PlayersPieces):
Count = 0
for Index in range(1, NUMBER_OF_PIECES + 1):
if PlayersPieces[Index][ROW] > -1:
# allow COLUMN instead of ROW
Count += 1
return Count
def CountNumberOfPieces(PlayersPieces):
Count = 0
for Index in range(1, NUMBER_OF_PIECES + 1):
if PlayersPieces[Index][ROW] > -1:
# allow COLUMN instead of ROW
Count += 1
return Count
def PrintResult(A, B, NextPlayer):
print 'Game ended'
TotalA = CountNumberOfPieces(A)
TotalB = CountNumberOfPieces(B)
TotalA = A[0][0] - TotalA - 10 * A[0][1]
TotalB = B[0][0] - TotalB - 10 * B[0][1]
if TotalA < TotalB:
print 'A won this game with a score of ', TotalA
print 'B got a score of ', TotalB
elif TotalB < TotalA:
print 'B won this game with a score of ', TotalB
print 'A got a score of ', TotalA
else:
print 'it was a draw. Both players got a score of ', TotalA
PrintPlayerPieces(A, B)
Pascal
C#
Java
Next Player: a
There are 0 possible moves
Game ended
A won this game with a score of -17
B got a score of 3
1
OpponentsPieces;
Mark
Level Description
Range
Marking guidance:
A. solutions that ask the user to input the row and column of the piece to be removed.
Python 3
Python 2
Pascal
C#
Java
Next Player: a
a1 can move to 1 , 0
a1 can move to 1 , 2
a2 can move to 7 , 0
a3 can move to 3 , 6
a5 can move to 4 , 3
a7 can move to 3 , 4
a7 can move to 3 , 6
a8 can jump to 3 , 4
There are 8 possible moves
Which piece do you want to move? a2
Which row do you want to move to? 7
Which column do you want to move to? 0
Which piece do you want to take? b1
1
[29]
5 1
2 False 1
3 2
4 Prime
25 1
5 2 False 1
3 1
4 1
5 0
True
6 Not prime
Note to examiners
If a language allows variables to be used without explicit declaration (eg
Python) then this mark should be awarded if the correct variables exist in the
program code and the first value they are assigned is of the correct data type.
2. WHILE loop with syntax allowed by the programming language and one correct
condition for termination of the loop;
3. second correct condition for while loop;
4. correct prompt "Enter a positive whole number: " and Number assigned
value entered by user;
5. correct syntax for the IF statements inside attempt at loop;
A. IF … ELSEIF;
6. correct contents in IF statements;
7. FOR loop with syntax allowed by the programming language over correct range;
8. correct assignment to c inside FOR loop;
9. output statement giving correct output; A. accept without spaces
VB.NET
Sub Main()
Dim Number As Integer
Dim c As Integer
Number = 0
While Number < 1 Or Number > 10
Console.Write("Enter a positive whole number: ")
Number = Console.ReadLine
If Number > 10 Then
Console.WriteLine("Number too large")
Else
If Number < 1 Then
Console.WriteLine("Not a positive number.")
End If
End If
End While
c = 1
For k = 0 To Number - 1
Console.WriteLine(c)
c = (c * (Number - 1 - k)) \ (k + 1)
Next
Console.ReadLine()
End Sub
Python 3
Number = 0
while Number < 1 or Number > 10:
Number = int(input("Enter a positive whole number: "))
if Number > 10:
print("Number too large")
elif Number < 1:
print ("Not a positive number")
c = 1
for k in range(Number):
print c
c = (c * (Number - 1 - k)) // (k + 1)
Pascal
var
Number, c, k : Integer;
begin
Number := 0;
while (Number < 1) or (Number > 10) do
begin
write('Enter a positive whole number: ');
readln(Number);
if Number > 10 then
writeln('Number too large')
else
if Number < 1 then
writeln('Not a positive number.')
end;
c := 1;
for k := 0 to (Number - 1) do
begin
writeln(c);
c := (c * (Number - 1 - k)) div (k + 1);
end;
readln;
end.
Java
int number = 0;
while (number < 1 || number > 10)
{
Console.writeLine(("Enter a positive whole number: "));
number = Integer.parseInt(Console.readLine());
if (number > 10)
{
Console.writeLine("Number too large");
}
else if (number < 1)
{
Console.writeLine("Not a positive number");
}
}
int c = 1;
for (int k = 0; k < number; k++)
{
Console.write(c + " ");
c = (c * (number - 1 - k) / (k + 1));
}
>
A. Alternative layout :
Enter a positive whole number: -3
Not a positive number.
Enter a positive whole number: 11
Number too large.
Enter a positive whole number: 10
1
9
36
84
126
126
84
36
9
1
>
This question required students to describe a difference between a global and a local variable,
2. and fewer than half of students succeeded in providing a description that secured both marks.
Although there was an understanding that the scope of a local variable is more limited, this was
often phrased too vaguely to be fully creditworthy.
Converting pseudocode to program code was carried out successfully by most students, with
3. approximately ninety percent of students picking up either full marks or eight out of nine on part
(a). The most common way in which a mark was dropped was reversing the logic of the selection
statement.
Where the code was sound, the evidence mark of part (b) was almost always awarded. Students
are reminded of the importance of ensuring that screenshot evidence is legible in all such
questions.
For each of the four question parts, most students gained the mark. Here, students were required
4. to identify a variable and three subroutines. The most common way in which marks could not be
awarded was by the inclusion of additional code, such as parentheses alongside subroutine
identifiers.
For both question parts, most students gained the mark. As this question related to data
5. structures rather than subroutines, additional code was less frequently included here.
This question continued to examine students’ understanding of the error codes within the
7. skeleton program, and the majority were awarded both marks on offer. In circumstances where
one mark was obtained but two points had been made, there was often a re-phrasing of the first
point in an attempt to pick up the second mark.
This question comprised three parts, each of which asked about some aspect of the same
8. subroutine. In previous exams, this might have been presented as a single six mark question
rather than a series of related three-mark questions, and in such questions the scale of the
required answer presented a challenge to some students.
This format provided some structure, and most student marks were concentrated between two
and five out of six. Where marks were not awarded, it was quite common for an otherwise
creditworthy answer to be placed next to the wrong question. This suggests that marks were lost
due to a misunderstanding of the question rather than a misunderstanding of the code.
Where a mark was dropped in an otherwise correct response, it was that awarded for updating
the status register, which was missed out rather than being attempted incorrectly.
This question required addition of validation code; the requirement was that any specified line
10. number should exist within the assembly program. Although the lower bound was generally
correct, since it would always be 1, the upper bound was commonly hard-coded rather than
determined using a variable. Since the length of the assembly program could vary, hard-coding
was not enough for the mark.
Approximately half of the students secured either full marks or four out of five for part (a),
although very few students were awarded two or three marks. That indicates that this question
marks the beginning of the stage in which individual programming marks were cherry-picked due
to constraints of time or understanding.
There were two components to this question – adding the facility to insert an instruction and the
12. facility to remove one. As is often the case with the last question on the paper, there were many
partial attempts, and this question lent itself to such attempts. Some students attempted to write
code for insertion only, and others for deletion only. Only a minority of those who made any
attempt at all were awarded zero marks for part (a), with students securing marks for modifying
the menu and handling the new inputs even if they did not complete the task.
Parts (b) and (c) required screenshot evidence for a successful deletion and insertion
respectively. Given that a large number of students had only attempted one of these two pieces
of functionality, a high number of non-attempts were registered. Nevertheless, the majority of
students who made a partial attempt at part (a) also attempted the corresponding screenshot
evidence question.
Most students were able to secure either four or five marks on the trace table question. Where
13. students secured four marks, the mark that was dropped was the final mark. This required the
result of the algorithm to be given.
This question was completed well by students with the majority of students achieved a high
14. mark. The most common mistake was related to the requirement to generate a random integer
between 1 and 6 inclusive. Some students were unable to write the correct syntax for random
integer generation. Others wrote syntactically-correct code that produced an integer in the wrong
range, such as between 0 and 6 inclusive.
Where students were unfamiliar with the syntax for random integer generation, subsequent
marks were still secured. Commonly, variables were used to store integers that were not
randomly generated, but these variables were subsequently processed correctly. This enabled
students to demonstrate their programming abilities in spite of an early error or omission.
Many students secured both marks for this question, with only twenty-seven percent failing to
19. pick up any marks.
The question required changes to be described that would apply to a single subroutine of the
skeleton program. Some students, in describing changes outside this subroutine, dropped a
mark. Others described the same change in two different ways and only gained one mark.
Many students failed to secure full marks in this question, with responses that were insufficiently
20. specific rather than incorrect. The most common way in which a mark was dropped was to
correctly define definite iteration, and then to present indefinite iteration as the opposite of
definite iteration. Where a mark is available for providing a definition, a standalone definition
should be provided.
This question required students to identify subroutines that contained examples of definite and
21. indefinite iteration. The majority of students secured this mark.
This question required students to identify subroutines that contained examples of definite and
22. indefinite iteration. The majority of students secured this mark.
Most students secured the first mark of this question by identifying that an exception stops a
23. program from crashing. Many fewer students recognised that exception handling is relevant to
run time errors. 'Errors', in isolation, did not demonstrate a sufficient level of understanding.
The majority of students were able to identify a subroutine that performed exception handling, as
24. required by this question. Of those who correctly identified the subroutine, most were able to
identify a relevant circumstance that might cause an exception.
The most common reason for dropping a mark on this question was to give more than just the
subroutine's name. For example, LoadPuzzleFile was creditworthy, whereas def
LoadPuzzleFile or LoadPuzzleFile(PuzzleName, Puzzle) was not.
Many students dropped the mark on this question by providing an incomplete answer. Only a
25. very small number of answers were incorrect, but many more were incomplete. Stating only that
a subroutine is a named section of code was insufficient on its own, and was a commonly-given
answer.
Both marks of this question were secured by the majority of students. The most common reason
28. for dropped marks was giving more than just the subroutine’s name. For example,
ResetDataStructures was creditworthy, whereas ResetDataStructures() was not.
This question was the first that required changes to be made to the skeleton code. On the whole,
29. responses to this question were of a good quality, with most students securing most marks.
The most commonly dropped mark related to the requirement for new code to be at an
appropriate place within the subroutine. Validation had already been included to check that inputs
could be converted to integers. The new code, checking whether those integers related to
protected coordinates, should have been added after this validation code.
This question required additional validation to be added to the skeleton code. A value should not
30. be permitted in a cell if it already exists in the same row, column, or sub-grid. Most students
secured some marks on this question, but only a minority picked up all six. The marks relating to
the sub-grid were secured by fewer students than the marks relating to the row and column.
Determining whether a value already existed within the same row or column was a relatively
straightforward task. This could be accomplished using two simple loops. The most common way
of checking a sub-grid required a combination of the modulo operator and nested loops. Other
students opted for a nine-part selection structure, which was equally creditworthy.
This question required the addition of 'undo' functionality to the skeleton code. Design marks
31. were applicable to this question, so syntactically incorrect code could be credited. The majority of
students secured at least two of the three design marks.
Most students created the subroutine correctly, and were able to make a valid call to it from
elsewhere in the code. Beyond this, the majority of students conformed to one of two groups.
One group gained no further marks, and the other group secured all or most of the remaining
marks.
Marks dropped by more able students included replacement of a number with an empty string
rather than a space. Another common error was assuming that the number of 'undo' moves
would always be a single digit value. Were the user to enter -10, indicating ten 'undo' moves, this
would result in one 'undo' and an ignored zero.
Many vague answers were given for the difference between local and global variables.
47. Regardless of how the student’s chosen programming language requires local / global variables
to be declared, students need to be aware that a global variable is accessible to all parts of the
program, whereas a local variable is accessible only in the program block in which it was
declared. Many students’ answers were very vague as to the reasons for using local variables.
Some were able to state that memory used to store local variables is released when the
subroutine terminates, but very few mentioned that local variables make a subroutine
self-contained and therefore it is easier to re-use such subroutines in other programs.
Most students completed the testing section well and provided clear screenshots of their code
working.
The majority of students recognised that the algorithm produced binary but, to gain the mark,
they needed to state that the conversion was from decimal to binary.
The majority of students secured both of the marks for this question. A few students copied
49. across more than just the identifier for each part and therefore did not gain the mark as it was not
clear which part of the copied code they believed the identifier to be.
Less able students stated that it was the player’s pieces that would be contained in the
52. parameter. To earn this mark, a reference to the positions of player A’s pieces was required.
Very few responses provided clear explanations of what happens in the WHILE loop in
55. SelectMove. Many descriptions merely reworded the programming steps. An example of an
explanation gaining high marks was:
The user is asked to enter a Piece ID. The list of moves is searched sequentially for an
occurrence of the Piece ID entered until either the Piece ID is found or the end of ListOfMoves is
encountered. If the end of the list is encountered the user is asked again to enter the Piece ID.
(a) Task 1 required meaningful error messages to be displayed as well as the error code.
56.
Most students used either a series of IF statements or a CASE statement. Some responses
used a dictionary or a tuple. All these methods were given credit. However, meaningful
error messages were required. In particular, error code 3 needed to inform the user that a
number was required as input.
The majority of students made the small change to the final IF statement from checking the
middle piece did not belong to the opponent to checking that it was the opponent’s. A
common mistake was to change the assignment of OppositePiecePlayer to be the same
as Player. This may result in jumping over the opponent’s piece, but it is poor
programming practice as it removes transparency of code. Player and
OppositePiecePlayer should never be the same value.
(c) Task 1 required the writing of a new subroutine to count the number of pieces a player had
on the board.
The majority of students produced sensible code for this task and credit was given for
designing the subroutine so that it could be called either with A or with B without duplicating
code. Some responses counted the pieces on the board rather than in the data structures A
and B. Both methods were given credit.
Task 2 required rewriting the PrintResult subroutine to output the winner and scores
using the amended rules.
The formula was given in the question but many students did not make use of the values
held in the A and B data structures for number of moves made and number of dames held.
A common error was to assume that the highest score wins, contrary to the information
given in the question. Some students did not output the scores or consider the possibility of
a draw. Both requirements were stated in the question.
(d) This question changed the rules of the game and allowed the player to take an opponent’s
piece. Some students were able to analyse the new requirements and that the
OpponentsPieces data structure now needed to be passed to the MoveDame subroutine, as
changes to this data structure now needed to be made.
Many students secured some marks on this question. A common omission was not
checking that the piece to be removed was an opponent’s existing piece. Another common
error was to fail to update the opponent’s data structure with - 1 values in place of the
co-ordinates.
Some students struggled to complete the trace tables. The question clearly stated that the
58. pseudo-code described a method to test whether an integer is prime or not, yet some answers to
part a left the trace table showing that 5 was not prime, and some answers to part b left the trace
table showing that 25 was prime. Using a trace table to show how values change while iterating
through a loop needs practice. Many answers indicated little understanding of repeatedly
applying code until the condition(s) terminate the loop. Pseudo-code clearly shows what code is
part of a loop by ending with ENDWHILE or ENDFOR. Similarly, IF statements terminate with ENDIF.
Indentation is also used to help students see the logical flow of statements.
The majority of students secured both of the marks for this question. A few students copied
60. across more than just the identifier for each part and therefore did not gain the mark as it was not
clear which part of the copied code they believed the identifier to be.