Programming – A Level Computer Science (old syllabus, to 2021) (9608)

130 questions · page 7 of 9 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
91
9608/22/M/J/18 · Question 3May/June 2018Paper 2211 marks
Loading question…
Question text

3
A chocolate factory produces bars of chocolate. A computer program controls the process.
The weight of each bar is stored in an array, BarWeight. The array contains 100 elements,
representing the weights of 100 bars that make up one shipping box.
A procedure, CheckWeight(), is required to:
1.
examine each array element and count how many times the weight has exceeded MaxWeight
2.
compare the count obtained with a limit value, Threshold. Call procedure ServiceCheck()
if the count exceeds the Threshold
3.
output a message if the count does not exceed the Threshold. For example:
"ShippingBox OK – maximum weight exceeded 3 times."
Draw a program flowchart on the next page to represent the algorithm for the CheckWeight()
procedure.
Assume that:
•
the array contains 100 valid weight values and the first element is BarWeight[1]
•
MaxWeight, Threshold and BarWeight are global variables.
Variable declarations are not required in program flowcharts.
[10]
Question 4 begins on the next page.

92
9608/22/M/J/18 · Question 4May/June 2018Paper 225 marks
Loading question…
Question text

4
The structure chart shows part of the design of a program for an online shopping system.
Process basket
B
E
A
C
F
D
G
Change item
Discard basket
Checkout
quantity
(remove all items)
(pay and despatch)
(a) (i)
Draw on the chart to show the following facts.
•
Each of the modules at the lower level returns a Boolean parameter, X.
•
Process basket will call only one of the modules shown at the lower level.
[2]
(ii)
The parameters A to G shown on the chart will be used to pass the following information.
PaymentDetails
Quantity
BasketID
DeliveryAddress
ItemID
Complete the following table to show the parameter and the information it represents.
Parameter
Information
A
B
C
D
E
F
G
[3]

93
9608/22/M/J/18 · Question 5May/June 2018Paper 2218 marks
Loading question…
Question text

5
A golf club holds information about its members. When a member completes a round of golf, their
score is stored along with their membership number and the date of the round.
A program is to be written to store and process the score information. The information to be stored
is formed into a string as follows:
<MembershipNumber><Date><Score>
(a) The program designer considers storing the strings in either a 1D array, RoundScore or
as a separate variable for each round, for example, RoundScore01, RoundScore02,
RoundScore03 and so on.
Describe two advantages of storing the strings in a 1D array rather than as separate variables.
Advantage 1 …
…
Advantage 2 …
…
[2]
(b) A procedure, AddNewScores() is being developed. The procedure will be coded using
an Integrated Development Environment (IDE).
Name two features provided by an IDE that assist in the initial detection of errors in the
procedure.
Feature 1 …
…
Feature 2 …
…
[2]
(c) The program needs a function, GetNumber(), to return a valid membership number. A valid
membership number is a four-digit numeric string between “1111” and “9999”.
The structured English representing the algorithm for this function is as follows:
1.
Prompt and input a membership number.
2.
Validate the membership number.
3.
Repeat from step 1 if the membership number is invalid.
4.
Return the valid membership number as a string.
An example of the function call in pseudocode is:
GetNumber()
MembershipNumber
Write program code for the GetNumber() function.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…

Advertisement
94
9608/23/M/J/18 · Question 1May/June 2018Paper 2314 marks
Loading question…
Question text

1
(a) A program controls the heating system of an energy-efficient house.
Give a suitable identifier name for each of the data items.
Description of data item
Suitable identifier name
The temperature inside the house
The temperature outside the house
The wind speed
Whether it was raining or not
[4]
(b) (i)
Program variables have values as follows:
Variable
Value
Quality
'D'
DayNumber
20
MyName
"Stephen"
QualityConfirmed
TRUE
Factor
6.5
Evaluate each expression in the following table.
If an expression is invalid, write ERROR.
For the built-in functions list, refer to the Appendix on page 15.
Expression
Evaluates to
MID(MyName, 4, 4) & "ol"
QualityConfirmed AND (Factor >= 6.5)
20 + ASC(Quality)
QualityConfirmed + 3
MOD(Factor * 2, 9)
[5]
(ii)
Programming languages support different data types.
Give an appropriate data type for each of these variables from part (b)(i).
Variable
Data type
QualityConfirmed
DayNumber
Factor
Quality
MyName
[5]

95
9608/23/M/J/18 · Question 2May/June 2018Paper 2317 marks
Loading question…
Question text

2
The following is a function design in pseudocode.
Line numbers are given for reference only.
01
FUNCTION GradeCalc(Mark : ARRAY[] OF INTEGER) RETURNS INTEGER
02
03
DECLARE
DGradeCount : INTEGER
04
DECLARE
n : INTEGER
05
DECLARE
Grade : STRING
06
DECLARE
ThisMark : INTEGER
07
0
// initialise variables
08
DGradeCount
1
09
n
1
10
ThisMark
11
REPEAT
Mark[n]
// get next mark from Mark array
12
ThisMark
13
14
IF ThisMark > 74
15
THEN
"Distinction"
16
Grade
DGradeCount + 1 // one more Distinction
17
DGradeCount
18
ELSE
19
IF ThisMark > 59
20
THEN
"Merit"
21
Grade
22
ELSE
23
IF ThisMark > 39
24
THEN
"Pass"
25
Grade
26
ELSE
"Fail"
27
Grade
28
ENDIF
29
ENDIF
30
ENDIF
31
32
OUTPUT "Grade for Student " & n & " is " & Grade
33
n + 1
34
n
35
UNTIL n = 101 // no more elements in the array
36
37
RETURN Grade // return the number of Distinction grades
38
39
ENDFUNCTION
40
41
DECLARE Mark : ARRAY[1:100] OF INTEGER
42
DECLARE DistinctionGrades : INTEGER
43
44
CALL GetMarks(Mark[]) // fill the array with student marks
GradeCalc(Mark[])
45
DistinctionGrades
(a) This pseudocode includes features that are examples of good practice.
Explain why it is useful to include the two following features.
Comments …
…
Indentation …
…
[2]
(b) Study the function GradeCalc(). Identify the features of the function in the following table.
Feature
Answer
A line number containing an example of an integer assignment statement
A line number containing the start of a selection structure
A line number containing the end of a selection structure
The upper bound of the Mark array
The number of dimensions of the Mark array
The name for the type of loop structure used
A line number containing an unnecessary assignment statement
The number of times OUTPUT is called
The number of local variables
[9]
(c) (i)
There is a mistake in the pseudocode that would produce a data type mismatch error if a
programmer were to write similar program code.
Describe this mistake and how it may be corrected.
…
…
…
… [2]
(ii)
Lines 14 to 30 of the pseudocode on page 4 could be written using a CASE structure.
Write the equivalent CASE structure in pseudocode.
…
…
…
…
…
…

96
9608/23/M/J/18 · Question 3May/June 2018Paper 235 marks
Loading question…
Question text

3
A modular program design consists of four modules:
Module1 has three sub-tasks. Each sub-task is implemented by a single subroutine (either a
function or a procedure).
The subroutine headings are defined as follows:
FUNCTION Module2 (Weight : REAL) RETURNS BOOLEAN
PROCEDURE Module3 (Weight : REAL, Customer : STRING, Purchased : DATE)
FUNCTION Module4 (Purchased : DATE, Account : INTEGER) RETURNS INTEGER
(a) State the term given to values passed between modules.
… [1]
(b) Draw a structure chart to represent the program design.
Use the letters in the table to label the values passed between modules.
Value
Label
Boolean return value
A
Integer return value
B
C
Account
D
Customer
E
Purchased
F
Weight
Structure chart
[4]

97
9608/23/M/J/18 · Question 4May/June 2018Paper 2310 marks
Loading question…
Question text

4
A program controls a chemical process in a factory.
The temperature is monitored as part of the control process. The temperature is measured at
fixed time intervals and the value is stored in an array, PTemp. The array contains 100 elements,
representing 100 temperature values. The first element is PTemp[1].
The program will check whether the temperature is outside the acceptable range more than 20
times. This task is performed by a function, IsTempOK().
The algorithm for the function IsTempOK() is expressed in structured English as follows:
1
Examine each array element and count the number of times that a temperature is less than
MinTemp or more than MaxTemp.
2
If the count in step 1 exceeds 20, return FALSE, otherwise return TRUE.
Draw a program flowchart, on the next page, to represent the algorithm for the function
IsTempOK().
Assume:
•
the array contains 100 valid temperature values
•
PTemp, MinTemp and MaxTemp are global variables.
Note that variable declarations are not required in program flowcharts.
[9]

98
9608/23/M/J/18 · Question 6May/June 2018Paper 2310 marks
Loading question…
Question text

6
(a) Individual elements in a 1D array are referenced using an integer variable.
For example, using the variable n, an individual element would be referenced in pseudocode
as:
StudentGrade[n]
Give the correct technical term for the variable n.
… [1]
(b) A 2D array, Picture, contains data representing a bitmap image. Each element of the array
represents one pixel of the image. The image is grey-scale encoded where the value of each
pixel ranges from 0 (representing black) to 255 (representing white) with intermediate values
representing different levels of grey.
The following is an example of an image and the corresponding data values for the Picture
array.
Bitmap image
Values
240 10
10
10
10
10
10 240
80
80 240 80
80 240 80
80
80
80 240 80
80 240 80
80
80
80 150 150 150 150 80
80
80
80 240 240 240 240 80
80
80
80 150 150 150 150 80
80
240 240 150 150 150 150 240 240
240 240 150 150 150 150 240 240
In pseudocode, the array is declared as follows:
DECLARE Picture : ARRAY[1:8, 1:8] OF INTEGER
A function, Clip(), is required that will:
•
take an integer parameter, MaxVal, to represent the maximum allowed value for each
pixel
•
limit each pixel value to the maximum allowed value
•
return TRUE if any of the pixel values have been changed, otherwise return FALSE
An example use of the function is:
Clip(234)
IsClipped
This will limit the maximum pixel value within the array to 234. Pixels with a value not greater
than 234 will remain unchanged.
Write pseudocode to implement the Clip() function.
Assume that Picture is a global variable.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement
99
9608/23/M/J/18 · Question 7May/June 2018Paper 236 marks
Loading question…
Question text

7
A function, IsFactor() takes two integer parameters and checks whether the second parameter
is a factor of the first parameter.
For example IsFactor(6,3) would return TRUE as six divided by three has a remainder of zero.
This function returns FALSE if there is a non-zero remainder, or if the value of the second
parameter is zero.
Write program code to implement the IsFactor() function.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING
returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns string "BCD"
LENGTH(ThisString : STRING) RETURNS INTEGER
returns the integer value representing the length of string ThisString
Example: LENGTH("Happy Days") returns 10
LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING
returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns string "ABC"
RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING
returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns string "FGH"
INT(x : REAL) RETURNS INTEGER

100
9608/21/O/N/17 · Question 1Oct/Nov 2017Paper 2117 marks
Loading question…
Question text

1
(a) (i)
Procedural high-level languages usually support different data types.
Give an appropriate data type for each data value in the following table.
Data value
Data type
27
"27"
"27.3"
TRUE
27/3/2015
27.3
[6]
(ii)
State an appropriate data structure to store the individual test scores for a class of
students.
… [1]
(iii)
Describe how characters are represented using the ASCII character set.
…
…
…
… [2]
(b) Functions and procedures are subroutines.
Explain why you should use subroutines when designing a program solution.
…
…
…
… [2]
(c) The following pseudocode is an example of nested IF statements.
IF MyVar = 1
THEN
CALL Proc1()
ELSE
IF MyVar = 2
THEN
CALL Proc2()
ELSE
IF MyVar = 3
THEN
CALL Proc3()
ELSE
OUTPUT "Error"
ENDIF
ENDIF
ENDIF
Use pseudocode to write a CASE statement with the same functionality.
…
…
…
…
…
…
…
… [4]
(d) Program coding is a transferable skill.
You are given program code written in a high-level language that you have not studied.
State two different features of the code that you should be able to recognise.
1 …
…
2 …
…

101
9608/21/O/N/17 · Question 2Oct/Nov 2017Paper 2116 marks
Loading question…
Question text

2
The following pseudocode represents a simple algorithm.
DECLARE NumberFound, Remainder, Number : INTEGER
DECLARE StartNumber, EndNumber, Divisor : INTEGER
INPUT StartNumber
INPUT EndNumber
INPUT Divisor
0
NumberFound
StartNumber TO EndNumber
FOR Number
MODULUS(Number, Divisor)
Remainder
IF Remainder = 0
THEN
OUTPUT Number
NumberFound + 1
NumberFound
ENDIF
ENDFOR
OUTPUT "Count: " & NumberFound
For the built-in functions list, refer to the Appendix on page 14.
(a) Complete the following trace table.
StartNumber
EndNumber
Divisor
NumberFound
Number
Remainder
Output
11
13
2
0
[3]
(b) Describe the purpose of this algorithm.
…
…
…
…
…
… [3]
(c) Draw a program flowchart to represent this algorithm.
Variable declarations are not required in program flowcharts.
[10]

102
9608/21/O/N/17 · Question 3Oct/Nov 2017Paper 2123 marks
Loading question…
Question text

3
(a) A multi-user computer system stores information about users. It uses a 1D array,
UserNameArray, of type STRING. There are 100 elements in the array.
The format of the string in each element of the array is as follows:
<UserID><UserName>
•
UserID is a six-character string of numerals.
•
UserName is a variable-length string.
Write pseudocode for a procedure, BubbleSort, to perform an efficient bubble sort on
UserNameArray. The array is to be sorted in ascending order of UserID.
You should assume that UserNameArray has been declared as a global variable.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

103
9608/21/O/N/17 · Question 4Oct/Nov 2017Paper 215 marks
Loading question…
Question text

4
Numeric formatting converts a numeric value to a string in order to present it in a specific way.
In a generic high-level language, formatting is implemented using a mask system. In this system,
each character of the mask corresponds to one character of the formatted string.
Mask characters have the following meaning:
Mask character
Meaning
Character must be a digit or a space
#
Character must be a digit
0
Any other mask characters are taken as literal values and are included in the formatted string.
(a) Using the mask "###00.00", complete the following table. Use □ to represent a space. The
first value has been done for you.
Value
Formatted string
1327.5
"□1327.50"
1234
7.456
[2]
(b) For each row in the following table, define the mask required to produce the formatted output
from the given value. □ represents a space.
Value
Required output
Mask
1234.00
"1,234.00"
3445.66
"£3,445.66"
10345.56
"$□ □10,345"
[3]

Advertisement
104
9608/21/O/N/17 · Question 5Oct/Nov 2017Paper 2114 marks
Loading question…
Question text

5
A sports club maintains a record of the email address of each of its members. The details are
stored in a text file, EmailDetails.txt. The format of each line of the text file is as follows:
<MembershipNumber><EmailAddress>
•
MembershipNumber is a four-character string of numerals.
•
EmailAddress is a variable-length string.
Membership of the club has increased and a four-character membership number is no longer
adequate.
A procedure, MakeNewFile, is required to perform the following actions:
1.
Create a new file, NewEmailDetails.txt
2.
Read a line from file EmailDetails.txt
3.
Extend MembershipNumber by adding two leading zero digits (for example, "1234"
becomes "001234")
4.
Write the new line to file NewEmailDetails.txt
5.
Repeat steps 2 to 4 for all lines in the original file.
(a) Write pseudocode for the procedure MakeNewFile.
For the built-in functions list, refer to the Appendix on page 14.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [8]
(b) A function, IsEmailValid, is to be written to test for a valid email address format.
An email address has a valid format if it obeys the following three rules:
1.
It contains a single ‘@’ symbol.
2.
The ‘@’ symbol must be preceded by at least one character.
3.
The ‘@’ symbol must be followed by at least three characters.
Choose three different invalid strings to test distinct aspects of the rules.
Explain your choice in each case.
1 …
Explanation …

105
9608/22/O/N/17 · Question 1Oct/Nov 2017Paper 2223 marks
Loading question…
Question text

1
(a) (i)
Procedural high-level languages usually support different data types.
Give an appropriate data type for each data value in the following table:
Data value
Data type
FALSE
03/03/2013
35
"INTEGER"
3.5
"35"
[6]
(ii)
The following is a declaration in a high-level language:
DEFINE MyGrade[1 to 100]
State the data structure of variable MyGrade.
… [1]
(iii)
An experienced programmer is presented with program code in an unfamiliar high-level
language.
State two features of the code that the programmer should be able to recognise.
1 …
…
2 …
…
[2]
(b) (i)
In the ASCII character set ‘A’ is represented by the value 65. The values representing the
other characters of the alphabet follow in sequence, so ‘B’ is represented by 66, ‘C’ by 67
and so on.
The following table represents consecutive memory locations. Each memory location
stores one byte.
Complete the table to show how the string "CAGE" may be stored in memory using the
ASCII set.
Address
Data
100
101
102
103
104
105
[2]
(ii)
In a high-level language, a LENGTH function is used to return the number of characters in
a string.
Explain what is stored in addition to the string characters to allow this function to
determine this number.
…
…
…
… [2]
(c) Functions and procedures are subroutines.
Explain why parameters are used with subroutines.
…
…
…
…
…
… [3]
(d) The following pseudocode is an example of a CASE structure.
CASE OF MyMark
"Distinction"
75 to 100: MyGrade
"Pass"
35 to 74: MyGrade
"Fail"
0 to 34: MyGrade
OTHERWISE: OUTPUT "Invalid value entered"
ENDCASE
(i)
Describe what will happen if the pseudocode is tested when MyMark has the following
values:
27 …
…

Advertisement