Topical Past Papers: Computer Science 9608
Topical Past Papers: Computer Science 9608
10. (b) Explain why I and T are unsuitable as variable names and say how they can be improved. [2]
3. Kris has written a program that will work out the wages for her staff. The main steps for each employee are: to
work out the hours worked, work out the total earnings, work out tax and finally print out how much will be taken
home.
(e) (i) Explain how it is possible to use the same variable name for different variables in different modules. [2]
(ii) Explain how this can help when modules are programmed separately. [3]
2 Nathan is designing a software solution for stock control in a mobile phone shop. He has a colleague, called Andre,
who will help him write the program. Nathan decides to modularise the solution.
(a) Nathan will write the ShopSales module and Andre will write the OnlineSales module.
Nathan will use the identifier Sale for a sale in the shop, and Andre will use the identifier Sale for an online
order.
Explain how they can both use the same identifier and not cause a problem when the program is run. [2]
(b) Both programmers need to choose other identifiers that they will use.
(i) Explain why there are some words that cannot be used as identifiers. [1]
(ii) State three other rules of a high-level programming language that restrict the choice of
identifiers.
Language [3]
(iii) Give an example of an invalid identifier. [1]
Oct/NOV 2012.P21
1 Soni works for a software house which has been asked to design software for a cycle hire company, Super Bikes.
Explain how it is possible to use the same variable name for different variables in different modules. [2]
Page 1 of 20
Computer Science 9608
Topical Past Papers
3 Meena needs to be aware of her average grade and declares a variable AvMark, which she decides will be a
global variable.
3 Meena needs to be aware of her average mark and declares a variable with identifier MyAvMark which she
decides will be a global variable.
(a) State where in the program a global variable will be declared. [1]
Oct/Nov 2013.P21
2 (a) Juan has little programming experience, but has to write code for this program. He has written the following
pseudocode statements.
For each statement describe what is wrong and write a correct version.
Oct/Nov 2013.P22
1 (c) (i) Jemma is using the variable Percentage in one module and a different variable called Percentage in
another module.
Explain the feature of a high-level programming language that avoids any possible conflict. [2]
Page 2 of 20
Computer Science 9608
Topical Past Papers
1 The Science Department has a problem keeping track of its equipment. Ashvin has been asked to design and
program a solution as his Computing Project.
(a) Ashvin has little programming experience, but has to write code for this program. He starts by writing some
pseudocode.
For each statement, describe what is wrong and write a correct version.
(i) NoOfBalances + 1 ← NoOfBalances [2]
(ii) IF NoOfPipettes > NoOfBeakers OR < NoOfBottles THEN OUTPUT “Check
the numbers” [2]
4 Ashvin is also learning about recursion. He writes the pseudocode for a recursive function.
1 FUNCTION Calc(X)
2 DECLARE Temp
3 IF X > 0
4 THEN
5 Temp ← X + Calc(X – 2)
6 ELSE
7 Temp ← 0
8 ENDIF
9 RETURN Temp
10 ENDFUNCTION
(b) State the line number which shows that this function is recursive. [1]
Page 3 of 20
Computer Science 9608
Topical Past Papers
4 Ahmed combines white tiles with tiles of one other colour to make a pattern. He draws a design. Here is one
example:
Ahmed wants a program to calculate how many tiles he needs of each colour.
(a) Ali stores the design in a 2-dimensional array, FloorDesign. The length and width of the room will be no
more than 35 tiles each.
(i) Suggest a value Ali should use to represent the white and coloured tiles. [1]
Oct/Nov 2014.P22
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:
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.
Page 4 of 20
Computer Science 9608
Topical Past Papers
(iii) Write the statement to assign the value for a black token to the cell shown in the diagram. [2]
May/June 2015.P21/P22
The players take turns in placing their marker in an empty cell of the grid; player O always starts.
The game ends when one player completes a row, column or diagonal or the grid is full.
(a) The array Grid is to be used to represent the contents of the grid.
(i) To take their turn, the player inputs a row number and a column number to place their marker in an
empty cell.
Write the values player X has input to place their marker, ‘X’, in the above diagram:
Row ...................................................................................................................................
Column ......................................................................................................................... [1]
(ii) State the value Ali could use to represent an empty cell. [1]
Page 5 of 20
Computer Science 9608
Topical Past Papers
01 GameEnd ← FALSE
02 CurrentPlayer ← 'O'
03 CALL DisplayGrid()
04
05 REPEAT
06 CALL PlayerTakesTurn(CurrentPlayer)
07 CALL DisplayGrid()
08 IF HasPlayerWon() = TRUE
09 THEN
10 GameEnd ← TRUE
12 ELSE
13 IF GridFull() = TRUE
14 THEN
15 GameEnd ← TRUE
16 OUTPUT "Draw"
17 ELSE
18 CALL SwapPlayer(CurrentPlayer)
19 ENDIF
20 ENDIF
Page 6 of 20
Computer Science 9608
Topical Past Papers
[5]
May/June 2015.P23
Page 7 of 20
Computer Science 9608
Topical Past Papers
The object of the game is for a player to move from the bottom square (Square 01) to the top square (Square 30).
A roll of a 6-sided die determines how many squares the player moves.
The table below shows example moves. These use the board layout above, with the player currently on Square 04.
Ali plans to write a program to test different board designs. Each board design will have different numbers, positions
and lengths for the slides and ladders.
The program is to test each board design to check that it is possible to complete the game in a reasonable number of
moves.
For each board design, the program will simulate playing the game 1000 times and report the average number of
moves.
(a) Ali starts the high level design of his program using pseudocode.
Page 8 of 20
Computer Science 9608
Topical Past Papers
07 …………………………………………………………………………………………………………………………………………………………………………………………
08 AverageMovesPerGame ← …………………………………………………………………………………………………………………………………
09 OUTPUT AverageMovesPerGame
(a) (v) List the variable identifiers used in the pseudocode. [2]
(d) (i) A high-level programming language has a built-in function that generates a random number. The function is
defined as follows:
Ali’s program is to use this random number generator to simulate the rolling of a die. Complete the statement to
assign a number between 1 and 6 to NumberRolled.
NumberRolled ← ............................................................................................................
....................................................................................................................................... [1]
Page 9 of 20
Computer Science 9608
Topical Past Papers
1 A marathon runner records their time for a race in hours, minutes and seconds.
(a) The identifier table needs to show the variables required to write a program for this algorithm. Complete the
table.
[3]
The new design includes input of the runner’s current personal best marathon time (in seconds).
The output will now also show one of the following messages:
[1]
Page 10 of 20
Computer Science 9608
Topical Past Papers
These programs will use data about daily sales made from Site X (using variable SalesX) and Site Y (using variable
SalesY).
(i) Add to the identifier table to show the variables you need for this new program
Page 11 of 20
Computer Science 9608
Topical Past Papers
[3]
May/June 2015.P23
1 Horses are entered for a horse race. A horse may have to carry a penalty weight in addition to the rider. This
weight is added to the saddle. The penalty weight (if any) depends on the number of wins the horse has achieved in
previous races.
(a) Complete the identifier table showing the variables needed to code the program.
Page 12 of 20
Computer Science 9608
Topical Past Papers
[3]
5 A firm employs workers who assemble amplifiers. Each member of staff works an agreed number of hours each
day.
The firm records the number of completed amplifiers made by each employee each day.
(c) An experienced programmer suggests that the pseudocode would be best implemented as a procedure
AnalyseProductionData.
Assume that both arrays, DailyHoursWorked and ProductionData, are available to the procedure from the
main program and they are of the appropriate size.
DECLARE …………………………………………………………………………………………………………………………………………………………………………………………
DECLARE …………………………………………………………………………………………………………………………………………………………………………………………
DECLARE …………………………………………………………………………………………………………………………………………………………………………………………
DECLARE …………………………………………………………………………………………………………………………………………………………………………………………
Page 13 of 20
Computer Science 9608
Topical Past Papers
WorkerTotal[WorkerNum] ← 0
ENDFOR
FOR WorkerNum ← 1 TO 3
FOR DayNum ← 1 TO 4
WorkerTotal[WorkerNum] ← WorkerTotal[WorkerNum] +
ProductionData[DayNum, WorkerNum]
ENDFOR
ENDFOR
FOR WorkerNum ← 1 TO 3
IF WorkerAverage < 2
THEN
ENDIF
ENDFOR
ENDPROCEDURE
(i) Complete the declaration statements showing the local variables. [4]
Page 14 of 20
Computer Science 9608
Topical Past Papers
6 A firm employs five staff who take part in a training programme. Each member of staff must
complete a set of twelve tasks which can be taken in any order. When a member of staff successfully completes a
task, this is recorded.
A program is to be produced to record the completion of tasks for the five members of staff.
To test the code, the programmer makes the program generate test data.
The program generates pairs of random numbers:
• the first, in the range, 1 to 5 to represent the member of staff
• the second, in the range, 1 to 12 to represent the task
Each pair of numbers simulates the completion of one task by one member of staff.
(a) Explain why the generation of 60 (5 staff x 12 tasks) pairs of random numbers will not simulate all tasks
completed by all staff. [2]
(b) Data is currently recorded manually as shown.
Page 15 of 20
Computer Science 9608
Topical Past Papers
12 TaskNum ← RANDOM(1,12)
//in the given range
13 IF TaskGrid[StaffNum, TaskNum] = FALSE
14 THEN
15 TaskGrid[StaffNum, TaskNum] ← TRUE
16 NewStaffTask ←
TRUE
17 OUTPUT StaffNum, TaskNum
18 ENDIF
19 ENDWHILE
20 Completed ←Completed + 1
21 ENDWHILE
22 OUTPUT "Staff Task Count", Completed
23
24 // end of main program
25
26 PROCEDURE InitialiseTaskGrid()
27 DECLARE i : INTEGER
28 DECLARE j : INTEGER
29 FOR i ← 1 TO 5
30 FOR j ← 1 TO 12
31 TaskGrid[i, j] ← FALSE
32 ENDFOR
33 ENDFOR
34 ENDPROCEDURE
Page 16 of 20
Computer Science 9608
Topical Past Papers
4 The standard pack of playing cards has four suits – called Clubs, Diamonds, Hearts and Spades.
Each card has a value shown by its number or a name: 1 (Ace), 2, 3, … 10, 11 (Jack), 12 (Queen),13 (King). The pack of
cards has one combination for each suit and value.
A program is to be written which simulates a magician dealing all 52 cards from the card pack.
The program generates pairs of random numbers:
• the first, in the range 1 to 4, to represent the suit
• the second, in the range 1 to 13, to represent the card value
(a) Explain why the generation of 52 (4 suits x 13 card values) pairs of random numbers will not simulate the dealing
of the complete pack. [2]
Page 17 of 20
Computer Science 9608
Topical Past Papers
The table shows two cards have been dealt so far; the 3 of Hearts and the Jack of Clubs.
When each card is dealt, the appropriate cell changes from F to T.
The program will output the suit and the card value in the order in which the cards are dealt.
13 CardValue ←
RANDOM(1,13) // in the range given
14 IF CardPack[SuitNum, CardValue] = FALSE
15 THEN
16 CardPack[SuitNum, CardValue] ← TRUE
17 NewCard TRUE ←
18 OUTPUT SuitNum, CardValue
19 ENDIF
20 ENDWHILE
21 DealCount ←
DealCount + 1
22 ENDWHILE
23
24 // end of main program
25
Page 18 of 20
Computer Science 9608
Topical Past Papers
30 FOR j ← 1 TO 13
31 CardPack[i, j] ← FALSE
32 ENDFOR
33 ENDFOR
34 ENDPROCEDURE
[5]
Page 19 of 20
Computer Science 9608
Topical Past Papers
NextChar ←
ONECHAR(InputString, i)
IF NextChar <> " "
THEN
// the & character joins together two strings
NewString ← NewString & NextChar
ENDIF
ENDFOR
OUTPUT NewString
(i) Complete the identifier table below.
[4]
Page 20 of 20