Unit 1, 2015, QP
Unit 1, 2015, QP
Computing COMP1
Unit 1 Problem Solving, Programming, Data Representation and Practical Exercise
Monday 1 June 2015 9.00 am to 11.00 am
Time allowed
2 hours
Instructions
Type the information required on the front of your Electronic Answer Document.
Enter your answers into the Electronic Answer Document.
Answer all questions.
You will need access to:
– a computer
– a printer
– appropriate software
– an electronic version of the Skeleton Program
– a hard copy of the Preliminary Material.
Before the start of the examination make sure your Centre Number, Candidate Name and
Candidate Number are shown clearly in the footer of every page of your Electronic Answer
Document (not the front cover).
Information
The marks for questions are shown in brackets.
The maximum mark for this paper is 100.
No extra time is allowed for printing and collating.
The question paper is divided into four sections.
You are advised to spend time on each section as follows:
Section A – 35 minutes
Section B – 15 minutes
Section C – 10 minutes
Section D – 60 minutes.
At the end of the examination
Tie together all your printed Electronic Answer Document pages and hand them to the invigilator.
Warning
It may not be possible to issue a result for this unit if your details are not on every page of your
Electronic Answer Document.
M/SEM/109508/Jun15/E4 COMP1
2
Section A
Question 1
Use the space below for rough working, then copy the answer to your Electronic Answer
Document.
[1 mark]
Use the space below for rough working, then copy the answer to your Electronic Answer
Document.
[1 mark]
0 3 Why are bit patterns often displayed using hexadecimal instead of binary?
[1 mark]
0 4 Represent the denary number -59 as an 8-bit two’s complement binary integer.
Use the space below for rough working, then copy the answer to your Electronic Answer
Document.
[2 marks]
M/Jun15/COMP1
3
0 5 Represent the denary number 5.625 as an unsigned binary fixed point number with
three bits before and five bits after the binary point.
Use the space below for rough working, then copy the answer to your Electronic Answer
Document.
[2 marks]
The ASCII system uses 7 bits to represent a character. The ASCII code in denary for
the numeric character ‘0’ is 48; other numeric characters follow on from this in sequence.
The numeric character ‘0’ is represented using 7 bits as 0110000.
0 6 Using 7 bits, express the ASCII code for the character '6' in binary.
[1 mark]
0 7 How many different character codes can be represented using 7-bit ASCII?
Use the space below for rough working, then copy the answer to your Electronic Answer
Document.
[1 mark]
Examples of logical bitwise operators include AND, OR, NOT and XOR.
0 8 Describe how one of these logical bitwise operators can be used to convert the 7-bit
ASCII code for a numeric character into a 7-bit pure binary representation of the number,
(eg 0110001 for the numeric character '1' would be converted to 0000001).
[2 marks]
Turn over
M/Jun15/COMP1
4
Characters are transmitted using an 8-bit code that includes the 7-bit ASCII code and a
single parity bit in the most significant bit. A parity bit is added for error checking during
data transmission.
0 9 Using even parity, what 8-bit code is sent for the numeric character '0'?
[1 mark]
Hamming code is an alternative to the use of a single parity bit. Hamming code
uses multiple parity bits - this allows it to correct some errors that can occur during
transmission.
The parity bits are located in the power of two bit positions (1, 2, 4, 8, etc.). The other
bit positions are used for the data bits.
1 0 Describe how the receiver can detect and correct a single-bit error using Hamming code.
[4 marks]
Figure 1 shows the bit pattern received in a communication that is using even parity
Hamming code. The data bits received are 1101000.
Figure 1
Bit position 11 10 9 8 7 6 5 4 3 2 1
Bit 1 1 0 0 1 0 0 0 0 0 1
1 1 Which bit position from the bit pattern in Figure 1 contains an error?
Use the space below for rough working, then copy the answer to your Electronic Answer
Document.
[1 mark]
M/Jun15/COMP1
5
Figure 2 shows a Finite State Machine (FSM) represented as a state transition diagram.
The machine takes a bit pattern as an input. The bit pattern is considered to be valid
if the machine ends up in the accepting state Sx. The bit patterns 0111000 and
0110001 are valid; the bit patterns 010011 and 01110111 are not valid. Bit patterns
are processed starting with the left-most bit.
Figure 2
0 or 1
Sx
0 or 1
Si 0 or 1
Sa 0 or 1 0
1 Sj
0 1 Sg
Sy
0
0 or 1
Sb 1 0
0
1 Se Sh
Sc 1
1 0 or 1
Sd 0
Sf
1 2 Is the bit pattern 0111010 a valid input for the FSM shown in Figure 2?
[1 mark]
1 3 A finite state machine can also be represented as a state transition table. Table 1
shows part of the state transition table that represents the finite state machine shown in
Figure 2. The state transition table is only partially complete.
Table 1
Sg 1
Sy
Sy
Copy the contents of all the unshaded cells in Table 1 into the Electronic Answer
Document.
[2 marks]
Turn over
M/Jun15/COMP1
6
1 5 The state Si in the FSM shown in Figure 2 is not necessary and is going to be removed
from the FSM.
Describe the change that needs to be made so that state Si can be removed without
changing the functionality of the FSM.
[1 mark]
Question 2 Images are often represented in a computer’s memory using vector graphics.
A vector graphic consists of a collection of objects.
1 6 State three items of data that would need to be stored about a circle object if it is to be
represented using vector graphics.
[3 marks]
M/Jun15/COMP1
7
The function Len takes a string, S, and returns an integer value that is the number
of characters in the string S, eg
The function GetChar takes a string, S, and an integer value, n, and returns the
character that is in the nth position in the string S, eg
The function Concat takes two strings, S1 and S2, and returns a string that is the
string S1 followed by the string S2, eg
Figure 3
INPUT IStr
OStr ""
Count 1
WHILE Count <= Len(IStr) DO
OStr Concat(GetChar(IStr, Count), OStr)
Count Count + 1
ENDWHILE
1 9 Dry run the algorithm shown in Figure 3 by completing Table 2 for when the user enters
the string "Lou". The first row has been done for you.
Copy the cells in Table 2 that contain your answer into the Electronic Answer Document.
Table 2
[5 marks]
Turn over
M/Jun15/COMP1
8
Section B
The question in this section asks you to write program code starting from a new
program/project/file.
The algorithm, represented using pseudo-code in Figure 4, and the variable table,
Table 3, describe a program that calculates and displays all of the prime numbers
between 2 and 50, inclusive.
The MOD operator calculates the remainder resulting from an integer division
eg 10 MOD 3 = 1.
If you are unsure how to use the MOD operator in the programming language you
are using, there are examples of it being used in the Skeleton Program.
Figure 4
M/Jun15/COMP1
9
Table 3
2 1 SCREEN CAPTURE(S) for the test showing the correct working of the program.
[1 mark]
2 2 Describe the changes that would need to be made to the algorithm shown in Figure 4,
so that instead of displaying the prime numbers between 2 and 50, inclusive, it displays
all the prime numbers between 2 and a value input by the user, inclusive.
[3 marks]
Turn over
M/Jun15/COMP1
10
Section C
These questions refer to the Preliminary Material and require you to load the Skeleton Program,
but do not require any additional programming.
Refer either to the Preliminary Material issued with this question paper or your electronic copy.
2 3 a named constant
[1 mark]
2 6 Describe how this subroutine could be rewritten so that instead of there being three lines
of code that change the value in the start square, there could be just one line of code
that does this. The functionality of the MakeMove subroutine should not be altered by
the changes you describe.
[1 mark]
M/Jun15/COMP1
11
Table 4
Conditions >= 97 Y N Y Y
<= 123 N Y N Y
Explain why this decision table is not an accurate representation of the logic of this
selection structure.
[3 marks]
Turn over
M/Jun15/COMP1
12
Section D
These questions require you to load the Skeleton Program and make programming changes to it.
Question 6 This question refers to the MAIN PROGRAM BLOCK and will extend the
functionality of the Skeleton Program.
The number of moves made by the players in a game of CAPTURE THE SARRUM
will be tracked. A variable called NoOfMoves will be used to store the number of
moves completed by the players. At the start of every game NoOfMoves should
be set to an initial value of zero.
Each time a player enters a legal move 1 should be added to the value stored in
NoOfMoves.
After the call to the MakeMove subroutine, the NoOfMoves variable should be
updated and then a message should be displayed saying "The number of
moves completed so far: n" – where n is the value of NoOfMoves.
2 9 Your PROGRAM SOURCE CODE for the amended MAIN PROGRAM BLOCK.
[4 marks]
M/Jun15/COMP1
13
When the user has entered the start square and the finish square for their move, a
number of checks are made to see if their intended move is legal.
3 2 SCREEN CAPTURE(S) showing the requested test. You must make sure that
evidence for all parts of the requested test by the user is provided in the SCREEN
CAPTURE(S).
[3 marks]
Turn over
M/Jun15/COMP1
14
A kashshaptu moves in the same way as a sarrum (one square in any direction).
Like all the other pieces, a kashshaptu cannot move into a square containing a
piece of the same colour and when a kashshaptu is moved into a square containing
the opponent’s sarrum, it captures the sarrum and the game is over.
When a move would cause the kashshaptu to enter a square containing one of the
opponent’s pieces (except the sarrum), the kashshaptu stays in its start square and
the opponent’s piece changes colour and now belongs to the player who played the
kashshaptu. It then becomes the other player's turn.
M/Jun15/COMP1
15
Figure 5
3 WK WG White’s
kashshaptu
can move one
4
square in any
direction
5
6 WS BS
1 2 3 4 5 6 7 8
White enters a start square of 23 and a finish square of 22. The board should now look
like this:
2 WK
3 WG
6 WS BS
1 2 3 4 5 6 7 8
Turn over
M/Jun15/COMP1
16
Figure 6
2 BG
3 WK WG
White’s
4 kashshaptu
can move one
5 square in any
direction
6 WS BS
1 2 3 4 5 6 7 8
White enters a start square of 23 and a finish square of 22. The board should now look
like this:
2 WG
White’s
kashshaptu
3 WK WG stays in its
original square
4 and the black
gisgigir has now
5 become a white
gisgigir
6 WS BS
1 2 3 4 5 6 7 8
M/Jun15/COMP1
17
Task 1
Adapt the program source code for the CheckMoveIsLegal subroutine, so that a
kashshaptu (represented by the letter K) has the same legal moves as a sarrum.
Task 2
Adapt the program source code for the MakeMove subroutine, so that when a redum
is promoted, it becomes a kashshaptu (represented by the symbol K) and so that a
kashshaptu moves and captures in the way described.
You need to adapt only the program source code so that the player with the White
pieces can promote a redum to a kashshaptu and move a kashshaptu.
Task 3
Test that the changes you have made work:
Turn over
M/Jun15/COMP1
18
Question 9 This question will further extend the functionality of the Skeleton Program.
You can attempt this question regardless of whether or not you produced a solution to
Question 8 that correctly added the kashshaptu piece to the game.
FEN can be adapted to represent game positions from chess variants like CAPTURE
THE SARRUM.
FEN defines a particular game position in one line of text using ASCII characters. This
line of text can then be saved into a file or copied for use in another program.
To represent a game position in CAPTURE THE SARRUM, the FEN needs to represent
two items of information about the game position – the board state (what pieces are on
what squares) and which player’s turn it is.
The first item in a FEN record for CAPTURE THE SARRUM is the board state. The
board state is represented rank by rank – starting with rank 1 and ending with rank 8.
Within each rank the contents of each square are described – starting with file 1 and
ending with file 8.
After the board state, there will be either a W or B character to indicate if it is White’s or
Black’s turn.
Figure 7 shows an example board position from a game and the equivalent FEN
record.
Figure 8 shows the initial board position and the equivalent FEN record.
M/Jun15/COMP1
19
Figure 7
1 BG BE BN BM BS BN BE BG
2 BR BR BR BR BR BR
3 BR
4 WR BR
6 WR
7 WR WR WR WR WR WR
8 WG WE WN WM WS WN WE WG
1 2 3 4 5 6 7 8
genmsneg/rrr1r1rr/3r4/4Rr2/8/3R4/RRR2RRR/GENMSNEG/B
Turn over
M/Jun15/COMP1
20
Figure 8
1 BG BE BN BM BS BN BE BG
2 BR BR BR BR BR BR BR BR
7 WR WR WR WR WR WR WR WR
8 WG WE WN WM WS WN WE WG
1 2 3 4 5 6 7 8
genmsneg/rrrrrrrr/8/8/8/8/RRRRRRRR/GENMSNEG/W
Task 1
Create a new subroutine, GenerateFEN, which takes two parameters (the board and
whose turn it is) and creates a string containing the FEN record for the current state of a
CAPTURE THE SARRUM game. It should return this string to the calling routine.
You may choose whether to make the new subroutine a function or a procedure.
You are likely to get some marks for this task, even if your subroutine is only partially
working.
It does not matter if your new subroutine will work correctly for positions containing a
kashshaptu (from Question 8).
M/Jun15/COMP1
21
Task 2
Adapt the MAIN PROGRAM BLOCK so that the FEN record returned by the
GenerateFEN subroutine is displayed before asking the player to enter their move.
Task 3
Test your program works by conducting the following test:
3 7 Your PROGRAM SOURCE CODE for the amended MAIN PROGRAM BLOCK.
[3 marks]
END OF QUESTIONS
M/Jun15/COMP1
22
M/Jun15/COMP1
23
M/Jun15/COMP1
24
M/Jun15/COMP1