Computing (9691) · Oct/Nov 2014 · Question paper 22
Cambridge Computing (9691) question paper for paper 22, Oct/Nov 2014 — 9691/22/O/N/14, file 9691_w14_qp_22.pdf.
More Computing (9691) papers
Other papers · Oct/Nov 2014
- Paper 12Question paperMark scheme
- Paper 21Question paperMark scheme
- Paper 23Question paperMark scheme
- Paper 32Question paperMark scheme
Paper 22 in other years
- May/June 2016M/J 2016Question paperMark scheme
- Oct/Nov 2015O/N 2015Question paperMark scheme
- May/June 2015M/J 2015Question paperMark scheme
- May/June 2014M/J 2014Question paperMark scheme
- Oct/Nov 2013O/N 2013Question paperMark scheme
- May/June 2013M/J 2013Question paperMark scheme
- Oct/Nov 2012O/N 2012Question paperMark scheme
- May/June 2012M/J 2012Question paperMark scheme
Text of this paper
Cambridge International Examinations
Cambridge International Advanced Subsidiary and Advanced Level
* 8 0 9 9 1 3 9 8 7 0 *
9691/22
COMPUTING
Paper 2
October/November 2014
2 hours
Candidates answer on the Question Paper.
No additional materials are required.
READ THESE INSTRUCTIONS FIRST
Write your Centre number, candidate number and name on all the work you hand in.
Write in dark blue or black pen.
You may use a soft pencil for any diagrams, graphs or rough working.
Do not use staples, paper clips, glue or correction fluid.
DO NOT WRITE IN ANY BARCODES.
Answer all questions.
At the end of the examination, fasten all your work securely together.
The number of marks is given in brackets [ ] at the end of each question or part question.
This document consists of 9 printed pages and 3 blank pages.
DC (LEG/CGW) 88571/4
© UCLES 2014
[Turn over
2
1
A sports club in a town organises an annual sports day for competitors aged 8 to 18. The organiser
wants these competitors to enter the sports day events online.
(a) To enter an event, each competitor needs to supply the following information:
•
•
•
•
Competitor name
Age in years
Whether or not they are a sports club member
The letter code for the single event they want to enter:
A 50 m race
B 100 m race
C Long jump
D High jump
E 5 km cycle race
F 25 m swimming
The competitor confirms that their details are correct. Their computer calculates and displays
the entry fee. Entries are free for sports club members.
(i)
Draw a suitable screen layout.
Annual Sports Day Entry Form
[6]
© UCLES 2014
9691/22/O/N/14
3
(ii)
Justify the design of your screen layout in part (i).
[2]
(b) The entries will be stored as records consisting of the following fields.
(i)
Complete the following table. Give a single value for each Field size.
Field name
Data type
Field size (bytes)
CompetitorName
CompetitorAge
ClubMember
EventEntered
EntryFee
[10]
(ii)
Calculate the size of the file if 100 event entries are stored.
File size in bytes [3]
© UCLES 2014
9691/22/O/N/14
[Turn over
4
2
Nathan copied the following pseudocode from a computing textbook. He wants to find out what it
does.
(a) Dry-run the pseudocode with s = 64, x = 1 and y = 15.
Complete the trace table.
Start a new row in the trace table every time round the loop.
z ← FALSE
REPEAT
m ← (x + y) DIV
IF List[m] = s
THEN
z ← TRUE
ELSE
IF List[m] >
THEN
y ← m –
ELSE
x ← m +
ENDIF
ENDIF
UNTIL z = TRUE
OUTPUT m
List
2
s
1
1
1
27
2
28
3
33
4
36
5
39
6
41
7
45
8
52
9
64
10
67
11
78
12
79
13
81
14
85
15
92
Trace table:
s
z
x
y
m
List[m]
List[m] = s
List[m] > s
64
-
1
15
-
-
-
-
-
-
-
-
8
52
FALSE
OUTPUT [8]
(b) What does this pseudocode do?
[2]
© UCLES 2014
9691/22/O/N/14
5
3
A game is played by two players. Player A uses white tokens ( ). Player B uses black tokens ( ).
The players take turns dropping tokens into a vertical grid. The tokens fall straight down and
occupy the next available space in the chosen column. The aim of the game is to connect four of
one’s own colour tokens. This must be done in a vertical, horizontal or diagonal line.
Here is one example after Player A has had 2 turns and Player B has had 1 turn:
Row
6
5
4
3
2
1
Column 1
2
3
4
5
6
7
Nathan wants to write a program to allow two users to play the game on the computer.
The program will display a simplified version of the above grid which is redrawn after every turn.
(a) Before any tokens have been dropped into the grid, all grid cells are empty.
(i)
Suggest values Nathan should use to represent:
Empty cell
White token
Black token [2]
(ii)
The array Grid is to be used to represent the contents of the game grid.
In a high-level programming language, write statements to:
• declare the array Grid
• assign the value for an empty cell to all cells.
Language
Code
[7]
(iii)
Write the statement to assign the value for a black token to the cell shown in the diagram.
[2]
© UCLES 2014
9691/22/O/N/14
[Turn over
6
(b) After a player takes their turn, the new state of the grid is to be displayed on the screen. The
display will show only the cell contents.
In a high-level language, write programming statements to implement
the algorithm represented by the flowchart.
Start
Ensure that your code demonstrates good programming practice.
Language
Loop from row
6 down to 1
Code
Loop from
column
1 to 7
Output
contents of grid
cell for this row
and column
End of inner
loop?
No
Yes
End of outer
loop?
Yes
No
[4]
End
© UCLES 2014
9691/22/O/N/14
7
(c) To drop a token into the grid, the player enters the chosen column number.
The function ColumnNumberValid has a parameter (x) which is the chosen column
number. The function returns:
• TRUE if x is between 1 and 7 inclusive and there is still space in the column
• FALSE otherwise
(i)
Complete the pseudocode:
FUNCTION ColumnNumberValid(x : ) RETURNS
DECLARE Valid :
IF // x outside range?
THEN
Valid ← // column number not within range
ELSE
IF Grid[6, x] = // cell in top row empty?
THEN
Valid ← // cell empty
ELSE
Valid ← // cell not empty
ENDIF
ENDIF
RETURN Valid
ENDFUNCTION
(ii)
[8]
Nathan wants to test the validation of the parameter, x, by this function.
Give three different types of test data with an example of each.
Justify your choices.
Type of test data
Example test data
Justification
[9]
© UCLES 2014
9691/22/O/N/14
[Turn over
8
(d) The program stores in the variable NextPlayer the character 'A' or 'B' to show whose turn it
is next.
The chosen column number is validated using the function from part (c)(i).
The program then sets the relevant empty grid cell to the player’s token value.
Complete the pseudocode:
01 REPEAT
02
INPUT ChosenColumnNumber
03 UNTIL ColumnNumberValid( )
04 Row ← 1
// start with bottom row and find first empty row
05 WHILE Grid[Row, ChosenColumnNumber] <>
06
07 ENDWHILE
08 IF
09
10
11
12
THEN
Grid[Row, ChosenColumnNumber] ←
ELSE
Grid[Row, ChosenColumnNumber] ←
13 ENDIF
[5]
(e) Nathan wants a single player to play against the computer. He uses the built-in function
RANDOM(n) to simulate the computer’s choice of column. This function returns a whole
number in the range 1 to n inclusive.
He writes the procedure GetColumn to input the next move either from the computer or
Player ‘B’. This procedure has two parameters which are passed either by reference or by
value.
PROCEDURE GetColumn(Player : CHAR, Number : INTEGER)
IF Player = 'A'
// Player 'A' is the computer.
THEN
Number ← RANDOM(7)
ELSE
INPUT Number
ENDIF
ENDPROCEDURE
© UCLES 2014
9691/22/O/N/14
9
(i)
State which method of parameter passing (by reference or by value) is used for each of
Player and Number.
Player
Number [2]
(ii)
Write the procedure call which will replace line 02 of the pseudocode in part (d).
[2]
(f)
All programs should be maintainable.
List three features of maintainable programs used in the pseudocode in part (d).
1
2
3 [3]
© UCLES 2014
9691/22/O/N/14
10
BLANK PAGE
© UCLES 2014
9691/22/O/N/14
11
BLANK PAGE
© UCLES 2014
9691/22/O/N/14
12
BLANK PAGE
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.
© UCLES 2014
9691/22/O/N/14