User Defined Data Types
User Defined Data Types
User Defined Data Types
1 (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]
2
(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]
3
2 (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]
4
(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]
5
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]
6
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.
...................................................................................................................................................
...............................................................................................................................................[1]
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
...................................................................................................................................................
...............................................................................................................................................[1]
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
8
TYPE StudentRecord
DECLARE StudentID : INTEGER
DECLARE StudentFirstName : STRING
DECLARE StudentSurname : STRING
DECLARE StudentDOB : DATE
DECLARE StudentCourse : ARRAY[1:10] OF STRING
ENDTYPE
...............................................................................................................................................[1]
(i) Students can take six courses from: Computer Science, Engineering, Science, Maths,
Physics, Chemistry, Music, Drama and English Language.
Rewrite one line from the type definition of StudentRecord to implement the change.
DECLARE ...........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(ii) The values for the field StudentID must be between 1 and 8000 inclusive.
Rewrite one line from the type definition of StudentRecord to implement the change.
DECLARE .......................................................................................................................[1]
9
(c) A programmer is asked to write a program to process the assessment data for each student.
Students sit one exam in every course they take.
A composite data type, StudentAssessment, needs to be defined with the following three
fields.
• a student assessment code (a unique code of three letters and two digits)
• the marks for the six exams
• the average mark of the six exams
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[4]
10
TYPE BicycleRecord
ENDTYPE
(a) Write pseudocode statements to assign 567 to the BicycleID of LoanBicycle and
FALSE to the BicycleAvailable of LoanBicycle.
...................................................................................................................................................
............................................................................................................................................. [2]
(i) The definition has been extended to include borrower identification numbers,
BorrowerID, for the last 10 people who borrowed a bicycle. Each identification number
is an integer.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) The values for the field BicycleID must be between 500 and 599 inclusive.
Rewrite one pseudocode line from the type definition of BicycleRecord to implement
the change.
...........................................................................................................................................
..................................................................................................................................... [1]
11
TYPE ComputerRecord
ENDTYPE
...................................................................................................................................................
............................................................................................................................................. [2]
(i) The definition has been extended to include the student identification numbers,
StudentID, for up to 20 students who can use that computer. Each student identification
number is an integer.
Write the extra line of pseudocode needed in the type definition for ComputerRecord.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) The values for the field ComputerID must be between 1000 and 1999 inclusive.
Rewrite one pseudocode line from the type definition of ComputerRecord to implement
the change.
...........................................................................................................................................
..................................................................................................................................... [1]
12
TYPE box
ENDTYPE
(a) (i) Identify one composite and three non-composite data types used in the pseudocode.
..................................................................................................................................... [1]
Write pseudocode to store the details of this box in the first element of the array.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
13
(a) Draw one line from each data type to its correct classification.
Pointer
Record Composite
Set
Class Non-composite
Integer
[2]
(b) A user-defined data type, timeOfDay, is declared using the following pseudocode.
(i) Identify the type of user-defined data type declared and state its classification.
Type ..................................................................................................................................
Classification .....................................................................................................................
[2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
14
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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]
15
...................................................................................................................................................
............................................................................................................................................. [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]
16
TYPE Book
DECLARE ISBN : INTEGER
DECLARE Author : STRING
DECLARE Title : STRING
DECLARE Supplier : (Amazone, Stones, Smiths, Blackwalls, Greens,
Coals, Boarders)
ENDTYPE
...............................................................................................................................................[1]
(b) Name the non‑composite data type used in the Supplier declaration.
...............................................................................................................................................[1]
(c) (i) Write a pseudocode statement to declare a variable, BestSeller, of type Book.
.......................................................................................................................................[1]
.......................................................................................................................................[1]