Variant 21: May/June/2025
CONSTRUCT: sequence, selection and iteration (repetition)
9618/21/M/J/25/Q3 | 9.2 Algorithms
A student has been asked to create a simple guessing game program. This program will generate a random integer value between 1 and 100. It will then repeatedly prompt the user to input an integer value until they input the randomly generated value.
The student has written a structured English description:
step 1 – randomly generate an integer value between 1 and 100 inclusive
step 2 – prompt the user to input an integer value
step 3 – output an appropriate message if the value input was too high; then repeat from step 2
step 4 – output an appropriate message if the value input was too low; then repeat from step 2
step 5 – output an appropriate message if the value input was the same value that was randomly generated; then end the program.
Write a pseudocode algorithm from this structured English description. Assume no input validation is needed. [8]
Markscheme:
Efficient Bubble sort | Procedure | 2D Arrays | Constructs (iteration)
9618/21/M/J/25/Q6(b) | 10.2 Arrays
Each sensor used in the system has a unique sensor ID number in the range 1 to 50.
The program that is used to monitor the speed of each vehicle reads each sensor value every second and stores this value along with the sensor’s unique ID into a global 2D array Reading
The global array Reading has been declared as follows:
Write efficient pseudocode for the procedure Sort(). [8]
Markscheme:
Functions | Constructs (iteration[repetition]) -> WHILE Loop
9618/21/M/J/25/Q7(a) | 11.3 Structured Programming
A program is being developed to implement a customer loyalty scheme for a coffee shop.
The programmer has decided that the following data items need to be stored for each customer:
When a customer visits the shop and orders coffee, the scheme operates as follows:
• The total number of points is increased by the number of coffees ordered.
• If just one cup of coffee is ordered and the number of points goes above 10, then:
◦ the cup of coffee they have just ordered is given to them free of charge
◦ the number of points is reduced by 11.
• If the order is for multiple coffees and the number of points goes above 10, then:
◦ they get one coffee free of charge for every 11 points
◦ the number of points is reduced by 11 for each free coffee.
For example, the:
• customer currently has 9 points
• customer orders 16 cups of coffee
• total number of points now becomes 25
• customer gets 2 free coffees and now has 3 points left.
The programmer has defined a program module that is called every time a customer places an order:
Write pseudocode for module CustomerOrder(). [6]
Markscheme:
Functions| File Handling | String Manipulation | Constructs (Iteration)
9618/21/M/J/25/Q7(b)(i) | 11.3 Structured Programming
A text file Loyalty.txt will be used to store the data items for the loyalty scheme. The data items for each customer will be stored on a separate line of the text file where each data item is separated by a comma:
<CustomerID>,<Points>
The contents of the text file Loyalty.txt will always be stored in ascending order by customer ID.
When the data items are read from or written to the text file Loyalty.txt, they may need to be converted to the appropriate data type.
Each customer has a unique customer ID starting at "100001" with this value increasing by one each time a new customer joins the loyalty scheme.
When a customer joins the loyalty scheme, they are assigned the next customer ID and value of points is set to 0.
For example, if the loyalty scheme has 204 customers and a new customer joins the loyalty scheme, the following line is added to the text file Loyalty.txt:
"100205,0"
You can assume that the number of customers in the loyalty scheme will never be more than 9000.
The programmer has defined a program module as follows:
Write pseudocode for module AddNewCustomers().
Assume that there is at least one customer already in the loyalty scheme. [8]
Markscheme:
Variant 22: May/June/2025
Arrays (2D) | Declaration of Array
9618/22/M/J/25/Q1(d)(iii)
Give the pseudocode declaration for the array Product. [2]
Markscheme:
Case Constructs (Selection, Iteration)
9618/22/M/J/25/Q3 | 9.2 Algorithms
An algorithm is designed to generate and output two unique random integers. Each integer value is between –10 and 10 inclusive.
If both integers output are negative, a third random integer between 30 and 35 inclusive will be generated and output.
Write pseudocode for this algorithm. [8]
Markscheme:
File Handling | String Manipulation | Constructs (Iteration, Selection) | Arrays (usage in alternative solution)
9618/22/M/J/25/Q5(b)
At the end of each sequence of pictures, the time is saved as a string in the format
• HH represents the hours using two digits
• MM represents the minutes using two digits
• SS represents the seconds using two digits.
For example:
• "081230" is stored to represent the time 8:12:30, in the morning
• "152235" is stored to represent the time 15:22:35, in the afternoon.
Each string is stored on a new line in the text file TimeTaken.txt.
An algorithm is required to process the content of the text file TimeTaken.txt once it has been transferred to the computer.
For each hour when pictures are taken, output a suitable message showing the hour and the total number of sequences of pictures taken within that hour.
Example outputs:
Write pseudocode for this algorithm.
Assume the text file TimeTaken.txt contains at least one line. [8]
Markscheme:
Alternative solution and mark scheme use of an array to hold count for each hour
Also, for use of 24 variables and 24 selection conditions
Linear Search | Arrays (2D) | Functions | Case Constructs (Iteration) WHILE Loop, REPEAT Loop ; (selection)
9618/22/M/J/25/Q7(a)
A program is being developed to implement a customer loyalty scheme for a coffee shop.
Each customer has a unique customer ID starting at 10001 with this value increasing by one each time a new customer joins the loyalty scheme.
For example, the third customer who joins the loyalty scheme is given the customer ID 10003 The loyalty scheme is limited to 1000 customers.
A customer is awarded a loyalty point every time they buy a coffee.
The programmer has decided to use a global 2D array Loyalty of type INTEGER.
The array Loyalty is made up of 1000 rows and 2 columns.
Each row relates to one customer; column 1 contains the unique customer ID and column 2 contains the number of customer loyalty points.
Rows in the array Loyalty that are not currently being used have the value of Column 1 set to 99999 The array is sorted in ascending order by customer ID.
The programmer has defined a program module:
Write efficient pseudocode for module FindCustomer(). [8]
Markscheme:
Functions | 2D Arrays | Constructs (iteration, selection)
9618/22/M/J/25/Q7(b)
A customer can claim a free coffee for every 11 loyalty points.
The programmer has defined a second program module:
Write efficient pseudocode for module PointsReport()
Assume the array contains the data for at least one customer. [7]
Markscheme:
Example solution:
Variant 23: May/June/2025
Functions | Case Constructs (iteration [repetition])
9618/23/M/J/25/Q3
A programmer has been asked to create a module RollDice() to simulate multiple rolls of a dice. This module will be used as part of a program for a game.
The module will:
Write pseudocode for the module RollDice(). [7]
Markscheme:
String Manipulation | Functions | Constructs (iteration)
9618/23/M/J/25/Q5
A module Parity() takes a string as a parameter. The parameter has the identifier BitString and it represents a binary value.
The module will concatenate a single character to the end of BitString by applying one of the two rules:
The modified value of BitString is then returned.
For example:
Write pseudocode for the module Parity().
Assume parameter BitString can only contain the characters '0' and '1'. [8]
Markscheme:
Definining Modules (Functions, Procedures)
9618/23/M/J/25/Q6(b) | 12.2 Program Design
Study the structure chart:
Some of the parameter data types are:
Some of the modules in the structure chart are functions, others are procedures. Write the pseudocode to define the module headers: [5]
Markscheme:
Procedure + Parameters (using BYREF) | Constructs (Selection)
9618/23/M/J/25/Q7(a)(i) | 11.1 Programming Basics
A program is being developed to implement a customer loyalty scheme for a coffee shop.
The programmer has decided that the following data items need to be stored for each customer:
The programmer has defined a program module:
Write pseudocode for module UpdateVisit().
Assume the customer has made at least one previous visit. [5]
Markscheme:
Ameding module for selection statement
9618/23/M/J/25/Q7(a)(ii) | 11.3 Structured Programming
The programmer decides to amend the UpdateVisit() module so that loyalty points are further increased if the customer visits the coffee shop the same day of the week as their last visit.
Write the pseudocode for this condition. [1]
Markscheme:
String Manipulation | Functions |File Handling | Constructs (Selection)
9618/23/M/J/25/Q7(b)(i)
A text file Loyalty.txt will be used to store the data items for the loyalty scheme.
The text file Loyalty.txt contains only one line of data for each customer.
Each data item is separated by a comma:
LastVisitDateString is always eight characters in length in the format: DDMMYYYY.
An example of how a line of data will be stored in the text file Loyalty.txt is:
This example shows that the customer with an ID of 100123 had 132 loyalty points following their last visit to the coffee shop on 05/03/2025.
If a customer visits the coffee shop on a Monday, the value of their loyalty points is increased by 10.
The programmer has defined two more program modules:
Write pseudocode for module MondayCheck()
The module FindCustomer() must be used and assume it returns a valid string for the current customer. [8]
Markscheme:
String Manipulation (from Insert)
9618/23/M/J/25/Q7(b)(ii)
A date is stored in LastVisitDateString in the format: DDMMYYYY
DD is a 2-digit string
MM is a 2-digit string
YYYY is a 4-digit string.
For example, the date 03/09/2024 is stored as "03092024"
An algorithm is needed to convert the string stored in LastVisitDateString to data type DATE which is then stored in the variable LastVisitDate.
Complete the pseudocode for this algorithm:
Assume that LastVisitDateString has been declared and contains valid data. [4]
Markscheme:
Variant 21: May/June/2024
Arrays (1D) | Functions | Constructs (Iteration, Selection)
9618/21/M/J/24/Q4
Writing a Function w/ Array, counting odd and even index locations
A global 1D array Data contains 100 elements of type integer.
A function Check() will:
Write pseudocode for the function Check(). [6]
Markscheme:
Modifying Selection Statement
9618/21/M/J/24/Q5(b)(i)
The procedure is to be modified. If variable C is assigned a value other than 'X', 'Y' or 'Z', then procedure Error() is called and passed the value of variable C as a parameter.
This modification can be implemented by adding a single line of pseudocode.
Write the single line of pseudocode. [1]
Markscheme:
Functions | Case Constructs (Selection)
9618/21/M/J/24/Q6(a)
Three points on a grid form a triangle with sides of length A, B and C as shown in the example:
A function IsRA() will:
• take three sets of integers as parameters representing the coordinates of the three endpoints that form a triangle
• return TRUE if the endpoints form a right-angled triangle, otherwise return FALSE.
In pseudocode, the operator ‘^’ represents an exponent, which is the number of times a value is multiplied by itself.
For example, the expression Value2 may be written in pseudocode as
Value ^ 2
Complete the pseudocode for the function IsRA(). [6]
Markscheme:
Data Types| Parameters (& passing mechanisms)| Function vs Procedure (when to use)
9618/21/M/J/24/Q7(b)(ii)
The structure chart illustrates part of the membership program:
Write the pseudocode module headers for Sub-A and Sub-B. [4]
Markscheme:
String Manipulation | Functions | Constructs (Iteration & Selection)
9618/21/M/J/24/Q8(a)
Wrting Pseudocode INCLUDING File Handling, String Manipulation
A teacher is designing a program to process pseudocode projects written by her students.
Each student project is stored in a text file.
The process is split into a number of stages. Each stage performs a different task and creates a new file named as shown:
The teacher has defined the first program module as follows:
Complete the pseudocode for module DeleteComment(). [8]
Markscheme:
Functions | File Handling | String Manipulation | Constructs (Selection & Iteration)
9618/21/M/J/24/Q8(b)
Writing a Function using File Handling
A second module is defined:
Write pseudocode for module Stage_1().
Module DeleteComment() must be used in your solution. [7]
Markscheme:
Example:
Variant 22: May/June/2024
Case Constructs (Selection, Iteration)
9618/22/M/J/24/Q2(b)
A different part of the program contains an algorithm represented by the following program flowchart:
Write pseudocode for the algorithm. [5]
Markscheme:
Data Structures | Arrays
9618/22/M/J/24/Q3(a)(i)
A factory needs a program to help manage its production of items.
Data will be stored about each item. The data for each item will be held in a record structure of type Component.
The programmer has started to define the fields that will be needed as shown in the table.
Write pseudocode to declare the record structure for type Component. [4]
Markscheme:
Declaring a (1D) Array
9618/22/M/J/24/Q3(a)(ii)
A 1D array Item of 2000 elements will store the data for all items.
Write pseudocode to declare the Item array. [2]
Markscheme:
Case Constructs (Selection)
9618/22/M/J/24/Q4
A triangle has sides of length A, B and C.
In this example, A is the length of the longest side.
This triangle is said to be right‑angled if the following equation is true:
A procedure will be written to check whether three lengths represent a right‑angled triangle.
The lengths will be input in any sequence.
The procedure IsRA() will:
• prompt and input three integer values representing the three lengths
• test whether the three lengths correspond to the sides of a right‑angled triangle
• output a suitable message.
The length of the longest side may not be the first value input.
Write pseudocode for the procedure IsRA(). [5]
Markscheme:
Functions | String Manipulation | Case Constructs (Iteration & Selection)
9618/22/M/J/24/Q6(a)
A music player stores music in a digital form and has a display which shows the track being played.
Up to 16 characters can be displayed. Track titles longer than 16 characters will need to be trimmed as follows:
• Words must be removed from the end of the track title until the resulting title is less than 14 characters.
• When a word is removed, the space in front of that word is also removed.
• Three dots are added to the end of the last word displayed when one or more words have been removed.
The table below shows some examples:
A function Trim() will:
• take a string representing the original title
• return the string to be displayed.
Assume:
• Words in the original title are separated by a single space character.
• There are no spaces before the first word or after the last word of the original title.
• The first word of the original title is less than 14 characters.
Write pseudocode for the function Trim(). [7]
Markscheme:
Functions | String Manipulation | Case Constructs (Iteration and Selection)
9618/22/M/J/24/Q8(b)
The teacher has defined the first program module as follows:
Complete the pseudocode for module DeleteSpaces(). [6]
Markscheme:
Example algorithm based on finding position of first non-space character and then using substring function:
Functions | String Handling | File Handling | Case Constructs (Iteration & Selection)
9618/22/M/J/24/Q8(c)
Two modules are defined:
Write pseudocode for module Stage_2().
Modules DeleteComment() and DeleteSpaces() must be used in your solution. [8]
Markscheme:
Example:
Variant 23: May/June/2024
Arrays | Case Construct (Selection)
9618/23/M/J/24/Q3(a)(i)
A record structure is declared to hold data relating to components being produced in a factory:
The factory normally produces a batch (or set) of 1000 components at a time. A global array is declared to store 1000 records for a batch:
DECLARE Batch : ARRAY [1:1000] OF Component
Two global variables contain the minimum and maximum acceptable weight for each component. The values represent an inclusive range and are declared as:
DECLARE Min, Max : REAL
A program uses a variable ThisIndex as the array index to access a record.
Write a pseudocode clause to check whether or not the weight of an individual component is within the acceptable range. [3]
Markscheme:
Case Constructs (Iteration [repetition])| Procedure
9618/23/M/J/24/Q4(a)
A procedure TwoParts() will input a sequence of real values, one at a time.
The procedure will:
• process the sequence in two parts
• form a first total by adding the values until the first zero
• form a second total by adding the values after the first zero until the second zero
• output the average of the two totals, together with a suitable message.
Values input in the first part are totalled using global variable TotalA and those input in the second part are totalled using global variable TotalB.
Write pseudocode for the procedure TwoParts(). [6]
Markscheme:
Functions | String Manipulation | Case Constructs (Selection, Iteration, Sequence) -> depends on which solution you use
9618/23/M/J/24/Q6(a)
A program displays a progress bar to inform the user of the progress of tasks that take a significant time to complete, such as those involving file transfer operations.
Task progress is divided into 11 steps. Each step represents the amount of progress as a percentage. An image is associated with each step and each image is stored in a different file.
Different progress bar images may be selected. For a given image, files all have the same filename root, with a different suffix.
The table illustrates the process for using the image with filename root BargraphA.
A procedure Progress() will:
• be called with two parameters:
○ an integer representing the percentage progress (0 to 100 inclusive)
○ a string representing the image filename root
• generate the full image filename
• call a procedure Display() using the full image filename as the parameter.
Write pseudocode for procedure Progress(). [6]
Markscheme:
Functions | Defining Module Header
9618/23/M/J/24/Q6(b)(i)
The definition of procedure Progress() is provided here for reference:
Progress() will be rewritten and a new module Progress2() produced with these requirements:
• an additional parameter of type integer will specify the total number of steps
• the image filename will be returned (procedure Display() will not be called from within Progress2()).
Write pseudocode for the new module header.
Markscheme:
Functions | String Manipulation | Constructs (Selection)
9618/23/M/J/24/Q8(a)
A teacher is designing a program to process pseudocode projects written by her students.
The program analyses a student project and extracts information about each module that is defined (each procedure or function).
This information is stored in a global 2D array ModInfo of type string.
A module header is the first line of a module definition and starts with either of the keywords PROCEDURE or FUNCTION.
An example of part of the array is given below. Row 10 of the array shows that a procedure header occurs on line 27 and row 11 shows that a function header occurs on line 35. "P" represents a procedure and "F" represents a function:
The string stored in column 3 is called the module description. This is the module header without the keyword.
A valid module header will:
• be at least 13 characters long
• start with the keyword PROCEDURE or FUNCTION. The keyword may appear in either upper or lower case (or a mix of both) and must be followed by a space character.
The teacher has defined the first program module as follows:
Write pseudocode for module Header(). [7]
Markscheme:
Functions | Arrays (2D) | Constructs (Iteration & Selection) |
File Handling | String Manipulation
9618/23/M/J/24/Q8(b)
A new module is required:
As a reminder, the previous example of part of the array is repeated below:
Write pseudocode for module FindModules().
Assume that the array contains enough rows for the number of modules in each project. [8]
Markscheme:
Example:
Variant 21: Oct/Nov/2024
Case Constructs (Selection statement) - Completing the keyword
9618/21/O/N/24/Q1(d)
The final CASE condition (> 200) in the pseudocode example could be replaced with a keyword.
Give the keyword. [1]
Markscheme:
Procedure| Case Constructs (Selection) -> using conditional logic
9618/21/O/N/24/Q2
A program uses three global integer variables HH, MM and SS to represent the current time in hours, minutes and seconds using the 24-hour clock notation.
Midnight would be represented as 00:00:00 (HH:MM:SS). If the variables HH, MM and SS contained the values 16, 30 and 10 respectively, then the time would be 16:30:10 or just after 4.30 in the afternoon.
A procedure Tick() will be called every second.
The procedure Tick() will:
• update the value in SS each time it is called
• update the values in HH and MM as appropriate
• call a procedure CheckAlarm() at the start of each minute
• call a procedure NewDay() whenever the time reaches midnight.
Complete the pseudocode for procedure Tick(). [6]
Markscheme:
Functions | String Manipulation | Case Constructs (selection, sequence)
9618/21/O/N/24/Q4(c)
The module to perform the checks and calculation will be implemented as a function. The function will need to return both a real and a Boolean value.
To achieve this a record type is defined in pseudocode as follows:
The function Evaluate() will:
• take two parameters of type string representing the two numeric values
• return a variable of type Result with the Done field set to FALSE if either of the following applies:
◦ at least one of the strings does not represent a valid numeric value
◦ the numeric value of the string representing value y is zero
• otherwise return a variable of type Result with the Done field set to TRUE and the Value field assigned the result of the formula (based on the numeric value of the two parameters).
Write pseudocode for the function Evaluate(). [6]
Markscheme:
Functions | Arrays (1D) | Constructs (Selection, Sequence)
9618/21/O/N/24/Q6(b)
A factory produces food items. The items must be used within a certain number of days after their production date.
The number of days is known as the shelf life. It is different for each type of item but is always a whole number in the range 1 to 21 (inclusive).
The latest date that an item can be used is called the ‘use-by’ date. A program is needed to produce labels which show the ‘use-by’ date.
Part of the program is a function GetDate() which will:
• take two parameters: a production date and a value representing the shelf life
• return the corresponding ‘use-by’ date.
The program contains a global 1D array DaysInMonth of type integer which stores the number of days in each month (index 1 is January):
Complete the pseudocode for the function GetDate(). Date functions from the insert should be used in your solution. [7]
Markscheme:
Functions |Arrays | Case Constructs (Iteration, selection) -> depends on what solution you use
9618/21/O/N/24/Q8(a)
An exam paper has a maximum of 75 marks. One of five pass grades (A to E) is assigned, depending on the mark obtained. The lowest mark for a given grade is known as the grade boundary. For example, if the grade boundary for an A grade is 65 marks, then any candidate who achieves a mark of 65 or above will be awarded an A. A grade of U is awarded for marks below the E grade boundary.
The five grade boundaries are stored in a global 1D array GradeBoundary of type integer.
For example:
A global 2D array Result of type integer contains candidate marks for the exam. Each row relates to one candidate. Column 1 contains the candidate mark and column 2 contains the unique candidate ID.
For example, for the fourth and fifth candidates:
There are more rows in the array than candidates who sit the exam. Any unused rows will be at the end of the array.
Candidate papers that are given a mark within two marks of any grade boundary must be checked.
For example, given the values in the example grade boundaries above, any paper that was awarded between 41 and 45 marks (inclusive) would need to be checked.
A program is being written to identify papers that need to be checked.
The programmer has defined the first program module as follows:
Write pseudocode for module CheckMark(). [6]
Markscheme:
Functions | Arrays (2D) |File Handling | Case Constructs (Iteration & Selection)
9618/21/O/N/24/Q8(b)
A second module is defined:
Write pseudocode for module CheckAll().
CheckMark() must be used to check each individual mark. [8]
Markscheme:
Variant 22: Oct/Nov/2024
Functions | String Manipulation | Case Constructions (Iteration)
9618/22/O/N/24/Q2(a)
A program is being developed to process bank card information.
When a card number is displayed, all the characters except the last four are replaced with the asterisk character '*'. Card numbers are stored as strings.
The strings are between 10 and 20 characters in length.
The function Conceal() will take a string representing a card number and return a modified string.
Example strings:
The function Conceal() will:
• take a numeric string as a parameter representing the card number
• return a string in which the asterisk character replaces all except the last four characters of the card number parameter.
Write pseudocode for the function Conceal(). [6]
Markscheme:
Defining an Array (2D)
9618/22/O/N/24/Q2(b)(i)
The requirements have been changed. Conceal() will now be written as a procedure which will process 100 card numbers each time it is called.
The card numbers will be stored in a 2D array CardNumber.
The original string will be stored in column one and the modified string in column two.
Write pseudocode to declare the array. [2]
Markscheme:
Functions | Case Constructs (Selection)
9618/22/O/N/24/Q3(b)
A function to add a value to ThisStack is expressed in pseudocode as shown. The function will return a value to indicate whether the operation was successful or not.
Complete the pseudocode by filling in the gaps. [4]
Markscheme:
Functions | Case Constructs (Iteration and Selection)
9618/22/O/N/24/Q4
A global integer variable Tick is always incremented every millisecond (1000 times per second) regardless of the other programs running.
The value of Tick can be read by any program but the value should not be changed.
Assume that the value of Tick does not overflow.
As an example, the following pseudocode algorithm would output "Goodbye" 40 seconds after outputting "Hello".
A program is needed to help a user to time an event such as boiling an egg.
The time taken for the event is known as the elapsed time.
The program contains a procedure Timer() which will:
• take two integer values representing an elapsed time in minutes and seconds
• use the value of variable Tick to calculate the elapsed time
• output a warning message 30 seconds before the elapsed time is up
• output a final message when the total time has elapsed.
Write pseudocode for the procedure Timer(). [6]
Markscheme:
Functions | Case Constructs (Selection Statement)
9618/22/O/N/24/Q5(c)
A program contains a global 1D array Data with 100 elements of type INTEGER. The program contains a function Process() expressed in pseudocode as follows:
The function Process() contains a selection construct using a CASE structure.
Write pseudocode using a single selection construct with the same functionality without using a CASE structure. [2]
Markscheme:
Functions | Arrays | String Manipulation | Case Constructs (Iteration and Selection)
9618/22/O/N/24/Q6(a)
A shop sells sandwiches and snacks. The owner chooses a ‘daily special’ sandwich which is displayed on a board outside the shop. Each ‘daily special’ has two different fillings and is made with one type of bread.
The owner wants a program to randomly choose the ‘daily special’ sandwich.
The program designer decides to store the possible sandwich fillings in a 1D array of type string.
The array is declared in pseudocode as follows:
DECLARE Filling : ARRAY [1:35] OF STRING
Each element contains the name of one filling.
An example of the first five elements is as follows:
Both arrays may contain unused elements. The value of these will be an empty string and they may occur anywhere in each array.
A procedure Special() will output a message giving the ‘daily special’ sandwich made from two randomly selected different fillings and one randomly selected bread.
Unused array elements must not be used when creating the ‘daily special’ sandwich.
Using the above examples, the output could be:
"The daily special is Cheese and Onion on Brown bread."
Complete the pseudocode for the procedure Special().
Assume that both arrays are global. [7]
Markscheme:
Functions | Arrays (1D) | Linear Search | Constructs (Iteration and Selection)
9618/22/O/N/24/Q8(a)
A program is being developed to implement a game for up to six players.
During the game, each player assembles a team of characters. At the start of the game there are 45 characters available.
Each character has four attributes, as follows:
The programmer has defined a record type to define each character.
The record type definition is shown in pseudocode as follows:
The Player field indicates the player to which the character is assigned (1 to 6). The field value is 0 if the character is not assigned to any player.
The programmer has defined a global array to store the character data as follows:
DECLARE Character : ARRAY[1:45] OF CharacterType
At the start of the game all record fields are initialised, and all Player field values are set to 0
The programmer has defined a program module as follows:
Write pseudocode for module Assign(). [7]
Markscheme:
Arrays | File Handling | String Manipulation | Constructs (Iteration)
9618/22/O/N/24/Q8(b)
A new module will store the contents of the Character array in a text file.
The module is defined as follows:
Complete the pseudocode for module Save(). [7]
Markscheme:
Variant 23: Oct/Nov/2024
Case Constructs (Iteration and Selection)
9618/23/O/N/24/Q2(a)
An algorithm will:
1. prompt and input a sequence of 100 integer values, one at a time
1. 2. sum the positive integers
2. 3. output the result of the sum.
Write pseudocode for the algorithm.
Assume the value zero is neither positive nor negative. You must declare all variables used in the algorithm. [5]
Markscheme:
Arrays | Case Constructs (Iteration and Selection) | Sequence
9618/23/O/N/24/Q4(a)
An examination paper has a maximum of 75 marks.
One of five pass grades (A to E) is assigned, depending on the mark obtained. The lowest mark for a given grade is known as the grade boundary.
A program is being written to process examination marks. The five grade boundaries are stored in a global 1D array GB of type INTEGER, for example:
Complete the pseudocode. [4]
Markscheme:
Functions | Arrays | Case Constructs (usage of iteration & selection techniques)
9618/23/O/N/24/Q4(b)(ii)
A procedure GBInitialise() will initialise the Check array using values from the GB array.
Note it can be assumed that the maximum grade boundary value for A is 70 and the minimum value for E is 15.
Write pseudocode for the procedure. [6]
Markscheme:
Functions | Case Constructs (Iteration and Selection) -> depends on what solution you use (loop or no loop)
9618/23/O/N/24/Q6
In some countries, on the third Sunday in March, daylight saving time begins when clocks move forward by one hour.
A module AdjustClock() will take an integer parameter representing a year. The module will return an integer value representing the number of the day in March on which the clocks move forward.
For example, the following line of pseudocode would assign DayNumber the value 20: DayNumber ←AdjustClock(2022)
Write pseudocode for the function AdjustClock().
Date functions from the insert should be used in your solution. [7]
Markscheme:
Functions | Arrays | Case Constructs (Iteration and Selection)
9618/23/O/N/24/Q8(a)
A program is being developed to implement a game for up to six players.
During the game, each player assembles a team of characters. At the start of the game there are 45 characters available.
Each character has four attributes, as follows:
The programmer has defined a record type to define each character. The record type definition is shown in pseudocode as follows:
The Player field indicates the player to which the character is assigned (1 to 6). This field value is 0 if the character is not assigned to any player.
The programmer has defined a global array to store the character data, as follows:
DECLARE Character : ARRAY[1:45] OF CharacterType
At the start of the game all record fields are initialised, and all Player fields are set to 0
The programmer has defined a program module as follows:
Complete the pseudocode for module Count(). [7]
Markscheme:
Functions | Arrays | File Handling | String Manipulation | Case Constructs (Iteration [repetition])
9618/23/O/N/24/Q8(b)
The Character array data has been saved in the text file SaveFile.txt
Each line of the file contains one element of the array (one record).
New modules are defined:
As a reminder, the record structure is repeated here:
Write pseudocode for module Restore().
You must use the module Extract(). [7]
Markscheme:
Variant 21: May/June/2023
Declaring Variables + Assignment
9618/21/M/J/23/Q2(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. [3]
Markscheme:
Functions | String Manipulation | Case Constructs (Iteration and Selection)
9618/21/M/J/23/Q4
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]
Markscheme:
Functions | Arrays (2D) | Case Constructs (Iteration and Selection)
9618/21/M/J/23/Q6
A video-conferencing program supports up to six users. Speech from each user is sampled and digitised (converted from analogue to digital). Digitised values are stored in array Sample.
The array Sample consists of 6 rows by 128 columns and is of type integer. Each row contains 128 digitised sound samples from one user.
The digitised sound samples from each user are to be processed to produce a single value which will be stored in a 1D array Result of type integer. This process will be implemented by procedure Mix().
A procedure Mix() will:
• calculate the average of each of the 6 sound samples in a column
• ignore sound sample values of 10 or less
• store the average value in the corresponding position in Result
• repeat for each column in array Sample
The diagram uses example values to illustrate the process:
Write pseudocode for procedure Mix().
Assume Sample and Result are global. [6]
Markscheme:
Functions | String Manipulation | Case Constructs (Selection and Iteration)
9618/21/M/J/23/Q8(a)
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:
Item information is as follows:
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:
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. [7]
Markscheme:
Functions | File Handling | String Manipulation | Linear Search | Case Constructs (Iteration and Selection)
9618/21/M/J/23/Q8(b)
A new module has been defined:
Write efficient pseudocode for module CheckNewItem(). [7]
Markscheme:
Variant 22: May/June/2023
Assignment
9618/22/M/J/23/Q2(a)
A program stores a user’s date of birth using a variable MyDOB of type DATE.
Write a pseudocode statement, using a function from the insert, to assign the value corresponding to 17/11/2007 to MyDOB. [1]
Markscheme:
Assignment
9618/22/M/J/23/Q2(b)
MyDOB has been assigned a valid value representing the user’s date of birth.
Write a pseudocode statement to calculate the number of months from the month of the user’s birth until the end of the year and to assign this to the variable NumMonths.
For example, if MyDOB contains a value representing 02/07/2008, the value 5 would be assigned to NumMonths.
Markscheme:
Functions | String Manipulation | Case Constructs (Iteration and Selection)
9618/22/M/J/23/Q4
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]
Markscheme:
Functions | String Manipulation | Case Constructs (Iteration and Selection)
9618/22/M/J/23/Q6
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 (*).
Write pseudocode for procedure Square().
Parameter validation is not required. [6]
Markscheme:
Functions | String Manipulation | Case Constructs (Selection and Iteration)
9618/22/M/J/23/Q8(a)
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:
Valid item information is as follows:
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:
Write pseudocode for module CheckInfo().
Module OnlyAlpha() should be used as part of your solution. [7]
Functions | Arrays | String Manipulation | File Handling | Case Constructs (Iteration and Selection)
9618/22/M/J/23/Q8(b)
A new module is defined as follows:
As a reminder, the file Stock.txt is organised in ascending order of ItemNum and does not contain all possible values in the range.
Write pseudocode for module AddItem().
Markscheme:
Example of array-based solution:
Variant 23: May/June/2023
Functions | String Manipulation (concatenation operator &) | Case Constructs (Selection and Iteration)
9618/23/M/J/23/Q4
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]
Markscheme:
Functions | String Manipulation | Case Constructs (Iteration and Selection)
9618/23/M/J/23/Q6(a)
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
2. output each integer value between the start and the end value (not including the start and end values), where the sum of the last two digits is 6, for example, 142.
Write pseudocode for procedure Select().
Parameter validation is not required.
Markscheme:
Functions | File Handling | String Manipulation | Case Constructs (Iteration and Selection)
9618/23/M/J/23/Q8(a)
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:
Item information is as follows:
Write pseudocode for module ChangeSupp(). [8]
Markscheme:
Functions | File Handling | String Manipulation | Linear Search | Case Constructs (Iteration and Selection)
9618/23/M/J/23/Q8(b)
A new module is required:
Write pseudocode for module Report_1(). [6]
Markscheme:
Variant 21: Oct/Nov/2023
Functions | Case Constructs (Iteration and Selection)
9618/21/O/N/23/Q4(a)
A global array is declared in pseudocode as follows:
DECLARE Data : ARRAY[1:150] OF STRING
A function TooMany() will:
1. take two parameters: • a string (the search string) • an integer (the maximum value)
2. count the number of strings in the array that exactly match the search string 3. return TRUE if the count is greater than the maximum value, otherwise will return FALSE
Write pseudocode for the function TooMany().
Markscheme:
Linear Search | Case Constructs (Selection and Iteration)
9618/21/O/N/23/Q4(b)
The global array is changed to a 2D array, organised as 150 rows by 2 columns. It is declared in pseudocode as follows:
DECLARE Data : ARRAY[1:150, 1:2] OF STRING
The algorithm for the function in part (a) is changed. Strings will only be counted if both of the following conditions are true:
• The current row is an even number.
• The search string exactly matches the value in either column.
Write pseudocode to check these conditions. Assume that the row index is contained in variable Row and the search string in variable Search. [3]
Markscheme:
Procedures | String Manipulation (concatenation)| Case Constructs (Selection Statement)
9618/21/O/N/23/Q6(a)
The pseudocode OUTPUT command starts each output on a new line.
A new procedure MyOutput() will take a string and a Boolean parameter. MyOutput() may be called repeatedly and will use concatenation to build a string using a global variable MyString, up to a maximum length of 255 characters.
MyString will be output in either of these two cases:
1. The Boolean parameter value is TRUE
2. The resulting string (after concatenation) would be longer than 255 characters.
If MyString is not output, the string is concatenated with MyString.
For example, the calls to MyOutput() given below would result in the output as shown:
Write pseudocode for MyOutput(). [7]
Markscheme:
Procedures | File Handling | Case Constructs (Iteration) | String Manipulation (concatenation)
9618/21/O/N/23/Q8(a)
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:
The programmer has defined the first two program modules as follows:
Write pseudocode for module SendFile(). [7]
Assume:
• module Transmit() has already been written and is used to transmit a message
• the value of MyID may be used as SourceID
• the file specified contains no blank lines
• the file specified does not contain the line "****"
Markscheme:
Functions | Selection Statement (CASE..OF) | String Manipulation (concatenation)
9618/21/O/N/23/Q8(d)
A new module has been
defined:
Write pseudocode for module GetField().
Markscheme:
Variant 22: Oct/Nov/2023
Functions | Case Constructs (Iteration and Selection)
9618/22/O/N/23/Q4(a)
A procedure Count() will:
1. input a value (all values will be positive integers)
2. count the number of odd values and count the number of even values
3. repeat from step 1 until the value input is 99
4. output the two count values, with a suitable message.
The value 99 must not be counted.
Write pseudocode for the procedure Count(). [6]
Markscheme:
Procedures | File Handling | String Manipulation | Case Constructs (Iteration)
9618/22/O/N/23/Q6(a)
A procedure CreateFiles() will take two parameters:
• a string representing a file name
• an integer representing the number of files to be created.
The procedure will create the number of text files specified.
Each file is given a different name. Each file name is formed by concatenating the file name with a suffix based on the file number. The suffix is always three characters.
For example, the call CreateFiles("TestData", 3) would result in the creation of the three files, TestData.001, TestData.002 and TestData.003.
Each file will contain a single line. For example, file TestData.002 would contain the string:
This is File TestData.002
Write pseudocode for CreateFiles().
Assume both parameters are valid and that the integer value is between 1 and 999, inclusive. [6]
Markscheme:
Writing module header (Function)
9618/22/O/N/23/Q6(b)(ii)
A module CheckFiles() will count the number of files produced by CreateFiles() in part (a).
CheckFiles() will take a string representing a file name and return the number of files found.
Write the module header for CheckFiles().
Markscheme:
Functions | Arrays (2D) | Linear Search | String Manipulation | Case Constructs (Iteration and Selection)
9618/22/O/N/23/Q8(a)
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.
Data is sent as individual message strings. Each string contains the destination ID (the ID of the computer that is to receive the message) followed by the data:
Messages may pass through several computers on the way to their destination. When a message arrives at a computer, that is not the destination, the program needs to forward it on to another computer using one of its serial ports.
The port to use is obtained from information that is stored in an array RouteTable.
RouteTable is a global 2D array of integers. It is declared in pseudocode as follows:
DECLARE RouteTable : ARRAY[1:6,1:3] OF INTEGER
The values in the first two columns of RouteTable define a range of ID values. Column 3 gives the corresponding port number to use when forwarding the message to a computer with an ID within this range.
For example, the contents of RouteTable could be:
In this example, a message that arrives with a DestinationID of "283" will be forwarded using port 2.
Row 3 in the example shows an unused row. These may occur anywhere. Unused rows have the column 1 element set to −1. The value of unused elements in the other two columns is undefined.
The programmer has defined the first program module as follows:
Write pseudocode for module GetPort().
Assume DestinationID contains a valid three-digit string.
Markscheme:
Functions | String Manipulation | Case Constructs (Selection) | Stack
9618/22/O/N/23/Q8(b)
Copies of the same program will run on each computer. The program contains a global variable MyID of type string, which contains the unique ID of the computer in which the program is running.
When messages are received, they are placed on one of two stacks. Stack 1 is used for messages that have reached their destination and stack 2 is used for messages that will be forwarded on to another computer.
Additional modules are defined:
Write pseudocode for module ProcessMsg().
Module StackMsg() must be used. [7]
Markscheme:
Variant 23: Oct/Nov/2023
(1D) Array | Declaring / Defining an Array
9618/23/O/N/23/Q2(c)
The requirement changes. Array Data needs to hold 120 elements and each value may include a decimal place.
Write a pseudocode statement to declare the modified array. [2]
Markscheme:
Functions | Case Constructs (Iteration)
9618/23/O/N/23/Q4(a)
A procedure RandList() will output a sequence of 25 random integers, where each integer is larger than the previous one.
Write pseudocode for procedure RandList(). [6]
Markscheme:
Case Constructs (Conditional Statement)
9618/23/O/N/23/Q4(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:
Write a simplified version of the conditional clause. [1]
Markscheme:
String Manipulation | Case Constructs (Selection)
9618/23/O/N/23/Q6(a)
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:
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]
Markscheme:
Defining a Record | Data Types Declaration
9618/23/O/N/23/Q7(b)(i)
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.
Write pseudocode to define MyType. [3]
Markscheme:
Defining a Procedure (Module Header)
9618/23/O/N/23/Q7(b)(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().
Markscheme:
Functions | File Handling | String Manipulation | Case Constructs (Iteration and Selection)
9618/23/O/N/23/Q8(a)
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:
Write pseudocode for module ReceiveFile().
Module GetData() has already been written and must be used. [7]
Markscheme:
Functions | String Manipulation | File Handling (Indirect) | Case Constructs (Iteration and Selection)
9618/23/O/N/23/Q8(c)
Two new modules are defined, which will allow two users to exchange messages.
Write pseudocode for module Chat().
Modules GetData() and Transmit() must be used. [7]
Markscheme:
Variant 21: May/June/2022
Functions | Arrays (1D) | Case Constructs (Iteration and Selection)
9618/21/O/N/22/Q5
A program uses two 1D arrays of type integer. Array1 contains 600 elements and Array2 contains 200 elements.
Array1 contains sample values read from a sensor. The sensor always takes three consecutive samples and all of these values are stored in Array1.
A procedure Summarise() will calculate the average of three consecutive values from Array1 and write the result to Array2.
This will be repeated for all values in Array1. The diagram below illustrates the process for the first six entries in Array1.
Markscheme:
Write pseudocode for the procedure Summarise(). [5]
Markscheme:
Functions | String Manipulation | Case Constructs (Iteration and Selection)
9618/21/O/N/22/Q7(a)(i)
A simple arithmetic expression is stored as a string in the format:
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 '−')
Write pseudocode for the procedure Calculate(). [7]
Markscheme:
Functions | File Handling | Case Constructs (Iteration and Selection)
9618/21/O/N/22/Q8(a)
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:
Write pseudocode for module CheckFile().
Markscheme:
Functions | File Handling | Case Constructs (Iteration and Selection)
9618/21/O/N/22/Q8(c)
Further modules are defined as follows:
Write pseudocode for module CountErrors().
Assume CheckFile() and CheckLine() have been written and can be used in your solution.
Markscheme:
Variant 22: May/June/2022
Functions | Arrays | Case Constructs (Selection and Iteration)
9618/22/O/N/22/Q4(a)
The program flowchart represents a simple algorithm.
Write the equivalent pseudocode for the algorithm represented by the flowchart. [6]
Markscheme:
Amending Pseudocode | Case Constructs (Selection)
9618/22/O/N/22/Q5
Examine the following pseudocode.
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.
Markscheme:
Functions | Case Constructs (Iteration and Selection)
9618/22/O/N/22/Q6(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.
Write pseudocode for the function FindBaseNumber(). [7]
Markscheme:
Procedure | Arrays (1D) | Linear Search | Case Constructs (Selection and Iteration)
9618/22/O/N/22/Q7(a)
A teacher is designing a program to perform simple syntax checks on programs written by students.
Two global 1D arrays are used to store the syntax error data. Both arrays contain 500 elements.
• Array ErrCode contains integer values that represent an error number in the range 1 to 800.
• Array ErrText contains string values that represent an error description.
The following diagram shows an example of the arrays.
Write efficient pseudocode for module OutputError(). [6]
Markscheme:
Efficient Bubble Sort | Procedure | Case Constructs (Selection and Iteration)
9618/22/O/N/22/Q7(b)
Write an efficient bubble sort algorithm in pseudocode for module SortArrays(). [6]
Markscheme:
Arrays (1D) | Declaring an Array
9618/22/O/N/22/Q7(c)(iii)
Write the declaration for the single array in pseudocode. [1]
Markscheme:
Variant 23: May/June/2022
Declaring Record Structure
9618/23/M/J/22/Q5(a)(i)
A program will store attendance data about each employee of a company.
The data will be held in a record structure of type Employee. The fields that will be needed are as shown:
Write pseudocode to declare the record structure for type Employee.
Markscheme:
Arrays | Procedure | Case Constructs (Selection and Iteration)
9618/23/M/J/22/Q5(c)
A procedure Absentees() will output the EmployeeNumber and the Name of all employees who have an Attendance value of 90.00 or less.
Write pseudocode for the procedure Absentees(). Assume that the Staff array is global.
Markscheme:
Functions | Case Constructs (Selection and Iteration) | Recursion
9618/23/M/J/22/Q6(a)
The factorial of a number is the product of all the integers from 1 to that number.
Write pseudocode for the function Factorial().
Markscheme:
Functions | String Manipulation | Case Constructs (Iteration and Selection)
9618/23/M/J/22/Q9(a)
A program allows a user to save passwords used to log in to websites. A stored password is then inserted automatically when the user logs in to the corresponding website.
A student is developing a program to generate a strong password. The password will be of a fixed format, consisting of three groups of four alphanumeric characters, separated by the hyphen character '-'.
An example of a password is: "FxAf-3hzV-Aq49"
A valid password:
• must be 14 characters long
• must be organised as three groups of four alphanumeric characters. The groups are separated by hyphen characters
• may include duplicated characters, provided these appear in different groups.
The programmer has started to define program modules as follows:
Write pseudocode for the module Generate().
Markscheme:
Functions | Arrays (2D) | Linear Search | String Manipulation | Case Constructs (Iteration and Selection)
9618/23/M/J/22/Q9(b)
A global 2D array Secret of type STRING stores the passwords together with the website domain name where they are used. Secret contains 1000 elements organised as 500 rows by 2 columns.
Unused elements contain the empty string (""). These may occur anywhere in the array.
An example of part of the array is:
Write pseudocode for the module AddPassword(). [6]
Markscheme:
Variant 21: Oct/Nov/2022
REPEATED QUESTIONS FROM Variant 21: May/June/2022
Variant 22: Oct/Nov/2022
Repeated questions from Variant 22: May/June/2022
Variant 23: Oct/Nov/2022
Functions | String Manipulation | Case Constructs (Sequence)
9618/23/O/N/22/Q5(a)(i)
A text string contains three data items concatenated as shown:
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. [6]
Markscheme:
Assignment using Record Data Type
9618/23/O/N/22/Q5(b)(i)
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:
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]
Markscheme:
Functions | Case Constructs (Selection)
9618/23/O/N/22/Q6(b)
Components are weighed during manufacture. Weights are measured to the nearest whole gram.
Components that weigh at least 3 grams more than the maximum weight, or at least 3 grams less than the minimum weight, are rejected.
A component is rechecked if it weighs within 2 grams of either the maximum or minimum weight.
The final outcome of weighing each component is shown below:
A function Status() will be called with three parameters. These are integers representing the weight of an individual component together with the minimum and maximum weights.
The value returned from the function will be as follows:
Write pseudocode for Status(). [6]
Markscheme:
Arrays (1D) | Functions | String Manipulation | Linear Search | Case Constructs (Iteration and Selection)
9618/23/O/N/22/Q7(a)
A teacher is designing a program to perform simple syntax checks on programs written by students.
Two global 1D arrays are used to store the syntax error data. Both arrays contain 500 elements.
• Array ErrCode contains integer values that represent an error number in the range 1 to 800.
• Array ErrText contains string values that represent an error description.
Write pseudocode for module OutputRange(). Assume that the two numbers input represent a valid error number range. [8]
Markscheme:
Arrays | Functions | Linear Search | Bubble Sort | Case Constructs (Iteration and Selection)
9618/23/O/N/22/Q7(b)(i)
Two additional modules are defined:
Write pseudocode for the module AddError(). Assume that the error code is not already in the ErrCode array. [6]
Markscheme:
Variant 21: May/June 2021
Defining a Procedure | using Parameters (BYREF)
9618/21/M/J/21/Q2(b)
The definition for module LoanReturn() is amended as follows:
• LoanID and BookID are of type STRING
• Fine is of type REAL
Write the pseudocode header for the amended module LoanReturn(). [2]
Markscheme:
Functions | File Handling | Case Constructs (Selection and Iteration)
9618/21/M/J/21/Q3(b)
A procedure Preview() will:
• take the name of a text file as a parameter
• output a warning message if the file is empty
• otherwise output the first five lines from the file (or as many lines as there are in the file if this number is less than five).
Write pseudocode for the procedure Preview(). [5]
Markscheme:
String Manipulation )
9618/21/M/J/21/Q4(c)(i)
Two changes need to be made to the algorithm.
Change 1: Convert to lower case any character that is not the first character after a space.
Change 2: Replace multiple spaces with a single space.
Change 1 may be implemented by modifying one line of the pseudocode.
Write the modified line. [1]
Markscheme:
Functions | Arrays (2D) | Bubble Sort | Case Constructs (Iteration and Selection)
9618/21/M/J/21/Q5
A global 2D array Result of type INTEGER is used to store a list of exam candidate numbers together with their marks. The array contains 2000 elements, organised as 1000 rows and 2 columns.
Column 1 contains the candidate number and column 2 contains the mark for the corresponding candidate. All elements contain valid exam result data.
A procedure Sort() is needed to sort Result into ascending order of mark using an efficient bubble sort algorithm.
Write pseudocode for the procedure Sort().
Markscheme:
Functions | String Manipulation | Case Constructs (Iteration and Selection)
9618/21/M/J/21/Q7(a)
A program is needed to take a string containing a full name and produce a new string of initials.
Some words in the full name will be ignored. For example, "the", "and", "of", "for" and "to" may all be ignored.
Each letter of the abbreviated string must be upper case.
For example:
The programmer has decided to use a global variable FNString of type STRING to store the full name.
It is assumed that:
• words in the full name string are separated by a single space character
• space characters will not occur at the beginning or the end of the full name string
• the full name string contains at least one word.
The programmer has started to define program modules as follows:
Write pseudocode for the module GetStart().
Markscheme
Functions | String Manipulation | Case Constructs (Selection and Iteration)
9618/21/M/J/21/Q7(c)
As a reminder, the module description of GetWord() is repeated:
Write pseudocode for the module GetWord().
Markscheme:
Variant 22: May/June 2021
Functions | Arrays (1D) | Case Constructs (Iteration and Selection)
9618/22/M/J/21/Q5(a)(i)
A student is learning about arrays.
She wants to write a program to:
• declare a 1D array RNum of 100 elements of type INTEGER
• assign each element a random value in the range 1 to 200 inclusive
• count and output how many numbers generated were between 66 and 173 inclusive.
Write pseudocode to represent the algorithm. [6]
Markscheme:
Case Constructs (Selection statement)
9618/22/M/J/21/Q5(b)(ii)
The following is a pseudocode function.
Line numbers are given for reference only.
Markscheme:
Functions | String Manipulation | Arrays (1D) | Case Constructs (Iteration and Selection)
9618/22/M/J/21/Q6
A procedure CountVowels() will:
• be called with a string containing alphanumeric characters as its parameter
• count and output the number of occurrences of each vowel (a, e, i, o, u) in the string
• count and output the number of occurrences of the other alphabetic characters (as a single total).
The string may contain both upper and lower case characters.
Each count value will be stored in a unique element of a global 1D array CharCount of type INTEGER. The array will contain six elements.
Write pseudocode for the procedure CountVowels().
Markscheme:
Functions | String Manipulation | Linear Search | Arrays (1D) | Case Constructs (Iteration and Selection)
9618/22/M/J/21/Q8(a)
A program is needed to take a string containing a full name and to produce a new string of initials.
Some words in the full name will be ignored. For example, “the”, “and”, “of”, “for” and “to” may all be ignored. Each letter of the new string must be upper case.
For example:
Write pseudocode for the module IgnoreWord(). [5]
Markscheme:
Functions | String Manipulation | Case Constructs (Iteration and Selection)
9618/22/M/J/21/Q8(b)
Write pseudocode for the module GetInitials().
Markscheme:
Variant 23: May/June 2021
Repeated questions from Variant 21: May/June 2021
Variant 21: Oct/Nov/2021
Functions | Case Constructs (Selection and Iteration)
9618/21/O/N/21/Q2(b)
The program flowchart shown describes a simple algorithm.
Write pseudocode for the simple algorithm shown on page 6. [6]
Markscheme:
Functions | Arrays | String Manipulation | File Handling | Case Constructs (Iteration and Selection)
9618/21/O/N/21/Q5(c)
A function LogEvents() will:
• take a Student ID as a parameter
• for each element in the array that matches the Student ID parameter:
◦ add the value of the array element to the existing text file LogFile
◦ assign an empty string to the array element
• count the number of lines added to the file
• return this count.
Write pseudocode for the function LogEvents().
Markscheme:
Functions | Arrays (2D) | Case Constructs (Iteration [repetition])
9618/21/O/N/21/Q6(a)
A mobile phone has a touchscreen. The screen is represented by a grid, divided into 800 rows and 1280 columns.
The grid is represented by a 2D array Screen of type INTEGER. An array element will be set to 0 unless the user touches that part of the screen.
Many array elements are set to 1 by a single touch of a finger or a stylus.
The following diagram shows a simplified touchscreen. The dark line represents a touch to the screen. All grid elements that are wholly or partly inside the outline will be set to 1. These elements are shaded. The element shaded in black represents the centre point.
A program is needed to find the coordinates (the row and column) of the centre point.
The centre point on the diagram above is row 6, column 11. Assume:
• the user may only touch one area at a time
• screen rotation does not affect the touchscreen.
The programmer has started to define program modules as follows:
Write pseudocode to implement the module SetRow(). [5]
Markscheme:
Functions | Arrays (2D) | Linear Search | Case Constructs (Iteration and Selection)
9618/21/O/N/21/Q6(b)
The module description of SearchInRow() is provided here for reference.
Write pseudocode to implement the module SearchInRow().
Markscheme:
Functions | Arrays (2D) | Linear Search | Case Constructs (Selection)
9618/21/O/N/21/Q6(c)
The following new module is introduced:
Write pseudocode to implement the module GetCentreCol().
Markscheme:
Variant 22: Oct/Nov/2021
Procedure | Arrays | String Manipulation | Case Constructs (Iteration and Selection)
9618/22/O/N/21/Q3(b)
A procedure GetIDs() will:
• prompt and input the number of a club
• output the StudentID of all the students who are members of that club
• output a count of all students in the given club.
Write pseudocode for the procedure GetIDs().
Markscheme:
Functions | String Manipulation | File Handling | Case Constructs (Iteration and Selection)
9618/22/O/N/21/Q5(a)
A company has several departments. Each department stores the name, email address and the status of each employee in that department in its own text file. All text files have the same format.
Employee details are stored as three separate data strings on three consecutive lines of the file. An example of the first six lines of one of the files is as follows:
A procedure MakeNewFile() will:
Write pseudocode for the procedure MakeNewFile().
Markscheme:
Functions | Arrays (2D) | Linear Search | Case Constructs (Iteration and Selection)
9618/22/O/N/21/Q6(a)
A mobile phone has a touchscreen. The screen is represented by a grid, divided into 800 rows and 1280 columns.
The grid is represented by a 2D array Screen of type INTEGER. An array element will be set to 0 unless the user touches that part of the screen.
Many array elements will set to 1 by a single touch of a finger or a stylus.
The following diagram shows a simplified touchscreen. The dark line represents a touch on the screen. All grid elements that are wholly or partly inside the outline will be set to 1. These elements are shaded. The element shaded in black represents the centre point of the touch.
Write efficient pseudocode for the module FirstRowSet().
Markscheme:
Functions | Arrays (2D) | Linear Search | Case Constructs (Selection)
9618/22/O/N/21/Q6(d)
An additional module GetCentre() is defined as follows:
Write pseudocode for the module GetCentre().
Markscheme:
Variant 23: Oct/Nov/2021
Repeated questions from Variant 21: Oct/Nov/2021





0 Reviews