Topical Past Papers For Alevels Computer Science
Topical Past Papers For Alevels Computer Science
QUESTION 1.
3 (a) A particular programming language allows the programmer to define their own data types.
TYPE ThisDate
DECLARE ThisDay : (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)
DECLARE ThisMonth : (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug,
Sep, Oct, Nov, Dec)
DECLARE ThisYear : INTEGER ENDTYPE
(i) Name the non-composite data type used in the ThisDay and ThisMonth declarations.
.......................................................................................................................................[1]
.......................................................................................................................................[1]
(iii) The month value of DateOfBirth needs to be assigned to the variable MyMonthOfBirth.
.......................................................................................................................................[1]
© UCLES 2015
7
9608/31/M/J/15
(b) Annual rainfall data from a number of locations are to be processed in a program.
• location name
• total rainfall for each month of the year (centimetres to 1 decimal place)
A variable of this type can be used to store all the data for one particular location.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[5]
(ii) The programmer decides to store all the data in a file. Initially, data from 27 locations will be
stored. More rainfall locations will be added over time and will never exceed 100.
The programmer has to choose between two types of file organisation. The two types are serial and
sequential.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
© UCLES 2015
1
Lecturer Malik Kamran
9608/31/M/J/15
QUESTION 2.
4 (a) A particular programming language allows the programmer to define their own data types.
TYPE ThisAddress
DECLARE ThisHouseNo : INTEGER
DECLARE ThisStreet : STRING DECLARE ThisTown : STRING ENDTYPE
(i) Write the statement that assigns the house number 34 to HomeAddress.
.......................................................................................................................................[1]
Rewrite one line from the definition for each of the following changes.
DECLARE ...........................................................................................................................
The possible towns are limited to: Brightown, Arunde and Shoram.
DECLARE .......................................................................................................................[2]
© UCLES 2015
9
9608/33/M/J/15
(b) Temperature data from a number of weather stations are to be processed by a program.
• average temperature (to the nearest whole number) for each year from 2001 to 2015 inclusive
A programmer designs a composite data type WeatherStation. A variable of this type can be
used to store all the data for one particular station.
(i) Write the definition for the user-defined data type WeatherStation.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[5]
(ii) The programmer decides to store all the data in a file. The number of weather stations could
grow to reach 20000, but not all stations will be present at first.
Describe three steps which show how a new weather station record is added to the file.
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
........................................................................................................................................... 3
........................................................................................................................................
.......................................................................................................................................[3]
© UCLES 2015
1
Lecturer Malik Kamran
9608/33/M/J/15
© UCLES 2015
2
QUESTION 3.
1 (a) Consider the following user-defined data type:
TYPE LibraryBookRecord
DECLARE ISBN : INTEGER
DECLARE Title : STRING
ENDTYPE
(ii) Write a pseudocode statement that assigns ‘Dune’ to the Title of Book.
book.title asignment op "Dune"
.......................................................................................................................................[1]
(b) The user-defined data type LibraryBookRecord needs to be modified by adding the
following fields:
• a field called Genre which can take two values, fiction or non-fiction
• a field called NumberOfLoans which can be an integer value in the range 1 to 99
...................................................................................................................................................
Type LibrarybookRecord
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
(c) A pointer is a variable that stores the address of a variable of a particular type.
The four assignment statements are executed. The diagram shows the memory contents after
execution.
Memory
Contents
Variable
address
...
8217
IntVar 8216 88
8215
8214
...
7307
7305
...
6717
Temp1 6716 88
Temp2 6715 57
6714
...
Use the diagram to state the current values of the following expressions:
6715
(i) @Temp2 .........................................................................................................................[1]
(ii) 8216
IntPointer .................................................................................................................[1]
88
(iii) IntPointer^ ...............................................................................................................[1]
(iv) false
IntPointer^ = Temp2 + 6 .....................................................................................[1] (d)
Write pseudocode statements that will achieve the following:
(iii) Copy the value in Temp2 into the memory location currently pointed at by IntPointer.
temp2<-------- IntPointer^
.......................................................................................................................................[1]
QUESTION 4.
1 (a) Consider the following pseudocode user-defined data type:
TYPE MyContactDetail
DECLARE Name : STRING
DECLARE HouseNumber : INTEGER
ENDTYPE
(ii) Write a pseudocode statement that assigns 129 to the HouseNumber of NewFriend.
129 ------> NewFriend.HouseNumber
.......................................................................................................................................[1]
• adding a field called Area which can take three values, uptown, downtown or midtown •
amending the field HouseNumber so that house numbers can only be in the range 1 to 499.
Type MyContactDetail
...................................................................................................................................................
Declare Name : string
Declare HouseNumber : Integer (1..499)
...................................................................................................................................................
Declare Area: string (Uptown,downtown,midtown)
EndType
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
(c) A pointer is a variable that stores the address of a variable of a particular type.
The four assignment statements are executed. The diagram shows the memory contents after
execution.
Memory
Variable Contents
Address
...
5848
5847
...
4403
Sum 4402 33
4401
...
3428
MyInt1 3427 91
MyInt2 3426 33
3425
...
Use the diagram to state the current values of the following expressions:
4402
(i) IPointer .....................................................................................................................[1]
(ii)
33
IPointer^ ...................................................................................................................[1]
true
IPointer^ = MyInt2 ...............................................................................................[1]
[Turn over
(d) Write pseudocode statements that will achieve the following:
(iii) Copy the value in MyInt2 into the memory location currently pointed at by IPointer.
Myint2---->IPointer
.......................................................................................................................................[1]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(i) Complete the following pseudocode definition of a user-defined data type to store the
employee data.
TYPE Employee
...........................................................................................................................................
..................................................................................................................................... [1]
..................................................................................................................................... [1]
(iv) Employee is an example of a record that is a composite data type.
1 ........................................................................................................................................
2 ........................................................................................................................................
[2]
© UCLES 2019 9608/31/O/N/19
QUESTION 6. 9
6 (a) State what is meant by a user-defined data type.
...................................................................................................................................................
............................................................................................................................................. [2]
(b) A pseudocode declaration for a user-defined data type for the months of the year is as follows:
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) Write a pseudocode statement to declare a variable CurrentMonth of data type Months.
...........................................................................................................................................
..................................................................................................................................... [1]
(iii) Write a pseudocode statement to assign the value August to the variable CurrentMonth.
...........................................................................................................................................
..................................................................................................................................... [1]
© UCLES 2019 9608/32/O/N/19 [Turn over