10.1 Data Types & Records
AS Level · 3 questions found
What this topic covers
Section titled “What this topic covers”- Select appropriate data types: INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE
- Purpose of a record: holds mixed data types under one identifier
- Write pseudocode to define, read from and write to a record structure
Past paper questions
Section titled “Past paper questions” Q1


1
An algorithm is developed in pseudocode before being coded in a programming language.
(a) The following table shows four valid pseudocode assignment statements.
Complete the table by giving an appropriate data type to declare each of the variables A, B, C
and D.
Assignment statement
Data type
A
LEFT(MyName, 1)
B
Total * 2
C
INT(ItemCost) / 3
D
"Odd OR Even"
[4]
(b) Other variables in the program have example values as shown:
Variable
Value
Sorted
False
Tries
9
ID
"ZGAC001"
Complete the table by evaluating each expression, using the example values.
Expression
Evaluates to
Tries < 10 AND NOT Sorted
Tries MOD 4
TO_LOWER(MID(ID, 3, 1))
LENGTH(ID & "xx") >= Tries
[4]
(c) The variable names A, B, C and D in part (a) are not good programming practice.
(i) State why these variable names are not suitable.
..................................................................................................................................... [1]
(ii) Identify one problem that these variable names might cause.
..................................................................................................................................... [1]
(iii) The choice of suitable variable names is one example of good programming practice.
Give one other example.
..................................................................................................................................... [1]
Show mark scheme
1(a) [4 marks]
Assignment statement
Data type
CHAR / STRING
A
LEFT(MyName, 1)
INTEGER / REAL
B
Total * 2
REAL
C
INT(ItemCost) / 3
STRING
D
"Odd OR Even"
One mark per row
Data type
CHAR / STRING
A
LEFT(MyName, 1)
INTEGER / REAL
B
Total * 2
REAL
C
INT(ItemCost) / 3
STRING
D
"Odd OR Even"
One mark per row
1(b)
Expression
Evaluates to
Tries < 10 AND NOT Sorted
TRUE
Tries MOD 4
1
TO_LOWER(MID(ID, 3, 1))
'a' // "a"
LENGTH(ID & "xx") >= Tries
TRUE
One mark per row
Evaluates to
Tries < 10 AND NOT Sorted
TRUE
Tries MOD 4
1
TO_LOWER(MID(ID, 3, 1))
'a' // "a"
LENGTH(ID & "xx") >= Tries
TRUE
One mark per row
1(c)(i) [1 mark]
The names do not reflect / indicate the purpose of the variable // the names
are not meaningful
are not meaningful
1(c)(ii) [1 mark]
They make the program more difficult to understand / debug / maintain
1(c)(iii)
One mark from:
Indentation / use of white space
Capitalisation of keywords
Use of comments
Use of modular programming
Use of local variables
Note: max 1 mark
Indentation / use of white space
Capitalisation of keywords
Use of comments
Use of modular programming
Use of local variables
Note: max 1 mark
Q3

3
A factory needs a program to help manage its production of items.
Data will be stored about each item.
The data for each item will be held in a record structure of type Component.
The programmer has started to define the fields that will be needed as shown in the table.
Field
Example value
Comment
Item_Num
123478
a numeric value used as an array index
Reject
FALSE
TRUE if this item has been rejected
Stage
'B'
a letter to indicate the stage of production
Limit_1
13.5
any value in the range 0 to 100 inclusive
Limit_2
26.4
any value in the range 0 to 100 inclusive
(a) (i) Write pseudocode to declare the record structure for type Component.
..................................................................................................................................... [4]
(ii) A 1D array Item of 2000 elements will store the data for all items.
Write pseudocode to declare the Item array.
..................................................................................................................................... [2]
(b) State three benefits of using an array of records to store the data for all items.
1 ................................................................................................................................................
2 ................................................................................................................................................
3 ................................................................................................................................................
[3]
Show mark scheme
3(a)(i) [2 marks]
Pseudocode:
TYPE Component
DECLARE Item_Num : INTEGER
DECLARE Reject : BOOLEAN
DECLARE Stage : CHAR
DECLARE Limit_1 : REAL
DECLARE Limit_2 : REAL
ENDTYPE
Mark as follows:
1
One mark for
and
statements
TYPE
ENDTYPE
2
One mark for
and
fields
Item_Num
Reject
3
One mark for
field
Stage
4
One mark for Limit fields as
REAL
DECLARE Item : ARRAY [1:2000] OF Component//
TYPE Component
DECLARE Item_Num : INTEGER
DECLARE Reject : BOOLEAN
DECLARE Stage : CHAR
DECLARE Limit_1 : REAL
DECLARE Limit_2 : REAL
ENDTYPE
Mark as follows:
1
One mark for
and
statements
TYPE
ENDTYPE
2
One mark for
and
fields
Item_Num
Reject
3
One mark for
field
Stage
4
One mark for Limit fields as
REAL
DECLARE Item : ARRAY [1:2000] OF Component//
3(a)(ii) [3 marks]
DECLARE Item : ARRAY [2000] OF Component//
DECLARE Item : ARRAY [0:1999] OF Component
One mark per underlined phrase
DECLARE Item : ARRAY [0:1999] OF Component
One mark per underlined phrase
3(b) [5 marks]
One mark per point:
1
Allows for iteration / can use a loop
to access the records / data items
2
Use of index to directly access a
record
in the array // Example of
simplification of code e.g. use of dot notation Item[1].Stage
3
Simplifies the code / algorithm // Reduces duplication of code //
Program
easier to write / understand / maintain / test / debug //
Data items/record
easier to search / sort / manipulate
1
Allows for iteration / can use a loop
to access the records / data items
2
Use of index to directly access a
record
in the array // Example of
simplification of code e.g. use of dot notation Item[1].Stage
3
Simplifies the code / algorithm // Reduces duplication of code //
Program
easier to write / understand / maintain / test / debug //
Data items/record
easier to search / sort / manipulate
Q3


3
A record structure is declared to hold data relating to components being produced in a factory:
TYPE Component
DECLARE Item_ID : STRING
DECLARE Reject : BOOLEAN
DECLARE Weight : REAL
ENDTYPE
The factory normally produces a batch (or set) of 1000 components at a time. A global array is
declared to store 1000 records for a batch:
DECLARE Batch : ARRAY [1:1000] OF Component
Two global variables contain the minimum and maximum acceptable weight for each component.
The values represent an inclusive range and are declared as:
DECLARE Min, Max : REAL
(a) (i) A program uses a variable ThisIndex as the array index to access a record.
Write a pseudocode clause to check whether or not the weight of an individual component
is within the acceptable range.
..................................................................................................................................... [3]
(ii) When batches of less than 1000 components are processed, it is necessary to indicate
that certain elements in the array are unused.
Suggest how an unused array element could be indicated.
..................................................................................................................................... [1]
(b) A module InRange() will:
•
be called with an integer parameter representing an index value of a record in the Batch
array
•
check if the weight of the indexed component is within the acceptable range
•
return TRUE if the weight is in the range and FALSE if it is not.
A module BatchCheck() will:
•
iterate through a batch of 1000 component records
•
call module InRange() to check each individual component record
•
keep a count of the number of components that fail
•
output a suitable warning message and immediately stop if the number of failed
components exceeds 5.
Complete the program flowchart to represent the algorithm for module BatchCheck().
START
END
Is
Index = 1001 ?
Yes
No
[5]
,
,
,
,
Show mark scheme
3(a)(i)
Example solution using AND
IF Batch[ThisIndex].Weight >= Min AND
Batch[ThisIndex].Weight <= Max THEN
Alternative solution using OR
IF Batch[ThisIndex].Weight < Min OR
Batch[ThisIndex].Weight > Max THEN
Mark as follows:
1. Reference to
Batch[ThisIndex].Weight
2. A valid
check for one boundary
3. A valid check for other boundary with correct logic operator
IF Batch[ThisIndex].Weight >= Min AND
Batch[ThisIndex].Weight <= Max THEN
Alternative solution using OR
IF Batch[ThisIndex].Weight < Min OR
Batch[ThisIndex].Weight > Max THEN
Mark as follows:
1. Reference to
Batch[ThisIndex].Weight
2. A valid
check for one boundary
3. A valid check for other boundary with correct logic operator
3(a)(ii) [5 marks]
One mark for either:
Set the
field to an empty string / NULL / invalid value
Item_ID
Set
to <= 0 / zero
Weight
Set the
field to an empty string / NULL / invalid value
Item_ID
Set
to <= 0 / zero
Weight
3(b) [6 marks]
ne 1
Zo
ne 2
Zo
ne 3
Zo
ne 4
Zo
ne
5
Zo
One mark per zone
Zo
ne 2
Zo
ne 3
Zo
ne 4
Zo
ne
5
Zo
One mark per zone