Programming – A Level Computer Science (9618)
153 questions · page 8 of 11
Question text
8
A computer shop assembles computers using items bought from several suppliers. A text file
Stock.txt contains information about each item.
Information for each item is stored as a single line in the Stock.txt file in the format:
<ItemNum><SupplierCode><Description>
Valid item information is as follows:
Format
Comment
unique number for each item in the range
ItemNum
4 numeric characters
″0001″ to ″5999″ inclusive
SupplierCode
3 alphabetic characters
to identify the supplier of the item
Description
a string
a minimum of 12 characters
The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.
A programmer has started to define program modules as follows:
Module
Description
•
called with a parameter of type string
OnlyAlpha()
(already written)
•
returns TRUE if the string contains only alphabetic characters,
otherwise returns FALSE
CheckInfo()
•
called with a parameter of type string representing a line of item
information
•
checks to see whether the item information in the string is valid
•
returns TRUE if the item information is valid, otherwise returns
FALSE
(a) Write pseudocode for module CheckInfo().
Module OnlyAlpha() should be used as part of your solution.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
2
A program stores a date of birth for a student using a variable, MyDOB, of type DATE.
(a) MyDOB has been assigned a valid value corresponding to Kevin’s date of birth.
Complete the pseudocode statement to test whether Kevin was born on a Thursday.
… THEN [2]
IF
(b) A function CheckDate()will take three integer parameters representing a day, month and
year of a given date.
The function will validate the date of birth for a student that the parameters passed to it
represent.
For a date to be valid, a student must be at least 18 in year 2020.
(i)
Two of the parameter values can be checked without reference to the third parameter.
Describe these two checks.
Check 1 …
…
…
Check 2 …
…
…
…
[2]
(ii)
Several values of the parameter representing the day can only be checked completely
by referring to the value of one other parameter.
Describe this check.
…
…
…
… [2]
Question text
4
A function MakeString() will:
1.
take two parameters:
•
a count as an integer
•
a character
2.
generate a string of length equal to the count, made up of the character
3.
return the string generated, or return "ERROR" if the count is less than 1.
For example, the function call:
MakeString(3, 'Z') will return the string "ZZZ"
Write pseudocode for function MakeString().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
Question text
6
A procedure Select() will:
1.
take two integer values as parameters representing start and end values where both values
are greater than 9 and the end value is greater than the start value
output each integer value between the start and the end value (not including the start and
2.
end values), where the sum of the last two digits is 6, for example, 142.
(a) Write pseudocode for procedure Select().
Parameter validation is not required.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [7]
(b) The check performed by procedure Select() on the last two digits is needed at several
places in the program and will be implemented using
Question text
7
A school has a library system which allows students to borrow books for a length of time.
Information relating to students and books is stored in text files. Student information includes
name, home address, email address, date of birth, tutor and subject choices. Book information
includes author, title, subject category, library location and the date that the book was borrowed.
A program helps the staff to manage the borrowing of books.
(a) A new module needs to be written to generate emails to send to students who have an
overdue book. Students who are sent an email are prevented from borrowing any more books
until the overdue book is returned.
The process of abstraction has been used when designing the new module.
(i)
State the purpose of applying abstraction to this problem.
…
… [1]
(ii)
Identify one item of information that is required and one item that is not required in the
new module. Justify your choices.
Item required …
Justification …
…
…
Item not required …
Justification …
…
…
[2]
(iii)
Identify two operations that would be required to process data when an overdue book is
returned.
Operation 1 …
…
Operation 2 …
…
[2]
(b) Part of the library program contains program modules with headers as follows:
Pseudocode module header
PROCEDURE Module-X()
PROCEDURE Module-Y(BYREF RA : INTEGER, SA : REAL)
PROCEDURE Overlay()
FUNCTION Replace(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN
FUNCTION Reset(TA : STRING) RETURNS INTEGER
Module-X() and Module-Y() are both called from module Overlay().
Complete the structure chart.
[3]
Question text
8
A computer shop assembles desktop computers, using items bought from several suppliers. A text
file Stock.txt contains information about each item.
Information for each item is stored as a single line in the Stock.txt file in the format:
<ItemNum><SupplierCode><Description>
Item information is as follows:
Format
Comment
unique number for each item in the range “0001”
ItemNum
4 numeric characters
to “5999” inclusive
SupplierCode
3 alphabetic characters
code to identify the supplier of the item
Description
a string
a minimum of 12 characters
The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.
The programmer has defined the first program module as follows:
Module
Description
ChangeSupp()
• called with two parameters Code1 and Code2 of type string that represent
valid supplier codes
• creates a new file NewStock.txt from the contents of the
file Stock.txt where any reference to Code1 is replaced by Code2
• returns a count of the number of items that have had their supplier code
changed
(a) Write pseudocode for module ChangeSupp().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
(a) An algorithm includes a number of complex calculations. A programmer is writing a program
to implement the algorithm and decides to use library routines to provide part of the solution.
State three possible benefits of using library routines in the development of the program.
1 …
…
2 …
…
3 …
…
[3]
(b) The following pseudocode is part of a program that stores names and test marks for use in
other parts of the program.
DECLARE Name1, Name2, Name3 : STRING
DECLARE Mark1, Mark2, Mark3 : INTEGER
INPUT Name1
INPUT Mark1
INPUT Name2
INPUT Mark2
INPUT Name3
INPUT Mark3
(i)
The pseudocode needs to be changed to allow for data to be stored for up to 30 students.
Explain why it would be good practice to use arrays to store the data.
…
…
…
…
…
… [3]
(ii)
The following pseudocode statement includes array references:
OUTPUT "Student ", Name[Count], " scored ", Mark[Count]
State the purpose of the variable Count and give its data type.
Purpose …
…
Data type …
[2]
(c) The pseudocode statements in the following table may contain errors.
State the error in each case or write ‘NO ERROR’ if the statement contains no error.
Assume that any variables used are of the correct type for the given function.
Statement
Error
← "" THEN
IF EMPTY
← IS_NUM(-23.4)
Status
← STR_TO_NUM("37") + 5
X
← STR_TO_NUM("37" + "5")
Y
[4]
Question text
6
The following pseudocode algorithm attempts to check whether a string is a valid email address.
FUNCTION IsValid(InString : STRING) RETURNS BOOLEAN
DECLARE Index, Dots, Ats, Others : INTEGER
DECLARE NextChar : CHAR
DECLARE Valid : BOOLEAN
←
1
Index
←
0
Dots
←
0
Ats
←
0
Others
←
TRUE
Valid
REPEAT
←
MID(InString, Index, 1)
NextChar
CASE OF NextChar
←
Dots + 1
'.' : Dots
←
Ats + 1
'@' : Ats
IF Ats > 1 THEN
←
FALSE
Valid
ENDIF
←
Others + 1
OTHERWISE : Others
ENDCASE
IF Dots > 1 AND Ats = 0 THEN
←
FALSE
Valid
ELSE
←
Index + 1
Index
ENDIF
UNTIL Index > LENGTH(InString) OR Valid = FALSE
IF NOT (Dots >= 1 AND Ats = 1 AND Others > 8) THEN
←
FALSE
Valid
ENDIF
RETURN Valid
ENDFUNCTION
(a) Part of the validation is implemented by the line:
IF NOT (Dots >= 1 AND Ats = 1 AND Others > 8) THEN
State the values that would result in the condition evaluating to TRUE.
…
…
… [1]
(b) (i)
Complete the trace table by dry running the function when it is called as follows:
← IsValid("Liz.123@big@net")
Result
Index
NextChar
Dots
Ats
Others
Valid
[5]
(ii)
State the value returned when IsValid() is called using the expression shown in
part (b)(i).
… [1]
Question text
7
A simple arithmetic expression is stored as a string in the format:
<Value1><Operator><Value2>
An operator character is one of the following:
' + '
' − '
' * '
' / '
Example arithmetic expression strings:
"803+1904"
"34/7"
(a) A procedure Calculate() will:
•
take an arithmetic expression string as a parameter
•
evaluate the expression
•
output the result.
Assume:
•
the string contains only numeric digits and a single operator character
•
Value1 and Value2 represent integer values
•
Value1 and Value2 are unsigned (they will not be preceded by ' + ' or ' − ').
(i)
Write pseudocode for the procedure Calculate().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
8
A teacher is designing a program to perform simple syntax checks on programs written by
students. Student programs are submitted as text files, which are known as project files.
A project file may contain blank lines.
The teacher has defined the first program module as follows:
Module
Description
• takes the name of an existing project file as a parameter of type
string
CheckFile()
• returns TRUE if the file is valid (it contains at least 10 non-blank
lines), otherwise returns FALSE
(a) Write pseudocode for module CheckFile().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
(a) A programmer is developing an algorithm to solve a problem. Part of the algorithm would be
appropriate to implement as a subroutine (a procedure or a function).
(i)
State two reasons why the programmer may decide to use a subroutine.
1 …
…
2 …
…
[2]
(ii)
A procedure header is shown in pseudocode:
PROCEDURE MyProc(Count : INTEGER, Message : STRING)
Give the correct term for the identifiers Count and Message and explain their use.
Term …
Use …
…
…
…
[2]
(b) The algorithm in part (a) is part of a program that will be sold to the public.
All the software errors that were identified during in-house testing have been corrected.
Identify and describe the additional test stage that may be carried out before the program is
sold to the public.
Test stage …
Description …
…
…
…
…
…
[4]
(c) Part of an identifier table is shown:
Variable
Type
Example value
FlagDay
DATE
23/04/2004
CharList
STRING
"ABCDEF"
Count
INTEGER
29
Complete the table by evaluating each expression using the example values.
Expression
Evaluation
MID(CharList, MONTH(FlagDay), 1)
INT(Count / LENGTH(CharList))
(Count >= 29) AND (DAY(FlagDay) > 23)
[3]
Question text
5
Examine the following pseudocode.
IF A = TRUE THEN
IF B = TRUE THEN
IF C = TRUE THEN
CALL Sub1()
ELSE
CALL Sub2()
ENDIF
ENDIF
ELSE
IF B = TRUE THEN
IF C = TRUE THEN
CALL Sub4()
ELSE
CALL Sub3()
ENDIF
ELSE
IF C = FALSE THEN
CALL Sub3()
ELSE
CALL Sub4()
ENDIF
ENDIF
ENDIF
A programmer wants to re-write the pseudocode as four separate IF...THEN...ENDIF
statements, each containing a single CALL statement. This involves writing a single, simplified
logic expression as the condition in each statement.
Write the amended pseudocode.
1 …
…
…
2 …
…
…
3 …
…
…
4 …
…
…
[4]
Question text
6
(a) The factorial of an integer number is the product of all the integers from that number down
to 1.
In general, the factorial of n is n × (n−1) × ... × 2 × 1
For example, the factorial of 5 is 5 × 4 × 3 × 2 × 1 = 120
In this question, n will be referred to as the BaseNumber.
A function FindBaseNumber() will:
•
be called with a positive, non-zero integer value as a parameter
•
return BaseNumber if the parameter value is the factorial of the BaseNumber
•
return −1 if the parameter value is not a factorial.
For example:
Parameter value
Value returned
120
5
12
−1
6
3
1
1
FindBaseNumber(12) will return −1 because 12 is not a factorial.
You may use the rest of this page for rough working.
Write pseudocode for the function FindBaseNumber().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
2
A program is being designed for a smartphone to allow users to send money to the charity of their
choice.
Decomposition will be used to break the problem down into sub-problems.
Identify three program modules that could be used in the design and describe their use.
Module 1 …
Use …
…
…
…
Module 2 …
Use …
…
…
…
Module 3 …
Use …
…
…
…
[3]
Question text
5
(a) A text string contains three data items concatenated as shown:
<StockID><Description><Cost>
Item lengths are:
Item
Length
StockID
5
Description
32
Cost
the remainder of the string
A procedure Unpack() takes four parameters of type string. One parameter is the original
text string. The other three parameters are used to represent the three data items shown in
the table and are assigned values within the procedure. These values will be used by the
calling program after the procedure ends.
(i)
Write pseudocode for the procedure Unpack().
…
…
…
…
…
…
…
…
…
… [6]
(ii)
Explain the term procedure interface with reference to procedure Unpack().
…
…
…
… [2]
(b) The design changes and a record structure is defined to store the three data items.
A user-defined data type StockItem is created as shown:
TYPE StockItem
DECLARE StockID : STRING
DECLARE Description : STRING
DECLARE Cost : REAL
ENDTYPE
(i)
A variable LineData of type StockItem is declared.
Write the pseudocode statement to assign the value 12.99 to the Cost field of
LineData.
… [1]
(ii)
Procedure Unpack() is modified and converted to a function which takes the original
text string as the only parameter.
Explain the other changes that need to be made to convert the procedure into a function.
…
…
…
…
…