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

130 questions · page 5 of 9

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
61
9608/22/M/J/19 · Question 2May/June 2019Paper 2212 marks
Loading question…
Question text

2
(a) (i)
Procedures and functions are examples of subroutines.
State a reason for using subroutines in the construction of an algorithm.
…
… [1]
(ii)
Give three advantages of using subroutines in a program.
1 …
…
2 …
…
3 …
…
[3]
(iii)
The following pseudocode uses the subroutine DoSomething().
23 + DoSomething("Yellow")
Answer
State whether the subroutine is a function or a procedure. Justify your answer.
Type of subroutine …
Justification …
…
[2]
(b) The program development cycle involves writing, translating and testing a high-level language
program.
Describe these activities with reference to each of the following:
•
editor
•
translator
•
debugger
…
…
…
…
…
… [3]
(c) The following lines of code are taken from a high-level language program.
WHEN Result < 20
{
Call ResetSensor(3)
Result := GetSensor(3)
}
Identify the type of control structure and describe the function of the code.
Control structure …
Function of code …
…
…
…
…

62
9608/22/M/J/19 · Question 3May/June 2019Paper 228 marks
Loading question…
Question text

3
The following structure chart shows the relationship between three modules.
TopLevel
B
D
A
C
E
SubA
SubB
Parameters A to E have the following data types:
A, D : STRING
C
: CHAR
B, E : INTEGER
(a) (i)
Write the pseudocode header for module SubA().
…
…
… [3]
(ii)
Write the pseudocode header for module SubB().
…
…
… [3]
(b) Module hierarchy and parameters are two features that may be represented on a structure
chart.
State two other features than can be represented.
Feature 1 …
Feature 2 …
[2]
Question 4 begins on the next page.

63
9608/22/M/J/19 · Question 4May/June 2019Paper 2210 marks
Loading question…
Question text

4
The following is pseudocode for a string handling function.
For the built-in functions list, refer to the Appendix on page 16.
FUNCTION Search(InString : STRING) RETURNS INTEGER
DECLARE
NewString : STRING
DECLARE
Index : INTEGER
DECLARE
NextChar : CHAR
DECLARE
Selected : INTEGER
DECLARE
NewValue : INTEGER
'0'
NewString
0
Selected
1 TO LENGTH(InString)
FOR Index
MID(InString, Index, 1)
NextChar
IF NextChar < '0' OR NextChar > '9'
THEN
STRING_TO_NUM(NewString)
NewValue
IF NewValue > Selected
THEN
NewValue
Selected
ENDIF
'0'
NewString
ELSE
NewString & NextChar
NewString
ENDIF
ENDFOR
RETURN Selected
ENDFUNCTION
(a) (i)
The following assignment calls the Search() function:
Search("12∇34∇5∇∇39")
Result
Complete the following trace table by performing a dry run of this function call.
The symbol '∇' represents a space character. Use this symbol to represent a space
character in the trace table.
Index
NextChar
Selected
NewValue
NewString
[5]
(ii)
State the value returned by the function when it is called as shown in part (a)(i).
…
[1]
(b) There is an error in the algorithm. When called as shown in part (a)(i), the function did not
return the largest value as expected.
(i)
Explain why this error occurred when the program called the function.
…
…
…
… [2]
(ii)
Describe how the algorithm could be amended to correct the error.
…
…
…
… [2]

Advertisement
64
9608/22/M/J/19 · Question 5May/June 2019Paper 229 marks
Loading question…
Question text

5
A student is learning about text files. She wants to write a program to count the number of lines in
a file.
(a) Use structured English to describe an algorithm she could use.
…
…
…
…
…
… [3]
(b) A procedure, CountLines(), is being written to count the number of lines in a text file. The
procedure will:
•
take a filename as a string parameter
•
count the number of lines in the file
•
output a single suitable message that includes the total number of lines.
Write pseudocode for the procedure CountLines().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

65
9608/22/M/J/19 · Question 6May/June 2019Paper 2219 marks
Loading question…
Question text

6
Nadine is developing a program to store the ID and preferred name for each student in a school.
For example, student Pradeep uses the preferred name “Prad”.
The program will:
1.
prompt and input a valid user ID and a preferred name
2.
write the user ID and preferred name to one of two files
3.
allow the user to end the program or repeat from step 1.
The program will consist of three separate modules. Each module will be implemented using
either a procedure or a function.
Nadine has defined the modules as follows:
Module
Description
TopLevel()
•
Call GetInfo() to obtain a string containing a valid user ID and a
preferred name
•
Call WriteInfo() to write the string to either File1.txt or
File2.txt depending on the first character of the user ID as follows:
‘A’ to ‘M’: writes to File1.txt
○
‘N’ to ‘Z’: writes to File2.txt
○
For example, a string with a user ID of "G1234" writes to File1.txt
•
End the program if the file write was unsuccessful
•
Input (Y/N) to either repeat for the next user ID or to end the program
GetInfo()
•
Input a user ID and repeat until the user ID is valid
•
Input a preferred name. This will be an empty string if no preferred
name is input.
•
Concatenate the user ID and preferred name using a '*' character as
a separator and return this string
WriteInfo()
•
Open the file
•
Append the concatenated string to the file
•
Close the file
•
Return a Boolean value:
TRUE if the file write was successful
○
FALSE if the file write failed, for example, if the disk was full
○
A valid user ID:
•
is five characters in length
•
has a single upper case alphabetic character followed by four numeric characters, for
example “G1234”.
Nadine has decided that global variables and nested modules must not be used.
Nadine wants all inputs to have suitable prompts.
(a) Write program code for the module GetInfo().
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
…
…
…
…
…
…
…
…
…
…
…
…
…

66
9608/23/M/J/19 · Question 1May/June 2019Paper 2317 marks
Loading question…
Question text

1
The following pseudocode searches for the longest run of identical characters in the array
Message.
DECLARE Message : ARRAY[1:100] OF CHAR
PROCEDURE Search()
DECLARE
Index : INTEGER
DECLARE
ThisChar : CHAR
DECLARE
ThisRun : INTEGER
DECLARE
LongRun : INTEGER
Message[1]
ThisChar
1
ThisRun
1
LongRun
2 TO 100
FOR Index
IF Message[Index] = ThisChar
THEN
ThisRun + 1
ThisRun
ELSE
Message[Index]
ThisChar
IF ThisRun > LongRun
THEN
ThisRun
LongRun
ENDIF
1
ThisRun
ENDIF
ENDFOR
OUTPUT "The longest run was " , LongRun
ENDPROCEDURE
(a) Draw a program flowchart to represent the procedure Search().
Variable and array declarations are not required in program flowcharts.
[6]
(b) (i)
Program variables have values as follows:
Variable
Value
MeltingPoint
180.5
Soluble
FALSE
Attempt
3
ProductName
"Mushroom Compost"
Version
'A'
ProductID
"BZ27-4"
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 18.
Expression
Evaluates to
STRING_TO_NUM(MID(ProductID, 3, 2)) + 4
INT(MeltingPoint / 2)
Soluble AND Attempt > 3
LENGTH(ProductID & NUM_TO_STRING(MeltingPoint))
RIGHT(ProductName, 4) & MID(ProductName, 5, 4)
[5]
(ii)
Programming languages support different data types.
Give an appropriate data type for the following variables from part (b)(i).
Variable
Data type
MeltingPoint
Soluble
Attempt
Version
ProductID
[5]

67
9608/23/M/J/19 · Question 3May/June 2019Paper 238 marks
Loading question…
Question text

3
The following pseudocode represents three separate modules from an algorithm design. The
module contents are not shown.
FUNCTION Search(AA : INTEGER, BB : STRING) RETURNS INTEGER
ENDFUNCTION
FUNCTION Allocate() RETURNS BOOLEAN
ENDFUNCTION
PROCEDURE Enable(CC : INTEGER, BYREF DD : INTEGER)
ENDPROCEDURE
A fourth module, Setup(), refers to the previous three modules as follows:
PROCEDURE Setup()
WHILE Authorised = TRUE
ThisValue
Search(27, "Thursday")
Authorised
Allocate()
CALL Enable(ThisValue, 4)
ENDWHILE
ENDPROCEDURE
(a) Draw a structure chart to show the four modules and the parameters that these pass between
them.
[6]
(b) The algorithm is implemented in a high-level language. Changes are required and the
program is given to Albert, who is an experienced programmer. He is not familiar with the
language that has been used.
Explain why Albert would be able to understand the program.
…
…
…
… [2]

68
9608/23/M/J/19 · Question 4May/June 2019Paper 235 marks
Loading question…
Question text

4
A program is being written to process student information. One task involves inputting the names
of all students in a class.
A first attempt at the pseudocode for this task is as follows:
DECLARE Name1 : STRING
DECLARE Name2 : STRING
DECLARE Name3 : STRING
DECLARE Name40 : STRING
OUTPUT "Input the name for student 1"
INPUT Name1
OUTPUT "Input the name for student 2"
INPUT Name2
OUTPUT "Input the name for student 3"
INPUT Name3
OUTPUT "Input the name for student 40"
INPUT Name40
(a)
Re-write the pseudocode to perform this task in a more efficient way, to allow for the class of
40 students.
…
…
…
…
…
…
…
…
…
… [4]
(b)
Give one advantage of your solution.
… [1]
Question 5 begins on the next page.

Advertisement
69
9608/23/M/J/19 · Question 5May/June 2019Paper 2311 marks
Loading question…
Question text

5
Nigel is learning about string handling. He wants to write code to count the number of words in a
given string. A word is defined as a sequence of alphabetic characters that is separated by one or
more space characters.
His first attempt at writing an algorithm in pseudocode is as follows:
PROCEDURE CountWords(Message : STRING)
DECLARE NumWords : INTEGER
DECLARE Index : INTEGER
CONSTANT Space = ' '
0
NumWords
1 TO LENGTH(Message)
FOR Index
IF MID(Message, Index, 1) = Space
THEN
NumWords + 1
NumWords
ENDIF
ENDFOR
OUTPUT "Number of words : " , NumWords
ENDPROCEDURE
For the built-in functions list, refer to the Appendix on page 18.
His first attempt is incorrect. He will use white-box testing to help him to identify the problem.
(a) (i)
State the purpose of white-box testing.
…
… [1]
(ii)
Dry running the code is often used in white-box testing. In this method, the programmer
records the values of variables as they change.
Identify what the programmer would normally use to record the changes.
… [1]
(b) (i)
Write a test string containing two words that gives the output:
Number of words : 2
Use the symbol '∇' to represent each space character in your test string.
Explain why the algorithm gives the output shown above.
String …
Explanation …
…
…
…
…
[3]
(ii)
Nigel tested the procedure with the strings:
String 1: "Red∇and∇Yellow"
String 2: "Green∇∇and∇∇Pink∇"
Give the output that is produced for each of the strings.
Describe the changes that would need to be made to the algorithm to give the correct
output in each case.
Do not write pseudocode or program code.
String 1 …
Description …
…
…
…
String 2 …
Description …
…
…

70
9608/21/O/N/18 · Question 1Oct/Nov 2018Paper 2116 marks
Loading question…
Question text

1
(a) The following table contains statements written in pseudocode.
Show what type of programming construct each statement represents.
Put a tick (3) in the appropriate column for each statement.
Repetition
Statement
Selection
Assignment
(Iteration)
WHILE Count < 20
Count + 1
Count
IF MyGrade <> 'C' THEN
GetMark(StudentID)
Mark[Count]
ELSE OUTPUT "Fail"
ENDFOR
[6]
(b) (i)
The following table contains statements written in pseudocode.
Give the most appropriate data type for the variable used in each statement.
Statement
Data type
MyAverage
13.5
TRUE
ProjectCompleted
"Home Economics"
Subject
270
MyMark
'B'
MyGrade
[5]
(ii)
The following table contains statements written in pseudocode.
Complete the table by evaluating each expression using the values from part (b)(i).
If any expression is invalid, write “ERROR” in the Evaluates to column.
For the built-in functions list, refer to the Appendix on page 16.
Expression
Evaluates to
"Air-" & MID(Subject, 7, 3)
INT(MyAverage / 2)
ProjectCompleted AND MyMark > 270
ProjectCompleted OR MyMark > 260
ASC(MyGrade / 3)
[5]

71
9608/21/O/N/18 · Question 2Oct/Nov 2018Paper 2120 marks
Loading question…
Question text

2
Shop customers have a discount card with a unique card number. Customers collect points after
they have bought items. The more points they have, the bigger the discount. If they shop on a
Wednesday, their discount is increased by 20%.
The function GetDiscountRate() takes a card number as a parameter and returns the discount
rate for a customer based on the number of points they have collected. A flowchart for the function
is shown.
The function uses the following variables and functions.
Identifier
Data type
Description
The discount rate
DRate
REAL
The unique customer card number
CardNum
STRING
The number of points collected
Points
INTEGER
Takes the card number as a parameter and returns the
GetPoints()
FUNCTION
number of points already collected
Returns the day number: 1 for Monday, 2 for Tuesday etc.
Today()
FUNCTION
START
DRate
0
Points
GetPoints(CardNum)
Is
YES
DRate
0.2
Points > 199 ?
NO
Is
YES
DRate
0.1
Points > 99 ?
NO
Is Today =
YES
DRate
DRate * 1.2
Wednesday ?
NO
RETURN DRate
END
(a) Write pseudocode to implement the GetDiscountRate() function.
Your solution should follow the flowchart for the function as closely as possible. Variable
declarations should be included.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

72
9608/21/O/N/18 · Question 4Oct/Nov 2018Paper 2120 marks
Loading question…
Question text

4
Part of a program written in pseudocode is shown.
01 DECLARE NumElements : INTEGER
…
10 FUNCTION ScanArray(SearchString : STRING) RETURNS INTEGER
11
12
DECLARE ArrayIndex : INTEGER
13
DECLARE ArrayString : STRING
14
DECLARE NumberFound : INTEGER
15
0
16
ArrayIndex
0
17
NumberFound
18
1 TO NumElements
19
FOR ArrayIndex
ResultArray[ArrayIndex, 1]
20
ArrayString
21
IF ArrayString = SearchString
22
THEN
23
CALL SaveToFile(ArrayString)
NumberFound + 1
24
NumberFound
25
ENDIF
26
ENDFOR
27
28
RETURN NumberFound
29
30 ENDFUNCTION
(a) (i)
Examine the pseudocode and complete the following table.
Answer
The identifier name of a global integer
The identifier name of a user-defined procedure
The line number of an unnecessary statement
The scope of ArrayString
[4]
(ii)
Describe in detail the purpose of lines 19 to 26 in the function ScanArray().
Do not use pseudocode in your answer.
…
…
…
…
…
…
… [4]
(b) The function ScanArray() needs to be amended so that the comparison is not case
sensitive. For example, comparing “Aaaa” with “AAAa” should evaluate to TRUE.
Write program code to implement the amended ScanArray() 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
…
…
…
…
…
…
…
…
…
…
…

73
9608/21/O/N/18 · Question 5Oct/Nov 2018Paper 2110 marks
Loading question…
Question text

5
A program collects data about the performance of a car at regular time intervals. A text file,
CarStatus.txt, stores the data.
The format of each line of the text file is as follows:
<Time>,<Amount of fuel used>,<Distance travelled>
Data items are separated by a ‘,’ (comma) character.
The program contains the following functions.
Function
Description
Returns a string representing the current time. May return NULL under
GetTime()
certain circumstances.
Returns a string representing the amount of fuel used
GetFuel()
Returns a string representing the distance travelled
GetDistance()
The function SaveStatus() will:
•
obtain the time, fuel used and distance data using the appropriate function calls
•
check that the time string is not NULL
•
return FALSE if the current time string remains NULL after three attempts
•
form the text string, write it to the file and return TRUE
The file should not be open longer than necessary.
Write pseudocode for the SaveStatus() function.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement
74
9608/22/O/N/18 · Question 1Oct/Nov 2018Paper 2216 marks
Loading question…
Question text

1
(a) The following table contains statements written in pseudocode.
Show the type of programming construct each statement represents.
Put a tick (3) in the appropriate column for each statement.
Repetition
Statement
Selection
Assignment
(Iteration)
Index + 5
Index
1 TO 100
FOR Count
ReadValue(SensorID)
TempValue[Index]
IF Index < 30
UNTIL DayNumber > 7
OTHERWISE OUTPUT "ERROR"
[6]
(b) (i)
The following table contains statements written in pseudocode.
Give the most appropriate data type for the variable used in each statement.
Statement
Data type
Revision
'B'
13.3
MaxValue
TRUE
ArrayFull
"Design"
Activity
270
NumberOfEdits
[5]
(ii)
The following table contains statements written in pseudocode.
Complete the table by evaluating each expression using the values from part (b)(i).
If any expression is invalid, write “ERROR” in the Evaluates to column.
For the built-in functions list, refer to the Appendix on page 16.
Expression
Evaluates to
MID(Activity, 3, 4) & "ature"
INT(MaxValue * 2)
ArrayFull AND NumberOfEdits < 300
ASC(Revision + 1)
Activity = "Testing" OR Revision = 'A'
[5]

75
9608/22/O/N/18 · Question 2Oct/Nov 2018Paper 2218 marks
Loading question…
Question text

2
Shop customers have a discount card with a unique card number. Customers collect points each
time they buy items. The number of points they collect depends on:
•
the total amount they spend
•
the number of points already collected.
The function CalcPoints() takes the card number and the total amount spent as parameters. It
returns the number of new points collected. A flowchart for the function is shown.
The function uses the following variables and functions.
Identifier
Data type
Description
A numeric string representing the unique card number
CardNum
STRING
The number of points already collected
OldPoints
INTEGER
The number of new points collected
NewPoints
INTEGER
The amount spent
Total
REAL
Takes the card number as a parameter and returns the
GetPoints()
FUNCTION
number of points already collected
Refer to the Appendix on page 16
INT()
FUNCTION
START
Is
YES
Total > 100 ?
OldPoints
NO
GetPoints(CardNum)
Is
NO
OldPoints > 2000 ?
YES
NewPoints
INT(Total * 1.2)
NewPoints
0
NewPoints
INT(Total * 1.1)
RETURN NewPoints
END
(a) (i)
Write pseudocode for the CalcPoints() function.
Your solution should follow the flowchart as closely as possible.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement