Filters
Year Range
20212025
2021
2022
2024
2025
Difficulty
Session
Variant
Sub-topic
169 questions
CAIEAS Level9618-as · Paper 2

Programming

169 questions· page 1 of 17

Q32025 May/Jun·P218MMedium

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.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

....................................................................................................................................................

Similar questions
Q72025 May/Jun·P213 partsMedium
(a)

Write pseudocode for module CustomerOrder()

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................

(b)(i)

Write pseudocode for module AddNewCustomers()

Assume that there is at least one customer already in the loyalty scheme.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.....................................................................................................................................

(b)(ii)

The requirements for AddNewCustomers() are changed. There may be no existing customers in the loyalty scheme.

Explain the changes that will need to be made to the module AddNewCustomers()

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.....................................................................................................................................

Similar questions
Q32025 May/Jun·P228MMedium

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.

Similar questions
Q32025 May/Jun·P237MMedium

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:

step 1 – take a positive integer parameter representing the number of times the dice will be rolled

step 2 – simulate one roll of the dice by generating a random integer between 1 and 6 inclusive

step 3 – output the integer generated

step 4 – repeat, as required from step 2

step 5 – calculate the average value of the random integers generated

step 6 – return the average value.

Write pseudocode for the module RollDice()

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

....................................................................................................................................................

Similar questions
Q52025 May/Jun·P238MMedium

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:

• '0' if BitString contains an even number of 1s
• '1' if BitString contains an odd number of 1s.

The modified value of BitString is then returned.

For example:

ParameterString returnedExplanation
"0010010110""00100101100"there are an even number of 1s in the string passed to Parity() so a '0' is concatenated to the end of BitString
"101010""1010101"there are an odd number of 1s in the string passed to Parity() so a '1' is concatenated to the end of BitString

Write pseudocode for the module Parity()

Assume the parameter BitString can only contain the characters '0' and '1'

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

....................................................................................................................................................

Similar questions
Q72025 May/Jun·P234 partsMedium
(a)(i)

Write pseudocode for module UpdateVisit()

Assume the customer has made at least one previous visit.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

(a)(ii)

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.

...........................................................................................................................................

.....................................................................................................................................

(b)(i)

Write pseudocode for module MondayCheck()

The module FindCustomer() must be used and assume it returns a valid string for the current customer.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

(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.

DECLARE DayInt, MonthInt, YearInt : INTEGER
DECLARE LastVisitDate : DATE
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Similar questions
Q62025 Oct/Nov·P227MMedium

A string function Compare() will compare two strings.

The function will:

  • take four parameters:
    • two strings, String1 and String2
    • a character, Position, to indicate whether String1 will be compared with the start ('s'), or the end ('e') of String2
    • a Boolean, CaseMatters, to indicate whether an upper case character and lower case character (for example, 'A' and 'a') are regarded as different (TRUE), or as the same (FALSE)
  • return FALSE if String2 has fewer characters than String1
  • return TRUE if the comparison is true, otherwise return FALSE

For example:

ParameterReturn value
String1String2CaseMattersPosition
"Cat""Catalogue"TRUE's'TRUE
"CAT""Catalogue"TRUE's'FALSE
"CAT""Catalogue"FALSE's'TRUE
"Cat""Catalogue"TRUE'e'FALSE
"GUE""Catalogue"FALSE'e'TRUE
"Catalogue""Cat"TRUE's'FALSE

Write pseudocode for the function Compare()

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

....................................................................................................................................................

Similar questions
Q12025 Oct/Nov·P234 partsMedium-Easy
(a)

The programmer decides to use a library routine to provide part of the solution. One reason for this is that library routines may perform functions that the programmer is unable to program themselves.

State three other benefits of using library routines in the development of the program.

1 ................................................................................................................................................

2 ................................................................................................................................................

3 ................................................................................................................................................

(b)(i)

State two reasons why the programmer may decide to use a subroutine.

1 ........................................................................................................................................

2 ........................................................................................................................................

(b)(ii)

A function header in pseudocode is defined as:

FUNCTION Pass2(Count : INTEGER) RETURNS BOOLEAN

Complete the table by describing the terms used in the function header.

The first row has been completed.

TermDescription
Pass2the name of the function
Count
BOOLEAN
(c)

Variables in the program have example values:

VariableExample value
DoB23/6/2011
Multiplier2.5
AddressLine[1]"35 Lincoln Avenue"

Complete the table by evaluating each expression using the example values:

ExpressionEvaluates to
LENGTH(NUM_TO_STR(Multiplier))
MONTH(DoB) > 4
15 + STR_TO_NUM(MID(AddressLine[1], 2, 1))
Similar questions
Q42025 Oct/Nov·P236MMedium

A program contains a global 1D array Data containing 20 elements of type INTEGER

A global string NumString represents a sequence of three-digit numbers, separated by commas. For example:

"101,456,219,754,328"

The string contains at least four three-digit numbers. The total number of three-digit numbers in the string is unknown.

A procedure Store() will:

  • extract one three-digit number at a time from NumString
  • convert each of the three-digit numbers extracted to an integer and assign this to the next array element, starting from index 1
  • end when all three-digit numbers have been stored, or when the array is full.

Complete the pseudocode for Store()

All local variables used must be declared.

PROCEDURE Store()
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
ENDPROCEDURE
Similar questions
Q12024 May/Jun·P215 partsMedium-Easy
(a)

The following table shows four valid pseudocode assignment statements.

Complete the table by giving an appropriate data type to declare each of the variables A, B, C and D.

Assignment statementData type
A ← LEFT(MyName, 1)
B ← Total * 2
C ← INT(ItemCost) / 3
D ← "Odd OR Even"
(b)

Other variables in the program have example values as shown:

VariableValue
SortedFalse
Tries9
ID"ZGAC001"

Complete the table by evaluating each expression, using the example values.

ExpressionEvaluates to
Tries < 10 AND NOT Sorted
Tries MOD 4
TO_LOWER(MID(ID, 3, 1))
LENGTH(ID & "xx") >= Tries
(c)(i)

State why these variable names are not suitable.

(c)(ii)

Identify one problem that these variable names might cause.

(c)(iii)

The choice of suitable variable names is one example of good programming practice.

Give one other example.

Similar questions