Data types, arrays and files – A Level Computer Science (old syllabus, to 2021) (9608)
48 questions · page 4 of 4 · Clear filters
Question text
2
(a) (i)
State what is meant by a recursively defined procedure.
…
… [1]
(ii)
Write the line number from the pseudocode shown in part (b) that shows the
procedure X is recursive. …
[1]
(b) The recursive procedure X is defined as follows:
01 PROCEDURE X(Index, Item)
02
IF MyList[Index] > 0
03
THEN
04
IF MyList(Index) >= Item
05
THEN
06
MyList[Index] ← MyList[Index + 1]
07
ENDIF
08
CALL X(Index + 1, Item)
09
ENDIF
10 ENDPROCEDURE
An array MyList is used to store a sorted data set of non-zero integers. Unused cells contain
zero.
1
2
3
4
5
6
7
8
9
10
MyList
3
5
8
9
13
16
27
0
0
0
(i)
Complete the trace table for the dry-run of the pseudocode for the procedure
CALL X(1, 9).
MyList
Index
Item
1
2
3
4
5
6
7
8
9
10
3
5
8
9
13
16
27
0
0
0
1
9
[4]
State the purpose of procedure X when used with the array MyList.
(ii)
…
… [1]
Question text
5
(a) A program calculates the exam grade awarded from a mark input by the user. The code is
written as a function CalculateGrade.
The function:
has a single parameter Mark of INTEGER data type
•
returns the grade awarded Grade of STRING data type
•
The logic for calculating the grade is as follows:
Mark
Grade
Under 40
FAIL
40 and over and under 55
PASS
55 and over and under 70
MERIT
70 and over
DISTINCTION
The programmer designs the following table for test data:
Mark
Description
Expected result (Grade)
Normal
Abnormal
Extreme/Boundary
(i)
Complete the table above.
[3]
(ii)
State why this table design is suitable for black box testing.
…
… [1]
(b) When designing and writing program code, explain what is meant by:
•
an exception
•
exception handling
…
…
…
…
…
… [3]
(c) A program is to be written to read a list of exam marks from an existing text file into a 1D array.
Each line of the file stores the mark for one student.
State three exceptions that a programmer should anticipate for this program.
1 …
…
2 …
…
3 …
… [3]
(d) The following pseudocode is to read two numbers:
01 DECLARE Num1
: INTEGER
02 DECLARE Num2
: INTEGER
03 DECLARE Answer : INTEGER
04 TRY
05
OUTPUT "First number..."
06
INPUT Num1
07
OUTPUT "Second number..."
08
INPUT Num2
09
Answer ← Num1 / (Num2 – 6)
10
OUTPUT Answer
11 EXCEPT ThisException : EXCEPTION
12
OUTPUT ThisException.Message
13 FINALLY
14
// remainder of the program follows
…
29
30 ENDTRY
The programmer writes the corresponding program code.
A user inputs the number 53 followed by 6. The following output is produced:
First number...53
Second number...6
Arithmetic operation resulted in an overflow
(i)
State the pseudocode line number which causes the exception to be raised.
…
[1]
Explain the purpose of the pseudocode on lines 11 and 12.
(ii)
…
…
Question text
6
In a board game, one player has white pieces and the other player has black pieces. Players take
alternate turns to move one of their pieces. White always makes the first move.
The game ends if:
•
a player is unable to make a move when it is their turn. In this case, there is no winner. This is
called ‘stalemate’.
•
a player wins the game as a result of their last move and is called a ‘winner’.
(a) A state-transition diagram is drawn to clarify how the game is played.
Complete the following state-transition diagram.
WHITE
WINS
No move
possible
:+,7(·6
TURN
Stalemate
BLACK moves
BLACK
%/$&.·6
WINS
TURN
Winning
move
[4]
(b) The layout of the board at the start of the game is shown below:
x
y
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
The programmer decides to use a 2D array to represent the board. The index numbering to
be used is as shown.
Each square on the board is either occupied by one piece only, or is empty.
The data stored in the array indicate whether or not that square is occupied, and if so, with a
black piece or a white piece.
(i)
Write program code to initialise the contents of the array to represent the board at the
start of the game. Use characters as follows for each square:
'B' represents a black piece
'W' represents a white piece
'E' represents an empty square
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…