9618/21

Computer Science 9618/21October/November 2025

Cambridge AS Level · Fundamental Problem-solving and Programming Skills · worked solutions for every part, with the mark scheme

8
questions
75
marks
120
minutes

Topics Programming · Data Types and Structures · Software Development · Algorithm Design and Problem-solving

Q1Medium-EasyProgrammingData Types and StructuresSoftware Development

Refer to the insert for the list of pseudocode functions and operators.

A program is being developed to meet a particular customer requirement.

(a)

The program contains these variables:

VariableData type
MyCharCHAR
MyStringSTRING
MyIntINTEGER
MyDOBDATE

Complete the table by filling in the gaps using functions and/or operators from the insert.

Each expression must be valid.

Expression
MyString ← 'X' .............................. MyString
MyChar ← .............................. ("ABCD", ............... ,...............)
MyString ← .............................. (.............................. (MyDOB))
MyInt ← .............................. (.............................. (MyString) / 2)
4M
(b)

Different test methods will be used at different stages of the program development.

Complete the table by identifying the test method that matches the test description.

The first row has been completed for you.

Test descriptionTest method
carried out as soon as a program module has been codedalpha
carried out as program modules are being combined
completed by the developers without referring to the code
completed by the customer
3M
(c)

During the alpha testing stage, an Integrated Development Environment (IDE) is used to help locate an error that has been identified. The IDE report window feature is used to examine the values assigned to variables.

Explain how two other IDE features are used together with the report window feature to help locate the error.

3M
Q25MMediumAlgorithm Design and Problem-solvingData Types and Structures

Data is a global 1D array containing 30 elements of type STRING

An algorithm will output:

  • all non-blank elements (elements that do not contain an empty string)
  • the final total of the number of elements output.

Complete the program flowchart to represent the algorithm:

Similar questions
Q3Medium-EasyData Types and Structures

A program is needed to manage individual rentals in a car-hire business.

The data items for each rental will be held in a record structure of type RentalRecord

The programmer has started to define the items that will be needed:

ItemExample valueComment
RentalID"AB1234"a unique alpha-numeric value
CarID241a numeric value used as an array index
DisCode'S'a letter indicating the type of discount offered
Start13/06/2025when the rental starts
Duration7the number of days of the rental
CompletedFALSETRUE when the car is returned and the rental charge paid
(a)
6M
(i)

Write pseudocode to declare the record structure for type RentalRecord

4M
(ii)

A 1D array Rental containing 500 elements is used to store the data for all rental records.

Write pseudocode to declare the Rental array.

2M
(b)

State three benefits of using an array of records to store the data for all rentals.

3M
Q4MediumData Types and StructuresProgramming

A program contains a global 1D array Number consisting of 20 elements of type REAL

A procedure Store() will input a sequence of up to 20 real values, one value at a time. These values will be assigned to elements of the array using four steps:

Step 1: store the first value in the sequence in the first element of the array
Step 2: check each subsequent value input. If this value is larger than the previous value input, then assign the value to the next array element, otherwise go to step 4
Step 3: repeat from step 2 unless the array is full
Step 4: output the count of the number of values stored in the array together with a suitable message.

(a)

Complete the pseudocode for Store()

All variables used in the algorithm must be declared.

PROCEDURE Store()
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
ENDPROCEDURE
6M
(b)

The requirements of the program change:

  • the number of values in the sequence is unknown, but may be higher than 20
  • the values will need to be accessed by another program as data.

The data will be stored in a text file instead of an array.

3M
(i)

Give two benefits of using a text file instead of an array.

2M
(ii)

State any change that will need to be made before each value is written to the file.

1M
Q5Medium-EasyData Types and StructuresProgramming

A program is being designed in pseudocode.

The program contains the following declaration for the global array MyData:

DECLARE MyData : ARRAY[1:10000] OF STRING

A function FindFirst() is written to search the array for a given string and to return the index of the first element where that string is found, or to return –1 if the string is not found.

The function is written in pseudocode as shown:

FUNCTION FindFirst(SearchString : STRING) RETURNS INTEGER
    DECLARE Index, FoundAt : INTEGER
    FoundAt ← -1
    FOR Index ← 1 TO 10000
        IF MyData[Index] = SearchString THEN // outer conditional clause
            IF FoundAt = -1 THEN // inner conditional clause
                FoundAt ← Index
            ENDIF
        ENDIF
    NEXT Index
    RETURN FoundAt
ENDFUNCTION
(a)
3M
(i)

Comment on why the programmer chose –1 as the initial value of FoundAt

1M
(ii)

Explain the purpose of the outer conditional clause.

1M
(iii)

The inner conditional clause ensures that only the index of the first matching element, if any, is returned.

Explain how this clause works.

1M
(b)

The pseudocode does not use the most appropriate loop construct.

3M
(i)

Explain why this is not the most appropriate loop construct.

1M
(ii)

Suggest and justify a more appropriate loop construct that could be used.

Construct ...........................................................................................................................

Justification .......................................................................................................................

2M
Q6MediumAlgorithm Design and Problem-solvingProgramming

Students are learning about a simple check digit method for data validation. In this method, a single check digit is appended to the end of an original number to give a new number.

The students are studying a method which:

  • calculates the sum of all the digits in the original number
  • uses integer division to calculate the remainder when the sum is divided by 10
  • uses the remainder as the check digit
  • appends the check digit to the original number, creating the new number.

For example:

original number4162
sum of all digits4 + 1 + 6 + 2 = 13
remainder when the sum is divided by 10 using integer division3
new number41623

The method described can be used to detect single-digit errors. For example, if the new number is incorrectly input as 41633, then the check digit does not match and the input will be rejected.

(a)

An incorrect attempt was made to enter 41623. The first two digits were entered incorrectly; the last three digits were entered correctly.

When this number was tested, the check digit was found to be correct and the input was accepted.

Identify an example of the incorrect attempt to enter 41623 and explain why this number would not be rejected.

Number .....................................................................................................................................

Explanation ...............................................................................................................................

2M
(b)

A module Generate() will take an integer value representing an original number and return an integer value representing a new number which includes the check digit.

The original number is always at least three digits in length.

Write pseudocode for the module Generate()

Assume that the parameter is valid.

7M
Q7Medium-HardSoftware DevelopmentProgramming

There are several different ways to express an algorithm during the design of a program.

(a)

One part of the program contains an algorithm which is represented by a state-transition diagram.

The table shows the inputs, outputs and states for the algorithm:

Current stateInputOutputNext state
S1A2X2S3
S1A1X1S2
S2A4X4S5
S3A1S3
S3A3X3S2
S3A2X4S4
S4A1X1S4
S4A3S2
S4A4X4S5

Complete the state-transition diagram to represent the information given in the table.

5M
(b)

A structure chart is used to document a different part of the program.

This part of the program contains six modules:

Pseudocode module header
PROCEDURE Setup()
PROCEDURE Restart(H1 : STRING, C1 : INTEGER)
FUNCTION Modify(B1 : BOOLEAN) RETURNS INTEGER
PROCEDURE Final(T1 : INTEGER)
PROCEDURE Update(BYREF R2 : STRING)
FUNCTION Confirm() RETURNS BOOLEAN

Module Setup will repeatedly call three of the modules.

Complete the structure chart to document the information given in the table.

5M
Q8Medium-HardData Types and StructuresProgramming

A program is being developed to manage student book loans from a college library. Students may borrow up to five books at a time from the library.

The programmer has defined a record type to define each loan.

The record data items are:

Data itemData typeComment
StudentIDSTRINGthe unique ID of the student who has borrowed the book
BookIDSTRINGthe unique ID of the book being borrowed
OnLoanBOOLEANTRUE if the book has not been returned

The programmer has defined a global array Loan to store 5000 loan records.

There are more elements in the array than books in the library. Unused elements have the StudentID set to an empty string. These may occur anywhere in the array.

The programmer has defined the first program module:

ModuleDescription
OKToBorrow()• called with a parameter of type STRING representing a StudentID
• search the array for loan records for the specified student
• output a suitable message to say whether the student may, or may not, borrow another book
(a)

Write efficient pseudocode for the module OKToBorrow()

7M
(b)

A second module is defined:

ModuleDescription
ReturnBook()• called with two parameters of type STRING representing a StudentID and a BookID
• searches the array for the relevant loan record
• when found, sets OnLoan to FALSE and returns TRUE
• if a loan record is not found, or the book has already been returned, then returns FALSE

Write efficient pseudocode for the module ReturnBook()

Assume that each student is only allowed to borrow each book only once. That means that there will be no more than one loan record for a given combination of student and book.

8M
(c)

It is decided to introduce a system of fines for books that have been borrowed for too long.

Two new requirements are defined:

  1. Each loan has a maximum length, represented as a number of days.
  2. Each book in the library will be assigned one of three categories. Each category has a different maximum loan length.

Record structure and program design changes are needed to meet these two requirements.

Outline the changes that are necessary to meet the two requirements.

2M