Programming – A Level Computer Science (9618)

153 questions · page 7 of 11 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
91
9618/23/O/N/23 · Question 4Oct/Nov 2023Paper 237 marks
Loading question…
Question text

4
A procedure RandList() will output a sequence of 25 random integers, where each integer is
larger than the previous one.
(a) Write pseudocode for procedure RandList().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(b) Procedure RandList() is modified so that the random numbers are also written into a
1D array Result.
A new module is written to confirm that the numbers in the array are in ascending order.
This module contains an IF statement that performs a comparison between elements:
IF (Result[x + 1] = Result[x]) OR (Result[x] > Result[x + 1]) THEN
←
FALSE
Sequence
ENDIF
Write a simplified version of the conditional clause.
…
…
… [1]

92
9618/23/O/N/23 · Question 5Oct/Nov 2023Paper 2328 marks
Loading question…
Question text

5
A global 1D array of integers contains four elements, which are assigned values as shown:
← 4
Mix[1]
← 2
Mix[2]
← 3
Mix[3]
← 5
Mix[4]
A procedure Process() manipulates the values in the array.
The procedure is written in pseudocode as follows:
PROCEDURE Process(Start : INTEGER)
DECLARE Value, Index, Total : INTEGER
← Start
Index
← 0
Total
WHILE Total < 20
←
Mix[Index]
Value
←
Total + Value
Total
IF Index < 4 THEN
←
Mix[Index] + Mix[Index+1]
Mix[Index]
ELSE
←
Mix[Index] + Mix[1]
Mix[Index]
ENDIF
←
(Value MOD 4) + 1
Index
ENDWHILE
← Total * Index
Mix[1]
ENDPROCEDURE
Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:
CALL Process(2)
Index
Value
Total
Mix[1]
Mix[2]
Mix[3]
Mix[4]
[6]

93
9618/23/O/N/23 · Question 6Oct/Nov 2023Paper 236 marks
Loading question…
Question text

6
A function TestNum() will take a six-digit string as a parameter.
The function will test whether the string meets certain conditions and will return an integer value
as follows:
Return value
Condition
Example
1
The last three digits are the same but non-zero.
"253444"
2
The last three digits are zero.
"253000"
3
The first three and last three digits are the same.
"410410"
The function will return the highest possible value for the given string.
If the string does not meet any of the conditions, zero is returned.
Write pseudocode for function TestNum().
Assume that the parameter is valid.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]

Advertisement
94
9618/23/O/N/23 · Question 7Oct/Nov 2023Paper 237 marks
Loading question…
Question text

7
A structure chart shows the modular structure of a program:
Module-A()
T1
RA
SA
RB
Sub-Y1()
Sub-Y2()
Sub-9()
(a) Explain the meaning of the curved arrow symbol which begins and ends at Module-A().
…
…
…
… [2]
(b) The structure chart shows that Sub-9() is a function.
A Boolean value is returned by Sub-9() for processing by Module-A().
The original parameter RA is of type integer and RB is of type string.
A record type MyType will be defined with three fields to store the values passed between the
two modules.
(i)
Write pseudocode to define MyType.
…
…
…
…
…
… [3]
(ii)
The design is modified and Sub-9() is changed to a procedure.
The procedure will be called with a single parameter of type MyType.
Write the pseudocode header for procedure Sub-9().
…
… [2]

95
9618/23/O/N/23 · Question 8Oct/Nov 2023Paper 2320 marks
Loading question…
Question text

8
A class of students are developing a program to send data between computers. Many computers
are connected together to form a wired network. Serial ports are used to connect one computer to
another.
Each computer:
•
is assigned a unique three-digit ID
•
has three ports, each identified by an integer value
•
is connected to between one and three other computers.
Messages are sent between computers as a string of characters organised into fields as shown:
<STX><DestinationID><SourceID><Data><ETX>
Field name
Description
a single character marking the start of the message
STX
(ASCII value 02)
DestinationID
three numeric characters identifying the destination computer
SourceID
three numeric characters identifying the source computer
a variable length string containing the data being sent
Data
(Minimum length is 1 character)
a single character marking the end of the message
ETX
(ASCII value 03)
For example, the following message contains the data "Hello Jack" being sent from computer
"202" to computer "454":
<STX>"454202Hello Jack"<ETX>
Each computer will run a copy of the same program. Each program will contain a global variable
MyID of type string which contains the unique ID of the computer in which the program is running.
The first two program modules are defined as follows:
Module
Description
•
returns the data field from a message that has been received
GetData()
•
If no message is available, the module waits until one has been
(already written)
received.
•
takes a file name as a parameter of type string
•
creates a text file with the given file name (no checking required)
•
writes the data field returned by GetData() to the file
ReceiveFile()
•
repeats until the data field is "****", which is not written to the file
•
outputs a final message giving the total number of characters
written to the file, for example:
132456 characters were written to newfile.txt
(a) Write pseudocode for module ReceiveFile().
Module GetData() has already been written and must be used.
…
…
…
…
…
…
…
…
…
…
…
…
…
…

96
9618/21/M/J/23 · Question 1May/June 2023Paper 2110 marks
Loading question…
Question text

1
A programmer has written a program which includes the function Calculate().
When the program is run, the function returns an unexpected value.
(a) Describe how a typical Integrated Development Environment (IDE) could be used to help
debug the program to find the errors in the function Calculate().
…
…
…
…
…
…
…
… [4]
(b) The algorithm for function Calculate() contains the three pseudocode statements shown.
Describe the error in each statement or write ‘no error’ if the statement contains no error.
Assume any variables used are of the correct type for the given function.
Statement 1: Index
STR_TO_NUM(("27") + 2)
Error …
…
Statement 2: Index
STR_TO_NUM(MID("CPE1704TKS", 4, 2))
Error …
…
Statement 3: IF MONTH(ThisDate) > '6' THEN
Error …
…
[3]
(c) The program contains variables with values as follows:
Variable
Value
Active
TRUE
Points
75
Exempt
FALSE
(i)
Complete the table by evaluating each expression.
Expression
Evaluation
(Points > 99) OR Active
1
(Points MOD 2 = 0) OR Exempt
2
(Points <= 75) AND (Active OR Exempt)
3
(Active OR NOT Active) AND NOT Exempt
4
[2]
(ii)
Write expression 4 from the table in part (c)(i) in its simplest form.
… [1]

97
9618/21/M/J/23 · Question 2May/June 2023Paper 217 marks
Loading question…
Question text

2
A program contains an algorithm to output a string of a specified length containing identical
characters.
(a) The algorithm is described as follows:
1.
prompt and input a character and store in MyChar
2.
prompt and input an integer and store in MyCount
3.
generate a string consisting of MyChar repeated MyCount times
4.
output the string.
Draw a program flowchart to represent the algorithm.
START
END
[4]
(b) A different part of the program uses the variable StartDate.
Write pseudocode statements to declare StartDate and assign to it the date corresponding
to 15/11/2005.
Declaration …
Assignment …
[3]

98
9618/21/M/J/23 · Question 4May/June 2023Paper 216 marks
Loading question…
Question text

4
Function Replace() will:
1.
take three parameters:
•
a string (the original string)
•
a char (the original character)
•
a char (the new character)
2.
form a new string from the original string where all instances of the original character are
replaced by the new character
3.
return the new string.
Write pseudocode for function Replace().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]

Advertisement
99
9618/21/M/J/23 · Question 7May/June 2023Paper 218 marks
Loading question…
Question text

7
A school has a computerised library system that allows students to borrow books for a fixed length
of time. The system uses text files to store details of students, books and loans.
A new module is to be written which will generate emails to each student who has an overdue
book.
(a) Decomposition will be used to break down the problem of designing the new module 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]
(b) The program designer produces a structure chart for the new module. Part of the structure
chart is shown:
Module-A()
Module-B()
Module-C()
Module-D()
(i)
Explain the relationship between the four modules shown.
…
…
…
… [2]
(ii)
Two new modules are added: Module‑X() and Module‑Y().
•
Module‑X() has no parameters.
•
Module‑Y() will take a string and a real number as parameters and return a
Boolean value.
•
Module‑D() will call either Module‑X() or Module‑Y().
Draw only the part of the structure chart that represents the relationship between
Module‑X(), Module‑Y() and Module‑D().
[3]

100
9618/21/M/J/23 · Question 8May/June 2023Paper 2121 marks
Loading question…
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>
Item information is as follows:
Format
Comment
unique for each item in the range
ItemNum
4 numeric characters
"0001" to "5999" inclusive
SupplierCode
5 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
SuppExists()
•
called with a parameter of type string representing a supplier code
(already written)
•
returns TRUE if the supplier code is already in use, otherwise returns
FALSE
IsNewSupp()
•
called with a parameter of type string representing a new supplier code
•
returns TRUE if the string only contains alphabetic characters (either
upper or lower case) and the supplier code is not already in use,
otherwise returns FALSE
(a) Write pseudocode for module IsNewSupp().
Module SuppExists() has already been written and should be used as part of your solution.
Module SuppExists() will generate a run-time error if the given parameter is not
5 characters in length.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

101
9618/22/M/J/23 · Question 1May/June 2023Paper 2210 marks
Loading question…
Question text

1
A program calculates the postal cost based on the weight of the item and its destination.
Calculations occur at various points in the program and these result in the choice of several
possible postal costs. The programmer has built these postal costs into the program.
For example, the postal cost of $3.75 is used in the following lines of pseudocode:
IF Weight < 250 AND ValidAddress = TRUE THEN
3.75
// set postal cost for item to $3.75
ItemPostalCost
"Valid"
// item can be sent
ItemStatus
ENDIF
(a) (i)
Identify a more appropriate way of representing the postal costs.
… [1]
(ii)
Describe the advantages of your answer to part (a)(i) with reference to this program.
…
…
…
…
…
… [3]
(b) The lines of pseudocode contain features that make them easier to understand.
State three of these features.
1 …
2 …
3 …
[3]
(c) Give the appropriate data types for the following variables:
ValidAddress …
ItemPostalCost …
ItemStatus …
[3]

102
9618/22/M/J/23 · Question 4May/June 2023Paper 226 marks
Loading question…
Question text

4
A function GetNum() will:
1.
take two parameters: a string and a character
2.
count the number of times that the character occurs in the string
3.
return the count.
Any comparison between characters needs to be case sensitive. For example, character 'a' and
character 'A' are not identical.
Write pseudocode for function GetNum().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]

103
9618/22/M/J/23 · Question 5May/June 2023Paper 228 marks
Loading question…
Question text

5
A programmer has produced the following pseudocode to output the square root of the numbers
from 1 to 10.
Line numbers are for reference only.
10
DECLARE Num : REAL
1.0
11
Num
...
40
REPEAT
41
CALL DisplaySqrt(Num)
Num + 1.0
42
Num
43
UNTIL Num > 10
...
50
PROCEDURE DisplaySqrt(BYREF ThisNum : REAL)
51
OUTPUT ThisNum
SQRT(ThisNum)
// SQRT returns the square root
52
ThisNum
53
OUTPUT " has a square root of ", ThisNum
54
ENDPROCEDURE
The pseudocode is correctly converted into program code.
Function SQRT() is a library function and contains no errors.
The program code compiles without errors, but the program gives unexpected results. These are
caused by a design error.
(a) Explain why the program gives unexpected results.
…
…
…
…
…
… [3]
(b) Explain why the compiler does not identify this error.
…
… [1]
(c) Describe how a typical Integrated Development Environment (IDE) could be used to identify
this error.
…
…
…
…
…
… [3]
(d) The pseudocode is converted into program code as part of a larger program.
During compilation, a complex statement generates an error.
The programmer does not want to delete the complex statement but wants to change the
statement so that it is ignored by the compiler.
State how this may be achieved.
…
… [1]

Advertisement
104
9618/22/M/J/23 · Question 6May/June 2023Paper 226 marks
Loading question…
Question text

6
A procedure Square() will take an integer value in the range 1 to 9 as a parameter and output a
number square.
The boundary of a number square is made up of the character representing the parameter value.
The inside of the number square is made up of the asterisk character (*).
1
2
3
4
9
Parameter value
...
...
99 9 9 99 9 9 9
44 4 4
33 3
1
22
9 * * * ** * * 9
4* * 4
3* 3
22
9 ** * *** * 9
4** 4
333
9 *** **** 9
4444
Output
9 * * * ** * * 9
9 * * * ** * * 9
9 ** * *** * 9
9 ******* 9
999999999
The pseudocode OUTPUT command starts each output on a new line. For example, the following
three OUTPUT statements would result in the outputs as shown:
OUTPUT "Hello"
OUTPUT "ginger"
OUTPUT "cat"
Resulting output:
Hello
ginger
cat
Write pseudocode for procedure Square().
Parameter validation is not required.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

105
9618/22/M/J/23 · Question 7May/June 2023Paper 229 marks
Loading question…
Question text

7
A computer system for a shop stores information about each customer. The items of information
include name and address (both postal and email) together with payment details and order history.
The system also stores the product categories they are interested in and how they would like to be
contacted.
(a) The shop wants to add a program module that will generate emails to be sent to customers
who may be interested in receiving details of new products.
(i)
State three items of information that the new module would need. Justify your choice in
each case.
Information …
Justification …
…
Information …
Justification …
…
Information …
Justification …
…
[3]
(ii)
Identify two items of customer information that would not be required by the new module.
Justify your choice in each case.
Information …
Justification …
…
Information …
Justification …
…
[2]
(b) The program includes a module to validate a Personal Identification Number (PIN). This is
used when customers pay for goods using a bank card.
A state‑transition diagram has been produced for this module.
The table show the inputs, outputs and states for this part of the program:
Current state
Input
Output
Next state
S1
Input PIN
S2
S2
Re‑input PIN
Display error
S2
S2
Cancel
Re‑prompt
S1
S2
Valid PIN
Enable payment
S4
S2
Too many tries
Block Account
S3
Complete the state‑transition diagram to represent the information given in the table.
S2
START
S1
Cancel | Re-prompt
[4]

Advertisement