User defined data types
4 Two descriptions of user-defined data types are given.
Give appropriate type declaration statements for each, including appropriate names.
(a) A data type to hold a set of prime numbers below 20. These prime numbers are:
2, 3, 5, 7, 11, 13, 17, 19
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(b) A data type to point to a day in the week, for example Monday.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
3 (a) A hashing algorithm is used to calculate storage locations for records in a random access file.
It calculates hash values by using the function modulus 3.
The function modulus gives the remainder after integer division.
For example, 1030 modulus 3 = 1. Therefore, the record key 1030 gives a hash value of 1.
Complete the table to show the remaining hash values.
Record key. Hash value
1030 1
1050. ............ ...
1025. ................ [2]
(b) Describe what happens, in relation to the storage or retrieval of a record in the file, when
the calculated hash value is a duplicate of a previously calculated hash value for a different
record key.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
2 (a) Describe how records are organised and accessed in a sequential file.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(b) A hashing algorithm is used to calculate storage locations for records in a random access file.
The algorithm calculates hash values using the function modulus 5.
The function modulus gives the remainder after integer division.
For example, 3003 modulus 5 = 3, so the record key 3003 gives a hash value of 3.
Complete the table to show the remaining hash values.
Record key Hash value
3003 3
1029. ........
7630. .......... [2]