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

130 questions · page 2 of 9 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
16
9608/23/O/N/21 · Question 5Oct/Nov 2021Paper 2318 marks
Loading question…
Question text

5
A geocode string contains four alphanumeric characters, followed by the character '+' and then
two alphanumeric characters.
For example, the geocode string for the Avocado Restaurant in Cambridge UK is:
"1DFG+9N"
A website allows a user to upload a review of a restaurant.
A programmer has defined the following two arrays:
Array
Description
GeoData
•
a global 1D array of data type STRING
•
stores the geocode for each restaurant
Example:
"1DFG+9N"
GeoData[1]
Review
•
a global 1D array of data type STRING
•
stores the following data items as a single element in the array:
•
the four-character user ID of the reviewer
•
the geocode of the restaurant
•
the text of the review
•
the hash symbol (#) separates the data items in each single element
Example of a review for the Avocado restaurant submitted by user ID JH76:
"JH76#1DFG+9N#Good restaurant"
Review[1000]
Assume that:
•
both arrays are initialised with an empty string
•
both arrays can store up to 20 000 elements
•
new reviews are added in the next unused element of the Review array.
(a) The programmer writes a function CheckReview().
The design requirements of the function are shown in the following table:
Description
Parameter
Returns
•
•
•
searches the
a STRING value
the comment from the review
GeoData array to
containing the
if the geocode exists in the
determine if the user’s
user ID of the
GeoData array
latest review contains
reviewer
•
a STRING value of "LOCATION
a listed geocode
NOT FOUND" if the geocode of
the user’s review does not exist
in the GeoData array
•
a STRING value of "NO
REVIEW" if no review exists for
the user ID
Write pseudocode to complete the function CheckReview().
DECLARE GeoData : ARRAY[1:20000] OF STRING
DECLARE Review : ARRAY[1:20000] OF STRING
FUNCTION CheckReview(UserID : STRING) RETURNS STRING
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

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

2
(a) User names are stored in a text file. Each line of the file represents one name. Before a new
user name can be issued, a check has to be made to ensure that the new name is unique.
Use structured English to describe an algorithm that would prompt and input a new user
name and output a message to indicate whether or not it is unique.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(b) Complete the pseudocode expressions in the following table.
Use only the functions and operators described in the Appendix on pages 18–19.
Expression
Evaluates to
"Start"
… ("Stepwise" , … ) & "art"
"ten"
… ("Concatenate" , … , … )
12
2 * … ("Kipper")
TRUE
TRUE … FALSE
1
… (9, 2)
[5]
(c) Study the following pseudocode.
Line numbers are given for reference only.
01
PROCEDURE StringClean(InString : STRING)
02
03
DECLARE NextChar : CHAR
04
DECLARE OutString : STRING
05
DECLARE Index : INTEGER
06
""
07
OutString
08
1 TO LENGTH(InString)
09
FOR Index
10
MID(InString, Index, 1)
11
NextChar
LCASE(NextChar)
12
NextChar
13
14
IF NextChar >= 'a' AND NextChar <= 'z'
15
THEN
OutString & NextChar
16
OutString
17
ENDIF
18
19
ENDFOR
20
21
OUTPUT OutString
22
23
ENDPROCEDURE
Complete the following table by entering an appropriate answer.
Answer
The name for the type of loop used
A line number of a selection statement
The scope of OutString
The name of a function that is called
A line number containing a logical operator
[5]

18
9608/21/O/N/20 · Question 3Oct/Nov 2020Paper 2116 marks
Loading question…
Question text

3
The procedure OutputLines() outputs a number of lines from a text file.
An example of the use of the procedure is given by the following pseudocode:
CALL OutputLines(FileName, StartLine, NumberLines)
Parameter
Data type
Description
FileName
STRING
The name of the text file
StartLine
INTEGER
The number of the first line to be output
NumberLines
INTEGER
The number of lines to be output
The procedure is tested using the file MyFile.txt that contains 100 lines of text.
The procedure gives the expected result when called as follows:
CALL OutputLines("MyFile.txt", 1, 10)
(a) The procedure is correctly called with three parameters of the appropriate data types, but the
procedure does not give the expected result.
Give three different reasons why this might happen.
1 …
…
2 …
…
3 …
…
[3]
(b) Write program code for the procedure OutputLines().
Note: Parameter validation is not necessary.
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
19
9608/21/O/N/20 · Question 4Oct/Nov 2020Paper 2112 marks
Loading question…
Question text

4
A function, FormOut(), takes an integer parameter in the range 0 to 999 999 and returns a
formatted string depending on two other parameter values.
Formatting may incorporate the use of:
•
A prefix string to be added before the integer value (e.g. '$' or "Total: ")
•
A comma as a thousand-separator (e.g. "1,000")
The function will be called as follows:
FormOut(Number, Prefix, AddComma)
MyString
Parameter
Data type
Description
Number
INTEGER
The positive integer value to be formatted.
A string that will appear in front of the numeric value. Set to an
Prefix
STRING
empty string if no prefix is required.
TRUE if a comma is required in the formatted string.
AddComma
BOOLEAN
FALSE if a comma is not required in the formatted string.
(a) Fill in the tables to show two tests that could be carried out to test different aspects of the
function.
Give the expected result for each test.
TEST 1
Parameter
Value
Expected return string:
Number
…
Prefix
AddComma
TEST 2
Parameter
Value
Expected return string:
Number
Prefix
…
AddComma
[4]
(b) Write pseudocode for the function FormOut().
Refer to the Appendix on pages 18–19 for the list of built-in functions and operators.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

20
9608/21/O/N/20 · Question 5Oct/Nov 2020Paper 2120 marks
Loading question…
Question text

5
A message may contain several hashtags.
A hashtag is a string consisting of a hash character ‘#’, followed by one or more alphanumeric
characters.
A hashtag may be terminated by a space character, the start of the next hashtag, any other
non-alphanumeric character, or by the end of the message.
For example, the following message contains three hashtags:
"#Error27 is the result of #PoorPlanning by the #Designer"
The hashtags in the message are "#Error27", "#PoorPlanning" and "#Designer".
A program is being developed to process a message and extract each hashtag.
A global 1D array of strings, TagString, will store each hashtag in a single element.
Unused array elements will contain an empty string. The array will contain 10 000 elements.
A developer has started to define the modules as follows:
Module
Description
•
Called with two parameters:
•
a message string
•
an integer giving the number of the required hashtag.
For example, GetStart(Message, 3) would search
GetStart()
for the third hashtag in the string Message
•
Returns an integer value representing the start position
of the hashtag in the message string, or value −1 if that
hashtag does not exist
•
Called with two parameters:
•
a message string
•
an integer giving the hashtag start position within the
GetTag()
message
•
Returns the hashtag or an empty string if the character in
the message at the hashtag start position is not '#'
•
Called with a hashtag as a parameter
•
Returns the index position of the hashtag in array
GetIndex()
TagString
•
Returns the value −1 if the hashtag is not present in the
array
(a) Write pseudocode for the module GetIndex().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

21
9608/22/O/N/20 · Question 2Oct/Nov 2020Paper 2214 marks
Loading question…
Question text

2
(a) The following pseudocode is an attempt to define an algorithm that takes two numbers as
input and outputs the larger of the two numbers.
DECLARE A, B : INTEGER
INPUT A
INPUT B
IF A > B
THEN
OUTPUT A
ELSE
OUTPUT B
ENDIF
The algorithm needs to be amended to include the following changes:
Input three values, ensuring that each value input is unique.
1.
2.
Output the average.
3.
Output the largest value.
Write the pseudocode for the amended algorithm.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

22
9608/22/O/N/20 · Question 3Oct/Nov 2020Paper 2210 marks
Loading question…
Question text

3
A car has the ability to detect a skid by monitoring the rate of rotation (the rotational speed) of
each wheel. If the rate of rotation of any wheel is not within 10% of the average of all four wheels,
the car skids.
A function, CheckSkid(), is being developed.
The function will:
•
simulate real-time data acquisition, by prompting for the input of four integer values in the
range 0 to 1000 inclusive, representing the rate of rotation of each wheel
•
calculate the average value
•
check whether any individual value is more than 10% greater than the average or more than
10% less than the average
•
return TRUE if any individual value is more than 10% greater than the average or more than
10% less than the average and FALSE otherwise
•
output a suitable warning message.
(a) Write program code for the function CheckSkid().
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
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

23
9608/22/O/N/20 · Question 4Oct/Nov 2020Paper 2219 marks
Loading question…
Question text

4
(a) The following structured English describes an algorithm used to count the number of odd and
even digits in an input sequence.
1.
Initialise variables OddCount and EvenCount to zero.
2.
Prompt and input an integer.
3.
If the integer is not in the range 0 to 9 then go to step 7.
4.
If the integer is an even number then add 1 to EvenCount.
5.
Otherwise add 1 to OddCount.
6.
Repeat from step 2.
7.
Output "Same" if there are the same number of odd and even integers.
8.
Output "Odd" if there are more odd than even integers.
9.
Output "Even" if there are more even than odd integers.
Draw a flowchart on the following page to represent the algorithm.
[7]
(b) The following pseudocode is an attempt to check whether two equal-length strings consist of
identical characters.
Refer to the Appendix on pages 18–19 for the list of built-in functions and operators.
FUNCTION Compare(String1, String2 : STRING) RETURNS BOOLEAN
DECLARE x, y, Len1, Len2 : INTEGER
DECLARE RetFlag : BOOLEAN
DECLARE NextChar : CHAR
DECLARE New : STRING
LENGTH(String1)
Len1
TRUE
RetFlag
1 TO Len1
// for each char in String1
FOR x
LENGTH(String2)
Len2
MID(String1, x, 1)
// get NextChar from String1
NextChar
""
New
1 TO Len2
// for each char in String2
FOR y
IF NextChar <> MID(String2, y, 1)
// no match
THEN
New & MID(String2, y, 1) // save this char from String2
New
ENDIF
ENDFOR
New
// replace String2 with New
String2
ENDFOR
IF LENGTH(String2) <> 0
// anything left in String2 ?
THEN
FALSE
RetFlag
ENDIF
RETURN RetFlag
ENDFUNCTION
(i)
Complete the trace table below by performing a dry run of the function when it is called
as follows:
Compare("SUB", "BUS")
Result
The first row has been completed for you.
String1 String2 Len1 RetFlag
x
Len2
NextChar
New
y
"SUB"
"BUS"
3
TRUE
1
[5]
(ii)
State the value returned.
… [1]
(iii)
There is an error in the algorithm, which means that under certain circumstances, the
function will return an incorrect value.
Describe the problem. Give two test strings that would demonstrate it.
Problem …
…
…
…
…
Test String1 …
Test String2 …
[2]
(iv)
Describe the modification that needs to be made to the algorithm to correct the error.
Do not use pseudocode or program code in your answer.
…
…
…
…
…

Advertisement
24
9608/23/O/N/20 · Question 2Oct/Nov 2020Paper 2319 marks
Loading question…
Question text

2
(a) An algorithm is needed to input a list of numbers representing test marks for a class of
30 students.
The algorithm will output the number of students who have a mark greater than 75. It will also
output the average mark for the class.
Document the algorithm using structured English.
…
…
…
…
…
…
…
…
…
…
…
… [8]
(b) Each pseudocode statement in the following table contains an error.
State the error in each case.
Refer to the Appendix on page 16 for the list of built-in functions and operators.
Statement
Error
Code
LEFT(3, "Europe")
MID("ALARM:12:02", 7, 6)
Hour
LENGTH(27.5)
Size
INT(27 / (Count + 3)
Num
"Conditional" AND "Loop"
Result
[5]
(c) Part of a program flowchart is shown.
Set Index to 0
Set Status to FALSE
LOOP
Is
YES
Status = TRUE
?
NO
NO
Is Index > 100
?
Set Status to TopUp()
YES
SetLevel("Super")
Set Index to Index + 1
Write program code to implement the flowchart shown. Variable declarations are not
required.
Programming language …
Program code
…
…
…
…
…
…
…
…

25
9608/23/O/N/20 · Question 4Oct/Nov 2020Paper 2314 marks
Loading question…
Question text

4
(a) The following pseudocode includes a procedure that searches for a value in a 1D array and
outputs each position in the array where the value is found.
Refer to the Appendix on page 16 for the list of built-in functions and operators.
DECLARE NameList : ARRAY [1:100] OF STRING
DECLARE SearchString : STRING
PROCEDURE Search()
DECLARE Index : INTEGER
1 TO 100
FOR Index
IF NameList[Index] = SearchString
THEN
OUTPUT "Found at " & NUM_TO_STRING(Index)
ENDIF
ENDFOR
ENDPROCEDURE
The specification of module Search() changes. The pseudocode needs to be amended to
meet a new requirement.
The procedure needs to be implemented as a function, Search(), which will:
•
take the search value as a parameter
•
return an integer which is:
either the index value where the search value is first found
•
or –1 if the search value is not found.
•
Write the pseudocode for the function Search().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

26
9608/23/O/N/20 · Question 5Oct/Nov 2020Paper 2324 marks
Loading question…
Question text

5
A hashtag is used on a social media network to make it easier to find messages with a specific
theme or content. A hashtag is a string consisting of a hash character ‘#’ followed by a number of
alphanumeric characters.
A message may contain several hashtag strings. A hashtag may be terminated by a space
character, the start of the next hashtag, or by the end of the message.
For example, the following message contains three hashtags:
"#Alarm34 is the result of #BatteryFailure in the #PowerModule"
The hashtags in this message are "#Alarm34", "#BatteryFailure" and "#PowerModule".
A program is being developed to monitor their use.
The program will include two global arrays each containing 10 000 elements:
•
A 1D array, TagString, of type STRING storing each hashtag in a single element of the
array. All unused array elements contain an empty string ("").
•
A 1D array, TagCount, of type INTEGER storing a count of the number of times each hashtag
is used. The count value in a given element relates to the hashtag value stored in the element
in the TagString array with the corresponding index value.
A developer has started to define the modules. Module GetStart() has already been written.
Module
Description
•
Called with two parameters:
•
a message of type STRING
•
an integer giving the number of the required hashtag;
for example, GetStart(Message, 3) would search
GetStart()
for the third hashtag in the string Message
•
Returns an integer value representing the start position of
the hashtag in the message, or value −1 if that hashtag
does not exist
•
Called with a hashtag of type STRING
•
Copies the hashtag to the next free element of the
TagString array, and sets the corresponding element of
AddHashtag()
the TagCount array to 1
•
Returns FALSE if there are no unused elements in the
TagString array, otherwise returns TRUE
•
Called with a message of type STRING
•
Searches the message for hashtags using GetStart()
CountHashtag()
•
Returns a value representing the number of hashtags in the
message
•
Called with a hashtag of type STRING
•
Increments the value of the appropriate element in the
IncrementHashtag()
TagCount array if the hashtag is found
•
Returns TRUE if the hashtag is found, or FALSE if the
hashtag is not found
(a) Write pseudocode for the module AddHashtag().
…
…
…
…
…
…
…
…
…
…
…
…

27
9608/21/M/J/20 · Question 1May/June 2020Paper 218 marks
Loading question…
Question text

1
(a) Complete this definition of the term algorithm.
An algorithm is a solution to a problem expressed as …
…
… [2]
(b) A program design includes the use of subroutines (functions and procedures).
Give three advantages of using subroutines in a program.
1 …
…
2 …
…
3 …
…
[3]
(c) Draw lines on the following diagram to connect each computing term with the appropriate
description.
Term
Description
Checking that a program
Selection
performs as expected
A method for increasing the
Black-box testing
level of detail of an algorithm
To test a condition to determine
Stepwise refinement
the path of program execution
A method of executing certain
Iteration
lines of code more than once
[3]

28
9608/21/M/J/20 · Question 2May/June 2020Paper 2113 marks
Loading question…
Question text

2
(a) Three modules form part of a program for a car rental company. A description of the
relationship between the modules is summarised as follows:
Module name
Description
A customer will pay for each car rental either by bank card or by using their
RentCar()
account with the rental company.
Called with parameter HireCost, representing the cost of the rental.
PayByCard()
Returns a BOOLEAN value to indicate whether or not the card payment was
successful.
Called with parameters HireCost, AccountNumber, CurrentBalance
and AccountLimit.
•
Checks whether HireCost plus the CurrentBalance would exceed
PayByAccount()
the AccountLimit. If so, then the rental is not authorised.
•
If the rental is authorised, then the CurrentBalance is updated.
•
Returns a BOOLEAN value to indicate whether or not the rental was
authorised.
Draw a structure chart to show the relationship between the three modules and the
parameters passed between them.
[5]
(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.
To be a valid password, a string must:
•
be longer than 6 characters
•
contain at least one lower case letter
•
contain at least one upper case letter
•
contain at least one non-alphabetic character.
10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN
11
12
DECLARE Index : INTEGER
13
DECLARE StrLen : INTEGER
14
DECLARE NumUpper, NumLower : INTEGER
15
DECLARE NumNonAlpha : INTEGER
16
DECLARE NextChar : CHAR
17
0
18
NumUpper
0
19
NumLower
0
20
NumNonAlpha
21
LENGTH(InString)
22
StrLen
23
IF StrLen < 7
24
THEN
25
RETURN FALSE
26
ELSE
1 TO StrLen
27
FOR Index
MID(InString, Index, 1)
28
NextChar
29
IF NextChar >= 'a' AND NextChar <= 'z'
30
THEN
NumLower + 1
31
NumLower
32
ELSE
33
IF NextChar > 'A' AND NextChar <= 'Z'
34
THEN
NumUpper + 1
35
NumUpper
36
ELSE
NumNonAlpha + 1
37
NumNonAlpha
38
ENDIF
39
ENDIF
40
ENDFOR
41
ENDIF
42
43
IF (NumUpper >= 1) AND (NumLower >= 1) AND (NumNonAlpha >= 1)
44
THEN
45
RETURN TRUE
46
ELSE
47
RETURN FALSE
48
ENDIF
49
50 ENDFUNCTION
Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
The pseudocode does not work under all circumstances.
A dry run performed on the function Check(), with the string "crAsh99", produced the
following trace table.
The string is a valid password, but the pseudocode would return the value FALSE.
Trace
StrLen
Index
NextChar
NumUpper
NumLower
NumNonAlpha
table row
7
0
0
0
1
1
'c'
2
1
3
2
'r'
4
2
5
3
'A'
6
1
7
4
's'
8
3
9
5
'h'
10
4
11
6
'9'
12
2
13
7
'9'
14
3
15
(i)
Describe how the completed trace table may be used to identify the error in the
pseudocode. In your answer, refer to the trace table row number(s).
…
…
…
…
… [2]
(ii)
State the pseudocode line number that has to be changed to correct the error and write
the correct pseudocode for the complete line.
Line number …
Correct pseudocode …
…
[2]
(iii)
Rewrite

Advertisement
29
9608/21/M/J/20 · Question 3May/June 2020Paper 2115 marks
Loading question…
Question text

3
(a) A mobile phone provider has developed an account management program. The program
includes a procedure, AddCredit(). The procedure is called with two parameters, TopUp
and PhoneNum.
The relevant part of the identifier table and the program flowchart for the procedure are as
shown:
Identifier
Type
Description
TopUp
REAL
The amount of credit to be added
PhoneNum
STRING
The unique customer phone number
Balance
REAL
The current amount of credit
Multiple
REAL
The amount of credit bonus
Takes the phone number as a parameter and returns the current
GetBalance()
FUNCTION
balance
Takes the phone number and the new balance as parameters and
SetBalance()
PROCEDURE
updates the account with the new balance
START
Set Multiple
to 1
Set Balance to
GetBalance(PhoneNum)
Is
YES
Set Multiple to
Balance > 10 ?
1.25
NO
Is
YES
Set Multiple to
Balance > 5 ?
1.1
NO
Set TopUp to
TopUp * Multiple
SetBalance(PhoneNum, Balance + TopUp)
END
Write pseudocode to implement the procedure AddCredit(). The pseudocode must follow
the algorithm represented by the flowchart. Declare any local variables used.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

30
9608/21/M/J/20 · Question 5May/June 2020Paper 2112 marks
Loading question…
Question text

5
(a) A 1D array, Directory, of type STRING is used to store a list of school internal telephone
numbers. There are 1000 elements in the array. Each element stores a single data item. The
format of each data item is as follows:
<Number><Name>
Number is a four-digit numeric string.
Name is a variable-length string.
For example:
"1024Collins Robbie"
The following pseudocode is an initial attempt at defining a procedure SortContacts()
that will perform a bubble sort on Directory. The array is to be sorted in ascending order of
Name.
Fill in the gaps to complete the pseudocode.
Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
PROCEDURE SortContacts ()
DECLARE Temp : STRING
DECLARE FirstName, SecondName : STRING
DECLARE NoSwaps : …
DECLARE Boundary, J : INTEGER
…
Boundary
REPEAT
TRUE
NoSwaps
1 TO Boundary
FOR J
… (Directory[J], LENGTH(Directory[J]) – … )
FirstName
RIGHT(Directory[J + 1], LENGTH(Directory[J + 1]) – 4)
SecondName
IF FirstName …
THEN
Directory[J]
Temp
Directory …
Directory[J]
Temp
Directory[J + 1]
…
NoSwaps
ENDIF
ENDFOR
…
Boundary
UNTIL NoSwaps = TRUE
ENDPROCEDURE
[8]
(b) The pseudocode contains a mechanism designed to make this an efficient bubble sort.
Describe the mechanism and explain why it may be considered to be efficient.
…
…
…
…
…
…
…
…
…
… [4]

Advertisement