Data types, records, arrays and abstract data types – A Level Computer Science (9618)
80 questions · page 1 of 6 · Clear filters
Question text
1
A program is being developed to meet a particular customer requirement.
(a) The program contains these variables:
Variable
Data type
MyChar
CHAR
MyString
STRING
MyInt
INTEGER
MyDOB
DATE
Complete the table by filling in the gaps using functions and/or operators from the insert.
Each expression must be valid.
Expression
MyString
'X' … MyString
MyChar
… ("ABCD", … , … )
MyString
… ( … (MyDOB))
MyInt
… ( … (MyString) / 2)
[4]
(b) Different test methods will be used at different stages of the program development.
Complete the table by identifying the test method that matches the test description.
The first row has been completed for you.
Test description
Test method
carried out as soon as a program module has been coded
alpha
carried out as program modules are being combined
completed by the developers without referring to the code
completed by the customer
[3]
ĬÕĊ®Ġ´íÈõÏĪÅĊßû¸þ×
,
,
(c) During the alpha testing stage, an Integrated Development Environment (IDE) is used to help
locate an error that has been identified. The IDE report window feature is used to examine
the values assigned to variables.
Explain how two other IDE features are used together with the report window feature to help
locate the error.
…
…
…
…
…
… [3]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊßù¸þ×
Question text
2
Data is a global 1D array containing 30 elements of type STRING
An algorithm will output:
•
all non-blank elements (elements that do not contain an empty string)
•
the final total of the number of elements output.
Complete the program flowchart to represent the algorithm:
START
END
[5]
ĬÕĊ®Ġ´íÈõÏĪÅĊÝû¸Ā×
Question text
3
A program is needed to manage individual rentals in a car-hire business.
The data items for each rental will be held in a record structure of type RentalRecord
The programmer has started to define the items that will be needed:
Item
Example value
Comment
RentalID
"AB1234"
a unique alpha-numeric value
CarID
241
a numeric value used as an array index
DisCode
'S'
a letter indicating the type of discount offered
Start
13/06/2025
when the rental starts
Duration
7
the number of days of the rental
Completed
FALSE
TRUE when the car is returned and the rental charge paid
(a) (i)
Write pseudocode to declare the record structure for type RentalRecord
…
…
…
…
…
…
…
… [4]
(ii)
A 1D array Rental containing 500 elements is used to store the data for all rental records.
Write pseudocode to declare the Rental array.
…
… [2]
(b) State three benefits of using an array of records to store the data for all rentals.
1 …
…
2 …
…
3 …
…
[3]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÝù¸Ā×
[Turn
over
Question text
4
A program contains a global 1D array Number consisting of 20 elements of type REAL
A procedure Store() will input a sequence of up to 20 real values, one value at a time. These
values will be assigned to elements of the array using four steps:
Step 1: store the first value in the sequence in the first element of the array
Step 2: check each subsequent value input. If this value is larger than the previous value input,
then assign the value to the next array element, otherwise go to step 4
Step 3: repeat from step 2 unless the array is full
Step 4: output the count of the number of values stored in the array together with a suitable
message.
(a) Complete the pseudocode for Store()
All variables used in the algorithm must be declared.
PROCEDURE Store()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
ENDPROCEDURE
[6]
ĬÙĊ®Ġ´íÈõÏĪÅĊàùµþ×
,
,
(b) The requirements of the program change:
•
the number of values in the sequence is unknown, but may be higher than 20
•
the values will need to be accessed by another program as data.
The data will be stored in a text file instead of an array.
(i)
Give two benefits of using a text file instead of an array.
1 …
…
Question text
6
Students are learning about a simple check digit method for data validation. In this method, a
single check digit is appended to the end of an original number to give a new number.
The students are studying a method which:
•
calculates the sum of all the digits in the original number
•
uses integer division to calculate the remainder when the sum is divided by 10
•
uses the remainder as the check digit
•
appends the check digit to the original number, creating the new number.
For example:
original number
4162
sum of all digits
4 + 1 + 6 + 2 = 13
remainder when the sum is divided by 10 using integer division
3
new number
41623
The method described can be used to detect single-digit errors. For example, if the new number
is incorrectly input as 41633, then the check digit does not match and the input will be rejected.
(a) An incorrect attempt was made to enter 41623. The first two digits were entered incorrectly;
the last three digits were entered correctly.
When this number was tested, the check digit was found to be correct and the input was
accepted.
Identify an example of the incorrect attempt to enter 41623 and explain why this number
would not be rejected.
Number …
Explanation …
…
[2]
ĬÙĊ®Ġ´íÈõÏĪÅĊßù·þ×
,
,
(b) A module Generate() will take an integer value representing an original number and return
an integer value representing a new number which includes the check digit.
The original number is always at least three digits in length.
Write pseudocode for the module Generate()
Assume that the parameter is valid.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
8
A program is being developed to manage student book loans from a college library. Students may
borrow up to five books at a time from the library.
The programmer has defined a record type to define each loan.
The record data items are:
Data item
Data type
Comment
StudentID
STRING
the unique ID of the student who has borrowed the book
BookID
STRING
the unique ID of the book being borrowed
OnLoan
BOOLEAN
TRUE if the book has not been returned
The programmer has defined a global array Loan to store 5000 loan records.
There are more elements in the array than books in the library. Unused elements have the
StudentID set to an empty string. These may occur anywhere in the array.
The programmer has defined the first program module:
Module
Description
•
called with a parameter of type STRING representing a
StudentID
•
OKToBorrow()
search the array for loan records for the specified student
•
output a suitable message to say whether the student may, or
may not, borrow another book
ĬÕĊ®Ġ´íÈõÏĪÅĊÞü¶Ă×
,
,
(a) Write efficient pseudocode for the module OKToBorrow()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
2
Data is a global 1D array containing 20 elements of type REAL
An algorithm will:
•
input a sequence of real values, one at a time
•
assign each value to consecutive array elements, starting from index 1
•
end when the value 99.9 is input, or all 20 elements have been assigned (the value 99.9 must
not be stored in the array).
Complete the program flowchart to represent the algorithm:
START
END
[5]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÞû¸þ×
Question text
3
A text file OldFile.txt contains IDs, names and email addresses for members of a club. Three
information items are stored for each member and each item is stored on a separate line.
The example shows the information for the first two members in the first six lines of the file:
Line in file
Information item
Example data
"AB1234"
1
member 1 ID
"Freddie Jones"
2
member 1 name
"[email protected]"
3
member 1 email address
"BC2345"
4
member 2 ID
"Sue Smith"
5
member 2 name
"[email protected]"
6
member 2 email address
The member ID string is always two letters followed by four digits.
The file design is to be changed so that information for each user is stored as a single line of the
file, with the character '\' used as a separator between data items.
For example, the single line for member 1 will be:
"AB1234\Freddie Jones\[email protected]"
An algorithm will produce a new file NewFile.txt from the contents of OldFile.txt
Assume:
•
LineX, LineY and LineZ are of type STRING and are used to store the three items of
information for each member
•
NewString is a temporary variable of type STRING
•
OldFile.txt exists and contains valid data.
(a) The algorithm to create the new file is expressed in steps.
Complete the following numbered steps:
Step 1 :
open the file … in …
Step 2 :
open the file … in …
Step 3 :
read a line from … and store in …
Step 4 :
read a line from … and store in …
Step 5 :
read a line from … and store in …
Step 6 :
set NewString to …
Step 7 :
write NewString to …
Step 8 :
repeat from step … until …
Step 9 :
close both files.
[6]
ĬÕĊ®Ġ´íÈõÏĪÅĊàù¸Ā×
,
,
(b) The character '\' has been chosen as a separator.
Explain why this is a suitable character.
…
… [1]
(c) Two new information items are to be stored for each member. Both new items are encrypted;
they can each contain any character (including '\') and can be of any length up to a
maximum of 99 characters.
For example:
Information item
Example data
"AB1234"
member 1 ID
"Freddie Jones"
member 1 name
"[email protected]"
member 1 email address
"En/98&*(|?\/D7iP"
member 1 new information 1
"23\CoboL"
member 1 new information 2
Explain the additional file design changes needed so that:
•
all the information items for each member are stored on a single line of NewFile.txt
•
it is possible to extract each information item after the line is read.
Assume the '\' character is not used in any email address.
…
…
…
…
…
Question text
4
A quiz has nine questions. There are:
•
five easy questions each worth 3 points
•
four hard questions each worth 5 points.
At the end of the quiz the points for each correctly answered question are added to give a total
score.
A check is made to test that the total score is valid using a 1D array CheckTotal of type BOOLEAN.
Each index value of the array represents a possible total score. The corresponding element value
is TRUE if the index value represents a valid total score and FALSE otherwise.
The first nine rows of the array are:
Index
Element
Comment
value
value
TRUE
0
valid total score (no correct answers)
FALSE
1
invalid total score
FALSE
2
invalid total score
TRUE
3
valid total score (one 3-point question correct)
FALSE
4
invalid total score
TRUE
5
valid total score (one 5-point question correct)
TRUE
6
valid total score (two 3-point questions correct)
FALSE
7
invalid total score
TRUE
8
valid total score (one 3-point question and one 5-point question correct)
For example, a total score of 6 points is valid; the value of the array element at index value 6 is TRUE
(a) Write pseudocode to declare CheckTotal and to set all elements of the array to FALSE
All variables used must be declared.
…
…
…
…
…
…
…
… [4]
ĬÙĊ®Ġ´íÈõÏĪÅĊÝûµþ×
,
,
(b) The pseudocode represents an algorithm to set the appropriate elements of the array to TRUE
Complete the pseudocode:
DECLARE EasyQ, HardQ : INTEGER
… TO 15 STEP …
FOR EasyQ
0 TO … STEP …
FOR HardQ
TRUE
CheckTotal[ … ]
NEXT HardQ
NEXT EasyQ
[5]
(c) The array elements have been assigned the required values.
A module ValidateScore() will take an integer value representing a total score as a
parameter. It will return TRUE if the total score is valid, or FALSE if it is not valid.
Describe the algorithm for ValidateScore() using four steps.
Do not use pseudocode in your answer.
Step 1 …
…
Step 2 …
…
Step 3 …
…
Question text
7
The structure chart shows part of a program design:
Convert
Count
P2
T1
Key
Analyse
Update
Sort
(a) Explain the meaning of the curved arrow symbol in this structure chart.
…
…
…
… [2]
(b) The program designer has noted that:
•
Count is the number of elements in an array
•
T1 is a value representing the number of elements in an array that have been modified
•
Key is of type STRING
Write the pseudocode module headers for analyse, update and sort.
Analyse:
…
…
Update:
…
…
Sort:
…
…
[4]
ĬÙĊ®Ġ´íÈõÏĪÅĊàû·Ā×
Question text
8
A program is being developed to manage student book loans from a college library.
The programmer has defined a record type to define each loan.
The data items are:
Data item
Data type
Comment
StudentID
STRING
the unique ID of the student who has borrowed the book
BookID
STRING
the unique ID of the book being borrowed
OnLoan
BOOLEAN
TRUE if the book has not been returned
The programmer has defined a global array Loan to store 7000 loan records.
There are more elements in the array than books in the library. Unused elements have the
StudentID set to an empty string. These may occur anywhere in the array.
The programmer has defined a program module:
Module
Description
•
called with a parameter of type STRING representing a
StudentID
•
counts the number of books currently on loan to the
specified student
CountLoans()
•
counts the number of books that the student has already
returned
•
output both counts together with a suitable message
ĬÕĊ®Ġ´íÈõÏĪÅĊßú¶Ă×
,
,
(a) Write pseudocode for module CountLoans()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
2
(a) A program contains a global 1D array of type STRING containing 65 elements.
An existing text file is used to store the data in the array. Only non-blank elements (those that
do not contain an empty string) are written to the text file.
An algorithm will:
•
write the first element of the array as a new line in the text file
•
continue until all elements have been written, each to a new line of the text file.
Stepwise refinement is applied to the algorithm.
Describe up to six steps for this algorithm that could be used to produce pseudocode.
Do not use pseudocode statements in your answer.
Step 1 …
…
Step 2 …
…
Step 3 …
…
Step 4 …
…
Step 5 …
…
Step 6 …
…
[6]
(b) Iteration is one programming construct.
Identify one other programming construct that will be required when the algorithm from part
(a) is converted into pseudocode and explain how it is used.
Construct …
…
Use …
…
[2]
ĬÍĊ¾Ġ´íÈõÏĪÅĊÞû·Ā×
Question text
3
A program uses a stack to hold up to 30 integer values. The stack is implemented using a global
integer variable and a global 1D array.
The array is declared in pseudocode:
DECLARE ThisStack : ARRAY[1:30] OF INTEGER
Stack design notes:
•
The global variable SP acts as a stack pointer. SP contains the array index of the last value
pushed onto the stack.
•
If the stack is empty, then SP is assigned the value zero.
•
The first item added to the stack will be stored in ThisStack[1]
•
SP is incremented each time an item is added to the stack.
A function Pop() is written to remove an item from ThisStack. The function returns an item of
type PopData which is defined in pseudocode:
TYPE PopData
DECLARE Data
: INTEGER
DECLARE Exists : BOOLEAN
ENDTYPE
The value removed from the stack is assigned to Data and Exists is set to TRUE. If it is not
possible to remove a value from the stack, then Exists is set to FALSE
Complete the pseudocode for Pop()
FUNCTION Pop() RETURNS PopData
DECLARE ThisPop : …
IF … THEN
… // Stack is empty
PopData.Exists
ELSE
…
PopData.Data
…
PopData.Exists
…
SP
ENDIF
RETURN ThisPop
ENDFUNCTION
[5]
ĬÑĊ¾Ġ´íÈõÏĪÅĊßù¶þ×
Question text
4
A program contains a global 1D array Data containing 20 elements of type INTEGER
A global string NumString represents a sequence of three-digit numbers, separated by commas.
For example:
"101,456,219,754,328"
The string contains at least four three-digit numbers. The total number of three-digit numbers in
the string is unknown.
A procedure Store() will:
•
extract one three-digit number at a time from NumString
•
convert each of the three-digit numbers extracted to an integer and assign this to the next
array element, starting from index 1
•
end when all three-digit numbers have been stored, or when the array is full.
Complete the pseudocode for Store()
All local variables used must be declared.
PROCEDURE Store()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
ENDPROCEDURE
[6]
ĬÑĊ¾Ġ´íÈõÏĪÅĊÝù¶Ā×
,
,
ĬÓĊ¾Ġ´íÈõÏĪÅĊÝû¶Ā×
Question text
5
A global 1D array Num of integers contains four elements. A program assigns values to these
elements as shown:
1
Num[1]
2
Num[2]
5
Num[3]
3
Num[4]
A procedure Process() manipulates the values in the array.
The procedure is written in pseudocode:
PROCEDURE Process(Start : INTEGER)
DECLARE CaseVar, Index, Count : INTEGER
Start
Index
0
Count
WHILE Count <= 20
CaseVar Num[Index]
CASE OF CaseVar
1 : Num[Index] Num[Index] + Index //clause one
Index Index + 1
Count Count + 1
2 : Num[Index] Num[Index] + Index //clause two
Index Index + 2
Count Count + 2
3 : Num[Index] Num[Index] * 2
//clause three
Index Index + 3
Count Count - 1
4 : Count Count + 4
//clause four
OTHERWISE : Count 20
ENDCASE
(Index MOD 4) + 1
Index
ENDWHILE
ENDPROCEDURE
ĬÑĊ¾Ġ´íÈõÏĪÅĊàù¸þ×
,
,
(a) Complete the trace table by dry running the procedure when it is called in the statement:
CALL Process(1)
Index
CaseVar
Count
Num[1]
Num[2]
Num[3]
Num[4]
[5]
ĬÓĊ¾Ġ´íÈõÏĪÅĊàû¸þ×
,
,
(b) As a reminder, the CASE structure in the pseudocode is:
CASE OF CaseVar
1 : Num[Index] Num[Index] + Index //clause one
Index Index + 1
Count Count + 1
2 : Num[Index] Num[Index] + Index //clause two
Index Index + 2
Count Count + 2
3 : Num[Index] Num[Index] * 2
//clause three
Index Index + 3
Count Count - 1
4 : Count Count + 4
//clause four
OTHERWISE : Count 20
ENDCASE
The CASE structure could be optimised by combining two existing clauses.
(i)
Identify the CaseVar values for these two existing clauses.
… [1]
(ii)
Write pseudocode for a single clause to replace the two clauses identified in (b) (i).
…
…
… [2]
ĬÑĊ¾Ġ´íÈõÏĪÅĊÞù¸Ā×