3.1.1 Computer Science Chapter 1
3.1.1 Computer Science Chapter 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]
.......................................................................................................................................[1]
(b) Annual rainfall data from a number of locations are to be processed in a program.
• location name
• height above sea level (to the nearest metre)
• 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]
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]
(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]
TYPE LibraryBookRecord
DECLARE ISBN : INTEGER
DECLARE Title : STRING
ENDTYPE
.......................................................................................................................................[1]
(ii) Write a pseudocode statement that assigns ‘Dune’ to the Title of Book.
.......................................................................................................................................[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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[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
...
8217
IntVar 8216 88
8215
8214
...
7307
IntPointer 7306 8216
7305
...
6717
Temp1 6716 88
Temp2 6715 57
6714
...
Use the diagram to state the current values of the following expressions:
.......................................................................................................................................[1]
.......................................................................................................................................[1]
(iii) Copy the value in Temp2 into the memory location currently pointed at by IntPointer.
.......................................................................................................................................[1]
TYPE MyContactDetail
DECLARE Name : STRING
DECLARE HouseNumber : INTEGER
ENDTYPE
.......................................................................................................................................[1]
(ii) Write a pseudocode statement that assigns 129 to the HouseNumber of NewFriend.
.......................................................................................................................................[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.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[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
IPointer 5846 4402
5845
...
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:
.......................................................................................................................................[1]
.......................................................................................................................................[1]
(iii) Copy the value in MyInt2 into the memory location currently pointed at by IPointer.
.......................................................................................................................................[1]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(i) Complete the following pseudocode definition of a user-defined data type to store the
employee data.
TYPE Employee
..................................................................................)
...........................................................................................................................................
[4]
...........................................................................................................................................
..................................................................................................................................... [1]
...........................................................................................................................................
..................................................................................................................................... [1]
1 ........................................................................................................................................
2 ........................................................................................................................................
[2]
© UCLES 2019 9608/31/O/N/19
QUESTION 6. 9
...................................................................................................................................................
............................................................................................................................................. [2]
(b) A pseudocode declaration for a user-defined data type for the months of the year is as follows:
TYPE
DECLARE Months: (January, February, March, April, May, June, July,
August, September, October, November, December)
ENDTYPE
...........................................................................................................................................
..................................................................................................................................... [1]
...........................................................................................................................................
..................................................................................................................................... [1]
(iii) Write a pseudocode statement to assign the value August to the variable
CurrentMonth.
...........................................................................................................................................
..................................................................................................................................... [1]