Skip to content

12.2 Program Design

AS Level · 37 questions found

  • Structure charts: decompose into sub-tasks; show parameters between modules
  • Construct a structure chart; derive pseudocode from a structure chart
  • State-transition diagrams: purpose and how to use them
Q2
Oct/Nov 2025 Paper 2 v1

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:

START

END 5 marks

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: START END <span class="part-marks">5 marks</span>
Show mark scheme

2 Alternative solution Checking for empty string first

Q7
Oct/Nov 2025 Paper 2 v1

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. 5 marks

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

Current state Input Output Next state
S1 A2 X2 S3
S1 A1 X1 S2
S2 A4 X4 S5
S3 A1 S3
S3 A3 X3 S2
S3 A2 X4 S4
S4 A1 X1 S4
S4 A3 S2
S4 A4 X4 S5

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

(b) A structure chart is used to document a different part of the program. 5 marks

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.

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. <span class="part-marks">5 marks</span> The table shows the inputs, outputs and states for the algorithm: |Current state|Input|Output|Next state| |---|---|---|---| |S1|A2|X2|S3| |S1|A1|X1|S2| |S2|A4|X4|S5| |S3|A1||S3| |S3|A3|X3|S2| |S3|A2|X4|S4| |S4|A1|X1|S4| |S4|A3||S2| |S4|A4|X4|S5| Complete the state-transition diagram to represent the information given in the table. ![](../images/w25_21_q7_fig1.png) ![](../images/w25_21_q7_fig2.png) ### (b) A structure chart is used to document a different part of the program. <span class="part-marks">5 marks</span> 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. ![](../images/w25_21_q7_fig3.png)
Show mark scheme

7(a) [5 marks]

One mark for each: 1 Label A1 | X1 added on line from S1 to state labelled S2 2 States S3, S4 and S5 labelled 3 Line from S2 to S5 with event label A4|X4 4 Lines from S3 with correct event labels including 'loop' label 5 Lines from S4 with correct event labels including 'loop'

7(b) [5 marks]

One mark per point: 1 All boxes correctly labelled 2 Iteration arrow 3 Parameter to Restart 4 Return value from Modify and parameter to Final 5 BYREF parameter to Update

Q2
Oct/Nov 2025 Paper 2 v2

Data is a global 1D array containing 20 elements of type REAL

An algorithm will:

  • input a sequence of real values, one at a time

  • assign each value to consecutive array elements, starting from index 1

  • end when the value 99.9 is input, or all 20 elements have been assigned (the value 99.9 must not be stored in the array).

Complete the program flowchart to represent the algorithm:

START

END 5 marks

Data is a global 1D array containing 20 elements of type REAL An algorithm will: - input a sequence of real values, one at a time - assign each value to consecutive array elements, starting from index 1 - end when the value 99.9 is input, or all 20 elements have been assigned (the value 99.9 must not be stored in the array). Complete the program flowchart to represent the algorithm: START END <span class="part-marks">5 marks</span>
Show mark scheme

2 Alternative solution:

Q7
Oct/Nov 2025 Paper 2 v2

The structure chart shows part of a program design:

Convert
Count P2
T1
Key
Analyse Update Sort
Analyse Sort

(a) Explain the meaning of the curved arrow symbol in this structure chart. 2 marks

(b) The program designer has noted that: 4 marks

  • Count is the number of elements in an array

  • T1 is a value representing the number of elements in an array that have been modified

  • Key is of type STRING

Write the pseudocode module headers for analyse, update and sort.

Analyse:

Update:

Sort:

The structure chart shows part of a program design: |Convert<br>Count P2<br>T1<br>Key<br>Analyse Update Sort|| |---|---| |Analyse|Sort| ### (a) Explain the meaning of the curved arrow symbol in this structure chart. <span class="part-marks">2 marks</span> ### (b) The program designer has noted that: <span class="part-marks">4 marks</span> - Count is the number of elements in an array - T1 is a value representing the number of elements in an array that have been modified - Key is of type STRING Write the pseudocode module headers for analyse, update and sort. Analyse: Update: Sort:
Show mark scheme

7(a) [2 marks]

Example explanation : The arrow means that t repeatedly calls then and Conver Analyse Update then (in that order)10 Sort MP1 Reference to ‘repetition’…’ MP2 Naming all four modules correctly and the sequence is stated or implied

7(b) [4 marks]

MP1 PROCEDURE Analyse (Count : INTEGER) FUNCTION Update (Key : STRING) RETURNS INTEGER MP2 MP3 MP4 PROCEDURE Sort (BYREF P2 : BOOLEAN) Mark as follows: One mark per underlined part

Q1
Oct/Nov 2025 Paper 2 v3

A user requires a program that implements complex data encryption to a recognised international standard. A programmer has started the design of the program.

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

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

1

2

3

(b) The programmer has identified a different part of the algorithm that would be appropriate to implement as a subroutine (a procedure or a function); no suitable library routine exists for this part.

(i) State two reasons why the programmer may decide to use a subroutine. 2 marks

1

2

(ii) A function header in pseudocode is defined as: 2 marks

FUNCTION Pass2(Count : INTEGER) RETURNS BOOLEAN

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

The first row has been completed.

Term Description
Pass2 the name of the function
Count
BOOLEAN

(c) Variables in the program have example values: 3 marks

Variable Example value
DoB 23/6/2011
Multiplier 2.5
AddressLine[1] "35 Lincoln Avenue"

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

Expression Evaluates to
LENGTH(NUM_TO_STR(Multiplier))
MONTH(DoB) > 4
15 + STR_TO_NUM(MID(AddressLine[1], 2, 1))
A user requires a program that implements complex data encryption to a recognised international standard. A programmer has started the design of the program. ### (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. <span class="part-marks">3 marks</span> State three other benefits of using library routines in the development of the program. 1 2 3 ### (b) The programmer has identified a different part of the algorithm that would be appropriate to implement as a subroutine (a procedure or a function); no suitable library routine exists for this part. #### (i) State two reasons why the programmer may decide to use a subroutine. <span class="part-marks">2 marks</span> 1 2 #### (ii) A function header in pseudocode is defined as: <span class="part-marks">2 marks</span> FUNCTION Pass2(Count : INTEGER) RETURNS BOOLEAN Complete the table by describing the terms used in the function header. The first row has been completed. |Term|Description| |---|---| |Pass2|the name of the function| |Count|| |BOOLEAN|| ### (c) Variables in the program have example values: <span class="part-marks">3 marks</span> |Variable|Example value| |---|---| |DoB|23/6/2011| |Multiplier|2.5| |AddressLine[1]|"35 Lincoln Avenue"| Complete the table by evaluating each expression using the example values: |Expression|Evaluates to| |---|---| |LENGTH(NUM_TO_STR(Multiplier))|| |MONTH(DoB) > 4|| |15 + STR_TO_NUM(MID(AddressLine[1], 2, 1))||
Show mark scheme

1(a) [3 marks]

Answers include: 1 They are tried and tested // Free from errors 2 They are readily available // Speed up development time 3 They will be updated automatically when improvements are made // No maintenance of routine is needed (as automatically updated) 4 The algorithm will be compliant with the international standard One mark per point Max 3

1(b)(i) [2 marks]

1 When a part of the algorithm performs a specific task 2 Part is repeated // performed in several places 3 Testing / debugging / maintenance is easier One mark for each point Max 2

1(b)(ii) [2 marks]

Term Description the name of the function Pass2 Count The parameter / value passed to the function The (data) type returned (by the function) BOOLEAN One mark per description (excluding first row)

1(c) [3 marks]

Expression Evaluates to LENGTH(NUM_TO_STR(Multiplier)) 3 TRUE MONTH(DoB) > 4 20 15 + STR_TO_NUM(MID(AddressLine[1], 2, 1)) One mark per row

Q7
Oct/Nov 2025 Paper 2 v3

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. 5 marks

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

Current state Input Output Next state
S1 A1 S2
S2 A2 X4 S3
S3 A1 X1 S3
S3 A2 X1 S3
S3 A3 X3 S4
S3 A4 S2
S4 A3 X4 S5
S4 A4 X4 S5
S4 A1 S2

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

(b) A structure chart is used to document a different part of the program, made up of five modules. 4 marks

Program notes:

  • module Setup calls either module Restart, or module Confirm

  • module Confirm takes a string as a parameter and returns an integer

  • module Modify has no parameters and returns a Boolean

  • module Update takes a string as a parameter

  • module Restart repeatedly calls module Update followed by module Modify

  • module Restart takes a string as a parameter that is passed by reference.

Draw a structure chart to represent the relationship between the five modules, including all parameters and return values.

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. <span class="part-marks">5 marks</span> The table shows the inputs, outputs and states for the algorithm: |Current state|Input|Output|Next state| |---|---|---|---| |S1|A1||S2| |S2|A2|X4|S3| |S3|A1|X1|S3| |S3|A2|X1|S3| |S3|A3|X3|S4| |S3|A4||S2| |S4|A3|X4|S5| |S4|A4|X4|S5| |S4|A1||S2| Complete the state-transition diagram to represent the information given in the table: ![](../images/w25_23_q7_fig1.png) ![](../images/w25_23_q7_fig2.png) ### (b) A structure chart is used to document a different part of the program, made up of five modules. <span class="part-marks">4 marks</span> Program notes: - module Setup calls either module Restart, or module Confirm - module Confirm takes a string as a parameter and returns an integer - module Modify has no parameters and returns a Boolean - module Update takes a string as a parameter - module Restart repeatedly calls module Update followed by module Modify - module Restart takes a string as a parameter that is passed by reference. Draw a structure chart to represent the relationship between the five modules, including all parameters and return values.
Show mark scheme

7(a) [5 marks]

One mark for each: 1 S2 to S5 labelled 2 Label A1 added to event from S1 to S2 3 Event lines from S2 to S3 and S3 to S2 correctly labelled 4 Events lines from S3 to S3 and event line from S3 to S4 all labelled correctly 5 Event lines from S4 to S5 correctly and event line from S4 to S2 labelled correctly Max 4 for any additional events/lines

7(b) [4 marks]

One mark for each: 1 All boxes correctly labelled and connected in correct hierarchy 2 BYREF parameter to Restart, parameter to Confirm and return 3 Diamond and loop symbol 4 Parameter to Update and return from Modify

Q1
May/Jun 2025 Paper 2 v1

A program is being developed to help the manager of a shop control the stock.

(a) An identifier table has been used during the design stage. 4 marks

Complete the identifier table:

Example value Explanation Variable name Data type
"Fruit" a category of stock
that is sold in the shop
20/02/2025 when an item was
sold
12.67 the cost of an item
TRUE to indicate if an item is
in stock

(b) A module Sales() is part of the stock control program. 5 marks

The table contains pseudocode extracts from the module Sales()

Each extract may include all or part of:

  • assignment

  • selection

  • iteration (repetition).

Complete the table by placing one or more ticks (✓) in each row:

Pseudocode extract Assignment Selection Iteration
Result
CalculateTotal()
WHILE IsClosed
REPEAT
INPUT Value
UNTIL Sales[4] > Value
IF Sales[Current] <= 150 THEN
Discount
TRUE
ENDIF
CASE OF Option
A program is being developed to help the manager of a shop control the stock. ### (a) An identifier table has been used during the design stage. <span class="part-marks">4 marks</span> Complete the identifier table: |Example value|Explanation|Variable name|Data type| |---|---|---|---| |"Fruit"|a category of stock<br>that is sold in the shop||| |20/02/2025|when an item was<br>sold||| |12.67|the cost of an item||| |TRUE|to indicate if an item is<br>in stock||| ### (b) A module Sales() is part of the stock control program. <span class="part-marks">5 marks</span> The table contains pseudocode extracts from the module Sales() Each extract may include all or part of: - assignment - selection - iteration (repetition). Complete the table by placing one or more ticks (✓) in each row: |Pseudocode extract|Assignment|Selection|Iteration| |---|---|---|---| |Result<br> CalculateTotal()|||| |WHILE IsClosed|||| |REPEAT<br> INPUT Value<br>UNTIL Sales[4] > Value|||| |IF Sales[Current] <= 150 THEN<br> Discount<br> TRUE<br>ENDIF|||| |CASE OF Option||||
Show mark scheme

1(a) [4 marks]

Example Explanation Variable name Data type value "Fruit" Category STRING a category of stock that is sold in the shop DateSold DATE when an item was sold 12.67 (Item)Cost/Price REAL the cost of an item TRUE (Item)InStock BOOLEAN to indicate if an item is in stock and data type

1(b) [5 marks]

Pseudocode extract Assignment Selection Iteration  ✓ CalculateTotal() ✓ ✓ ✓ ✓ ✓  TRUE ✓

1(c) [3 marks]

Breaking down a problem into sub problems In order to explain / understand the process/task of how a (stock control) can be managed in more detail Leading to the concept of the program designed as a series of modules / procedures / functions // or by example of different stock control modules Makes the program easier to test / debug if no mention of stock control

Q2
May/Jun 2025 Paper 2 v1

A program is being developed to calculate the pay of employees working for a company.

A function CalculateBonus() calculates bonus pay based on the value of sales.

Bonus pay is calculated as shown in the table.

Value of sales
(in dollars)
Bonus pay
(in dollars)
below 2000 0
between 2000 and 4000 inclusive 10
above 4000 100

A flowchart for the function CalculateBonus() has been designed.

RETURN BonusPay

END

(a) The flowchart contains logic errors.

A program is being developed to calculate the pay of employees working for a company. A function CalculateBonus() calculates bonus pay based on the value of sales. Bonus pay is calculated as shown in the table. |Value of sales<br>(in dollars)|Bonus pay<br>(in dollars)| |---|---| |below 2000|0| |between 2000 and 4000 inclusive|10| |above 4000|100| A flowchart for the function CalculateBonus() has been designed. ![](../images/s25_21_q2_fig1.png) |RETURN BonusPay|| |---|---| ||| END ### (a) The flowchart contains logic errors.
Show mark scheme

2(a)(i) [1 mark]

The two decision boxes are in the wrong order // The first decision symbol is wrong The first decision should check for values greater than or equal to 2000

2(a)(ii) [1 mark]

Swap around the two decision boxes The first decision box should check for values greater than or equal to 2000 and the second decision box should check for values above 4000

2(b)(ii) [2 marks]

The value cannot be changed // avoids being different in two places Makes the program easier to understand Avoids repeatedly writing the same value throughout the program A change to the value requires a change in only one statement

2(b)(iii) [1 mark]

(The code is) tried and tested so error free Provides functionality / code that the programmer may find difficult to code themselves

2(c) [4 marks]

Syntax (error) Rules of programming language // the language grammar was not followed Run-time (error ) The program performs an illegal operation and one mark for the description

Q2
May/Jun 2025 Paper 2 v2

A program to calculate the pay of employees working for a company is being designed.

(a) Stepwise refinement has been used in the design of the program. 2 marks

Describe stepwise refinement.

(b) One of the program modules used to calculate employees’ weekly bonus pay has been completed. The amount of bonus pay they receive is based on the number of hours worked and the value of sales made as shown in the table.

Bonus pay and value of sales are both in dollars.

Hours worked Value of sales Bonus pay
between 1 and 40 inclusive 2000 or less 0
between 1 and 40 inclusive above 2000 50
above 40 2000 or less 10
above 40 above 2000 100

(i) The module is tested using white‑box testing. 2 marks

State two tests, using valid data, that can be used to test different paths through the program.

Test one:

Hours worked

Value of sales

Bonus pay

Test two:

Hours worked

Value of sales

Bonus pay

A program to calculate the pay of employees working for a company is being designed. ### (a) Stepwise refinement has been used in the design of the program. <span class="part-marks">2 marks</span> Describe stepwise refinement. ### (b) One of the program modules used to calculate employees’ weekly bonus pay has been completed. The amount of bonus pay they receive is based on the number of hours worked and the value of sales made as shown in the table. Bonus pay and value of sales are both in dollars. |Hours worked|Value of sales|Bonus pay| |---|---|---| |between 1 and 40 inclusive|2000 or less|0| |between 1 and 40 inclusive|above 2000|50| |above 40|2000 or less|10| |above 40|above 2000|100| #### (i) The module is tested using white‑box testing. <span class="part-marks">2 marks</span> State two tests, using valid data, that can be used to test different paths through the program. Test one: Hours worked Value of sales Bonus pay Test two: Hours worked Value of sales Bonus pay
Show mark scheme

2(a) [2 marks]

Mark as follows:

  1. To increase the level of detail of the algorithm // To break the problem / task into smaller steps …
  2. … until steps can be directly translated into lines of code // from which it can be programmed

2(b)(i) [2 marks]

One mark for each of set test values Hours worked between 1 and 40 inclusive  Sales value = 2000 Bonus Pay: 0 Hours worked above 40  Sales value = 2000 Bonus Pay: 10 Hours worked between 1 and 40 inclusive  Sales value 2000 Bonus Pay: 50 Hours worked above 40 Sales value above 2000 Bonus Pay: 100 max 2

2(b)(ii) [2 marks]

One mark per point • Simple modules are written to replace each of the unfinished modules. • Each simple module will return an expected value / will output a message to show it has been called.

2(b)(iii) [2 marks]

One mark for naming type of error and one mark for corresponding description Type of error: Logic (error) Description: Where the program does not behave as expected / Does not give expected result / An error in the logic of the algorithm Or Type of error: Run-time (error) Description: The program performs an illegal operation Max 2

Q4
May/Jun 2025 Paper 2 v2

An algorithm will:

  • input 100 integer values, one value at a time

  • store the first value input into the first location of the array Number

  • store the next input value in the next unused location of the array Number

  • output the contents of Number array in the opposite sequence to that in which the values were input.

Complete the program flowchart to represent the algorithm.

Variable declarations are not required.

START

END 6 marks

An algorithm will: - input 100 integer values, one value at a time - store the first value input into the first location of the array Number - store the next input value in the next unused location of the array Number - output the contents of Number array in the opposite sequence to that in which the values were input. Complete the program flowchart to represent the algorithm. Variable declarations are not required. START END <span class="part-marks">6 marks</span>
Show mark scheme

4 [6 marks]

One mark for each functional group as listed:

  1. Initialise Index used for to either 1 or 0 before first loop Number
  2. Loop 100 times
  3. Input value
  4. Increment array index and store value in array at element Number referenced by array in a loop index
  5. Output loop starts at last element in array Number
  6. Output array element referenced by in a loop Number Index
  7. Output all elements of array once in reverse order Number Max 6
Q5
May/Jun 2025 Paper 2 v2

An automated digital camera system is used to take a sequence of pictures of animals in a garden. During the design of the system, a state‑transition diagram is produced.

The table details the states in the automated digital camera system along with the events which cause the states to change.

The system starts in standby mode. The sequence of pictures is taken when in active mode.

Current state Event Next state
standby mode turn on detect mode
detect mode turn off standby mode
detect mode movement detected active mode
active mode 20 seconds elapsed sequence complete
active mode turn off standby mode
sequence complete time saved detect mode

(a) Complete the state‑transition diagram for the automated digital camera system. 4 marks

(b) At the end of each sequence of pictures, the time is saved as a string in the format <HH><MM><SS> where: 8 marks

  • 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:

Hour : 15 Total : 32 Hour : 18 Total : 1

Write pseudocode for this algorithm.

Assume the text file TimeTaken.txt contains at least one line.

An automated digital camera system is used to take a sequence of pictures of animals in a garden. During the design of the system, a state‑transition diagram is produced. The table details the states in the automated digital camera system along with the events which cause the states to change. The system starts in standby mode. The sequence of pictures is taken when in active mode. |Current state|Event|Next state| |---|---|---| |standby mode|turn on|detect mode| |detect mode|turn off|standby mode| |detect mode|movement detected|active mode| |active mode|20 seconds elapsed|sequence complete| |active mode|turn off|standby mode| |sequence complete|time saved|detect mode| ### (a) Complete the state‑transition diagram for the automated digital camera system. <span class="part-marks">4 marks</span> ![](../images/s25_22_q5_fig1.png) ### (b) At the end of each sequence of pictures, the time is saved as a string in the format &lt;HH&gt;&lt;MM&gt;&lt;SS&gt; where: <span class="part-marks">8 marks</span> - 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: Hour : 15 Total : 32 Hour : 18 Total : 1 Write pseudocode for this algorithm. Assume the text file TimeTaken.txt contains at least one line.
Show mark scheme

5(a) [4 marks]

Mark as follows: 1 Mark: The three new states drawn and labelled. 1 Mark: Two of the events drawn with labels connecting correct states and correct line direction 1 Mark: Four of the events drawn with labels connecting correct states and correct line direction. 1 Mark: All and only six events drawn with labels connecting correct states and correct line direction.

5(b)

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 DECLARE HoursArray[0 : 23] OF INTEGER DECLARE Index, Hour : INTEGER DECLARE Line : STRING  FOR Index 0 TO 23  HoursArray[Index] 0 NEXT Index OPENFILE "TimeTaken.txt" FOR READ WHILE NOT EOF("TimeTaken.txt") READFILE "TimeTaken.txt", Line  Hour STR_TO_NUM(LEFT(Line, 2))  HoursArray[Hour] HoursArray[Hour] + 1 ENDWHILE  FOR Index 0 TO 23 IF HoursArray[Index] <> 0 THEN OUTPUT "Hour : ", Index, " Total : ", HoursArray[Index] ENDIF NEXT Index CLOSEFILE "TimeTaken.txt" Mark as follows:

  1. Initialisation of 24 array elements to 0 // Initialisation of 24 Integer variables to 0
  2. Open for read and subsequently close "TimeTaken.txt"
  3. Conditional loop until EOF
  4. Read a line from in a loop "TimeTaken.txt"
  5. Extract Hour from line read in a loop
  6. Convert Hour to an integer value in a loop
  7. Increment appropriate array element / variable in a loop
  8. Output of each hour and corresponding count variable (with a suitable message) for all values where count is not zero
Q6
May/Jun 2025 Paper 2 v3

Study the structure chart:

Main
M
P
Sub_A Sub_B
V
R
X
W
T
U
Sub_Part1A Sub_Part2A Sub_Part3A Sub_Part1B Sub_Part2B
Sub_Part1A Sub_Part2B

Some of the parameter data types are:

  • R and V are of type INTEGER

  • T is of type REAL

  • U is of type STRING

  • W is of type BOOLEAN.

Some of the modules in the structure chart are functions, others are procedures.

(a) Explain one difference between functions and procedures. 1 mark

(b) Write the pseudocode to define the module headers: 5 marks

Sub_Part1A

Sub_Part2A

Sub_Part3A

(c) The structure chart uses the two symbols shown. 3 marks

Complete the table to explain what each symbol means and how the relevant modules in the structure chart are affected.

Symbol Explanation


______


______
Study the structure chart: |Main<br>M<br>P<br>Sub_A Sub_B<br>V<br>R<br>X<br>W<br>T<br>U<br>Sub_Part1A Sub_Part2A Sub_Part3A Sub_Part1B Sub_Part2B|| |---|---| |Sub_Part1A|Sub_Part2B| Some of the parameter data types are: - R and V are of type INTEGER - T is of type REAL - U is of type STRING - W is of type BOOLEAN. Some of the modules in the structure chart are functions, others are procedures. ### (a) Explain one difference between functions and procedures. <span class="part-marks">1 mark</span> ### (b) Write the pseudocode to define the module headers: <span class="part-marks">5 marks</span> Sub_Part1A Sub_Part2A Sub_Part3A ### (c) The structure chart uses the two symbols shown. <span class="part-marks">3 marks</span> Complete the table to explain what each symbol means and how the relevant modules in the structure chart are affected. |Symbol|Explanation| |---|---| ||______<br>______<br>______| ||______<br>______<br>______|
Show mark scheme

6(a) [1 mark]

MP1 A function returns a (single) value and a procedure does not MP2 A procedure can pass parameters by ByRef Max 1

6(b) [5 marks]

Sub_Part1A: 1 Mark PROCEDURE Sub_Part1A(R: INTEGER) Sub_Part2A: FUNCTION Sub_Part2A(T : REAL) RETURNS BOOLEAN 2 Marks Sub_Part3A: PROCEDURE Sub_Part3A(V: INTEGER, W: BOOLEAN, BYREF U : STRING) 2 Marks

6(c) [3 marks]

Symbol Explanation The module Main calls either Sub_A or Sub_B (which one is called is determined at run time) The module Sub_A will repeatedly call Sub_Part1A followed by Sub_Part2A then by Sub_Part3A MP1 Shape1: reference to selection MP2 Shape2: reference to repetition // iteration  MP3 Descption ( 2) including correct use of all module names in both parts

Q4
Oct/Nov 2024 Paper 2 v1

A program includes the following assignment statement:

Result ← STR_TO_NUM(x) / STR_TO_NUM(y)

When the program evaluates the expression in the statement, it performs a calculation.

Variable Result is of type real and variables x and y are of type string.

Two checks are required before the calculation is performed:

  1. The two strings represent valid numeric values.
  2. The numeric value of string y is not zero.

(a) Identify the type of error that could occur if these checks are not carried out and state a cause of this error. 2 marks

Type

Cause

(b) The designer considers implementing the checks and calculation as a module (a procedure or a function). One reason for this is that the same checks and calculations are performed at several places in the program. 2 marks

Give another reason why this is a suitable approach and state what is avoided by this approach.

Reason

Avoided

(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: 6 marks

TYPE Result DECLARE Done : BOOLEAN DECLARE Value : REAL ENDTYPE

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

A program includes the following assignment statement: Result ← STR_TO_NUM(x) / STR_TO_NUM(y) When the program evaluates the expression in the statement, it performs a calculation. Variable Result is of type real and variables x and y are of type string. Two checks are required before the calculation is performed: 1. The two strings represent valid numeric values. 2. The numeric value of string y is not zero. ### (a) Identify the type of error that could occur if these checks are not carried out and state a cause of this error. <span class="part-marks">2 marks</span> Type Cause ### (b) The designer considers implementing the checks and calculation as a module (a procedure or a function). One reason for this is that the same checks and calculations are performed at several places in the program. <span class="part-marks">2 marks</span> Give another reason why this is a suitable approach and state what is avoided by this approach. Reason Avoided ### (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: <span class="part-marks">6 marks</span> TYPE Result DECLARE Done : BOOLEAN DECLARE Value : REAL ENDTYPE 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().
Show mark scheme

4(a) [2 marks]

One mark per point: Type: Run-time error Cause: A divide by zero operation is attempted // Attempt to convert a non- numeric string to a number

4(b) [2 marks]

Answers include: Reason: • This part of the algorithm performs a specific task // if the check or calculation is changed it is changed only once • A (similar) subroutine is already available // Library routine is already available • The program is simplified / easier to understand / easier to design / code / test / debug / maintain Max 1 marks for 'Reason' Avoided: • Unnecessary code duplication • Errors caused by differences where several copies of the check and calculation exist Max 1 marks for 'Avoided'

4(c) [6 marks]

Example solution: FUNCTION Evaluate(NumStr1, NumStr2 : STRING) RETURNS Result DECLARE RetVal : Result DECLARE Num1, Num2 : REAL  RetVal.Done FALSE IF IS_NUM(NumStr1) = TRUE AND IS_NUM(NumStr2) = TRUE THEN  Num1 STR_TO_NUM(NumStr1)  Num2 STR_TO_NUM(NumStr2) IF Num2 <> 0 THEN  RetVal.Value (Num1 / Num2)  RetVal.Done TRUE ENDIF ENDIF RETURN RetVal ENDFUNCTION Note that order of parameters is not specified so divisor could be either parameter. Mark as follows: 1 Function heading, parameters, ending 2 ... Correct return type of Result 3 Local declaration of type Result 4 Attempt at using to check both parameters/strings IS_NUM() 5 Attempt at using of to convert both parameters/strings STR_TO_NUM() 6 Check if the divisor, is non-zero ... 7 … and if so correct calculation and assignment to field Value 8 Return variable of type having assigned both fields Result Max 6 marks

Q7
Oct/Nov 2024 Paper 2 v1

A program contains six modules with headers as follows:

Pseudocode module header

PROCEDURE Connect()

FUNCTION Activate(H1 : STRING, Code : INTEGER) RETURNS BOOLEAN

FUNCTION Sync(T1 : BOOLEAN, S2 : REAL) RETURNS INTEGER

PROCEDURE Initialise(BYREF ID : INTEGER, BYVAL CC : INTEGER)

FUNCTION Reset(RA : STRING) RETURNS INTEGER

FUNCTION Enable(SA : INTEGER) RETURNS BOOLEAN

Module Connect() will call either Activate() or Sync(). This is decided at run-time.

(a) Complete the structure chart for these modules. 5 marks

Connect
T1
Connect
T1
Connect
T1

(b) Explain the meaning of the curved arrow symbol used in the diagram in part (a). 2 marks

A program contains six modules with headers as follows: Pseudocode module header PROCEDURE Connect() FUNCTION Activate(H1 : STRING, Code : INTEGER) RETURNS BOOLEAN FUNCTION Sync(T1 : BOOLEAN, S2 : REAL) RETURNS INTEGER PROCEDURE Initialise(BYREF ID : INTEGER, BYVAL CC : INTEGER) FUNCTION Reset(RA : STRING) RETURNS INTEGER FUNCTION Enable(SA : INTEGER) RETURNS BOOLEAN Module Connect() will call either Activate() or Sync(). This is decided at run-time. ### (a) Complete the structure chart for these modules. <span class="part-marks">5 marks</span> |Connect<br>T1||| |---|---|---| |Connect<br>T1||| |Connect<br>T1||| |||| ### (b) Explain the meaning of the curved arrow symbol used in the diagram in part (a). <span class="part-marks">2 marks</span>
Show mark scheme

7(a) [5 marks]

One mark per point: 1 All module identified in correct hierarchy 2 Parameters to both Sync and Activate and return values 3 Parameters to both Reset and Enable 4 Parameters to Initialise 5 Decision diamond

7(b) [2 marks]

Explanation: Means that Sync repeatedly calls Reset and (then) Enable One mark for each point: MP1: reference to iteration MP2: naming all three modules correctly including correct sequence of calls

Q7
Oct/Nov 2024 Paper 2 v2

A coffee shop runs a computerised loyalty card system.

Customers are issued with a loyalty card with their name together with a unique customer ID.

Loyalty points are added to their card each time they spend money at the shop.

The following information is stored for each customer: ID, name, home address, email address, mobile phone number, date of birth, number of points, date of last visit and amount of money spent at last visit.

A new module will generate a personalised email message to each loyalty card customer who has not visited the coffee shop in the last three months. The message will include a unique voucher code which can be used to authorise a discount if the customer goes to the shop within the next two weeks.

(a) Identify three items of customer information that will be used by the new module and justify your choices. 3 marks

Item 1

Justification

Item 2

Justification

Item 3

Justification

(b) Identify the computational thinking skill that you needed to use to answer part (a). 1 mark

(c) It is decided to adopt a formal program development life cycle model for the development of the new module. 3 marks

The analysis of the new module is complete and the project moves on to the design stage. During this stage all the necessary algorithms and module designs will be defined.

State three other items that will be defined for the new module during the design stage.

1

2

3

(d) Part of the coffee shop program contains three program modules as follows: 3 marks

  • Module Init() has no parameters and returns a Boolean.

  • Module Reset() takes a string as a parameter and returns an Integer.

  • Module Check() repeatedly calls Init() followed by Reset().

Draw a structure chart to represent the relationship between the three modules, including all parameters and return values.

A coffee shop runs a computerised loyalty card system. Customers are issued with a loyalty card with their name together with a unique customer ID. Loyalty points are added to their card each time they spend money at the shop. The following information is stored for each customer: ID, name, home address, email address, mobile phone number, date of birth, number of points, date of last visit and amount of money spent at last visit. A new module will generate a personalised email message to each loyalty card customer who has not visited the coffee shop in the last three months. The message will include a unique voucher code which can be used to authorise a discount if the customer goes to the shop within the next two weeks. ### (a) Identify three items of customer information that will be used by the new module and justify your choices. <span class="part-marks">3 marks</span> Item 1 Justification Item 2 Justification Item 3 Justification ### (b) Identify the computational thinking skill that you needed to use to answer part (a). <span class="part-marks">1 mark</span> ### (c) It is decided to adopt a formal program development life cycle model for the development of the new module. <span class="part-marks">3 marks</span> The analysis of the new module is complete and the project moves on to the design stage. During this stage all the necessary algorithms and module designs will be defined. State three other items that will be defined for the new module during the design stage. 1 2 3 ### (d) Part of the coffee shop program contains three program modules as follows: <span class="part-marks">3 marks</span> - Module Init() has no parameters and returns a Boolean. - Module Reset() takes a string as a parameter and returns an Integer. - Module Check() repeatedly calls Init() followed by Reset(). Draw a structure chart to represent the relationship between the three modules, including all parameters and return values.
Show mark scheme

7(a) [3 marks]

Customer ID – to reference the other customer details • Email address – to send the email • Name – to personalise the email • Date of last visit – to select which customers should receive an email • Unique voucher code (or method of code generation) – to include in the email Mark as follows: One mark per item and justification Max 3 marks

7(b) [1 mark]

Abstraction

7(c) [3 marks]

MP1 Data structures // data dictionary / / identifier table(s) // validation rules MP2 Data-flow diagram // state-transition diagram MP3 User interface // Format for the email MP4 Testing method / Test plan / Test data / Trace tables MP5 Choice of email protocol to be used // Programming language to be used // Development environment MP6 Use of library routines // program to send the email Max 3 marks

7(d) [3 marks]

MP1 Three boxes correctly labelled and correct hierarchy MP2 Parameter and return values MP3 Iteration arrow

Q7
Oct/Nov 2024 Paper 2 v3

A coffee shop owner wants to introduce a computerised loyalty card system.

A programmer discusses the details of the system with the shop owner.

(a) Identify the stage of the program development life cycle that this discussion is part of and give a document that will be produced during this stage. 2 marks

Stage

Document

(b) The shop will give each customer a loyalty card that displays a unique customer ID as a bar code. A customer will be able to present their card each time they make a purchase. The system will scan the bar code, calculate points, and add them to the customer’s total. When the customer next makes a purchase and presents their card, they will have the option to exchange points for a discount. 4 marks

The designer decides that this activity will be handled by a new module. Decomposition will be used to break the problem of designing the new module down into sub-problems (sub-modules).

Identify four sub-modules that could be used in the design of the new module and describe their use.

Sub-module 1

Use

Sub-module 2

Use

Sub-module 3

Use

Sub-module 4

Use

A coffee shop owner wants to introduce a computerised loyalty card system. A programmer discusses the details of the system with the shop owner. ### (a) Identify the stage of the program development life cycle that this discussion is part of and give a document that will be produced during this stage. <span class="part-marks">2 marks</span> Stage Document ### (b) The shop will give each customer a loyalty card that displays a unique customer ID as a bar code. A customer will be able to present their card each time they make a purchase. The system will scan the bar code, calculate points, and add them to the customer’s total. When the customer next makes a purchase and presents their card, they will have the option to exchange points for a discount. <span class="part-marks">4 marks</span> The designer decides that this activity will be handled by a new module. Decomposition will be used to break the problem of designing the new module down into sub-problems (sub-modules). Identify four sub-modules that could be used in the design of the new module and describe their use. Sub-module 1 Use Sub-module 2 Use Sub-module 3 Use Sub-module 4 Use
Show mark scheme

7(a) [2 marks]

One mark per answer: MP1 Analysis MP2 Named document, examples include: • A requirement specification • Definition of System Objectives • List of problems with existing system • Survey results • Feasibility study • Interview notes Max 2 marks

7(b) [4 marks]

One mark for name and use Mark as follows: Examples include: Sub-module: ScanCard()/ GetID() Use: Read the barcode from the loyalty card / Get the customer ID from the barcode Sub-module: GetPoints() Use: Get the number of points the customer has Sub-module: ExchangePoints() / UpdateCard() Use: Reduce the number of loyalty points Sub-module: GetDiscount() / CalculateDiscount() Use: Calculate the discount Sub-module: CalculatePoints() Use: Calculate points (following a purchase) Sub-module: UpdatePoints() Use: Update total points a customer has (following a purchase) Sub-module: ShowDiscount() Use: Display the discount Max 4 marks

Q7
May/Jun 2024 Paper 2 v1

A fitness club has a computerised membership system. The fitness club offers a number of different exercise classes.

The following information is stored for each club member: name, home address, email address, mobile phone number, date of birth and the exercise(s) they are interested in.

(a) When an exercise class is planned, a new module will send personalised text messages to each member who has expressed an interest in that exercise. Members wishing to join the class send a text message back. Members may decide not to receive future text messages by replying with the message ‘STOP’.

The process of abstraction is used to filter out unnecessary information.

(i) State one advantage of applying abstraction to this problem. 1 mark

(ii) Identify three items of information that will be required by the new module. 3 marks

Justify your choices with reference to the given scenario.

Item 1 required

Justification

Item 2 required

Justification

Item 3 required

Justification

(iii) Identify two operations that would be required to process data when the new module receives a text message back from a member. 2 marks

Operation 1

Operation 2

(b) The structure chart illustrates part of the membership program:

Update
A
P2
T1
Name
P1
Sub-A Sub-B Sub-C
Sub-A Sub-C

Data item notes:

  • Name contains the name of a club member

  • P1 and T1 are of type real.

(i) Explain the meaning of the diamond symbol (labelled with the letter A) in the chart. 2 marks

(ii) Write the pseudocode module headers for Sub-A and Sub-B. 4 marks

Sub-A

Sub-B

A fitness club has a computerised membership system. The fitness club offers a number of different exercise classes. The following information is stored for each club member: name, home address, email address, mobile phone number, date of birth and the exercise(s) they are interested in. ### (a) When an exercise class is planned, a new module will send personalised text messages to each member who has expressed an interest in that exercise. Members wishing to join the class send a text message back. Members may decide **not** to receive future text messages by replying with the message ‘STOP’. The process of abstraction is used to filter out unnecessary information. #### (i) State **one** advantage of applying abstraction to this problem. <span class="part-marks">1 mark</span> #### (ii) Identify **three** items of information that will be required by the new module. <span class="part-marks">3 marks</span> Justify your choices with reference to the given scenario. Item 1 required Justification Item 2 required Justification Item 3 required Justification #### (iii) Identify **two** operations that would be required to process data when the new module receives a text message back from a member. <span class="part-marks">2 marks</span> Operation 1 Operation 2 ### (b) The structure chart illustrates part of the membership program: |Update<br>A<br>P2<br>T1<br>Name<br>P1<br>Sub-A Sub-B Sub-C|| |---|---| |Sub-A|Sub-C| Data item notes: - Name contains the name of a club member - P1 and T1 are of type real. #### (i) Explain the meaning of the diamond symbol (labelled with the letter A) in the chart. <span class="part-marks">2 marks</span> #### (ii) Write the pseudocode module headers for Sub-A and Sub-B. <span class="part-marks">4 marks</span> Sub-A Sub-B
Show mark scheme

7(a)(i) [3 marks]

To make the solution easier to design / implement / solve

7(a)(ii)

One mark per item and justification Item: mobile phone number Justification: to send the text message Item: name Justification: to personalise the text message Item: exercise interest Justification: to determine whether this member would be interested

7(a)(iii) [2 marks]

Examples include:  Add a member to a list of those interested in the new class  Remove the member from future SMS messages  Read/process Message  Identify who from One mark for each. Max 2 marks

7(b)(i) [4 marks]

Means that calls (one of) either or Update Sub-A, Sub-B Sub-C One mark for each point:  reference to selection / decision / if  naming all four modules correctly PROCEDURE Sub-A (Name : STRING, BYREF P2 : BOOLEAN)

7(b)(ii) [8 marks]

FUNCTION Sub-B (P1 : REAL) RETURNS REAL One mark per underlined part in each case FUNCTION DeleteComment(Line : STRING) RETURNS STRING

Q7
May/Jun 2024 Paper 2 v2

A fitness club has a computerised membership system.

The system stores information for each club member: name, home address, email address, mobile phone number, date of birth and exercise preferences.

Many classes are full, and the club creates a waiting list for each class. The club adds details of members who want to join a class that is full to the waiting list for that class.

When the system identifies that a space is available in one of the classes, a new module will send a text message to each member who is on the waiting list.

(a) Decomposition will be used to break the new module into sub‑modules (sub‑problems). 3 marks

Identify three sub‑modules that could be used in the design and describe their use.

Sub‑module 1

Use

Sub‑module 2

Use

Sub‑module 3

Use

(b) A different part of the program is represented by the following state‑transition diagram. 5 marks

Input-B | Output-W

Assume that the current state for each row is given by the ‘Next state’ on the previous row. For example, the first Input‑A is made when in state S1.

If there is no output for a given transition, then the output cell should contain ‘none’.

The first two rows have been completed.

Input Output Next state
S1
Input‑A none S3
Output‑W
none
Input‑B
Input‑A
S4

(ii) Identify the input sequence that will cause the minimum number of state changes in the transition from S1 to S4. 1 mark

A fitness club has a computerised membership system. The system stores information for each club member: name, home address, email address, mobile phone number, date of birth and exercise preferences. Many classes are full, and the club creates a waiting list for each class. The club adds details of members who want to join a class that is full to the waiting list for that class. When the system identifies that a space is available in one of the classes, a new module will send a text message to each member who is on the waiting list. ### (a) Decomposition will be used to break the new module into sub‑modules (sub‑problems). <span class="part-marks">3 marks</span> Identify **three** sub‑modules that could be used in the design **and** describe their use. Sub‑module 1 Use Sub‑module 2 Use Sub‑module 3 Use ### (b) A different part of the program is represented by the following state‑transition diagram. <span class="part-marks">5 marks</span> Input-B | Output-W ![](../images/s24_22_q7_fig1.png) Assume that the current state for each row is given by the ‘Next state’ on the previous row. For example, the first Input‑A is made when in state S1. If there is no output for a given transition, then the output cell should contain ‘none’. The first two rows have been completed. |Input|Output|Next state| |---|---|---| |||S1| |Input‑A|none|S3| ||Output‑W|| ||none|| |Input‑B||| |Input‑A||| |||S4| #### (ii) Identify the input sequence that will cause the minimum number of state changes in the transition from S1 to S4. <span class="part-marks">1 mark</span>
Show mark scheme

7(a)

Examples include: Module: IdentifyMember() Use: Identifies a club member who has expressed an interest in a given class Module: GetMemberPhoneNumber() Use: Gets the mobile phone number of a member Module: CreateMessage() Use: Generates a text message to a member Module: SendMessage() Use: Sends a text message to a member in the waiting list One mark for name and use Note: max 3 marks

7(b)(i) [5 marks]

Input Output Next state S1 Input-A none S3 Input-A Output-W S3 Input-B none S2 Input-B none S5 Input-A none S2 Input-A Output-X S4 One mark per row 3 to 7

7(b)(ii) [2 marks]

Input-B, Input-A

Q7
May/Jun 2024 Paper 2 v3

Seven program modules form part of a program. A description of the relationship between the modules is summarised below. Any return values are stated in the description.

Module name Description
Mod-A calls Mod-B followed by Mod-C
Mod-B
called with parameters Par1 and Par2

calls either Mod-D or Mod-E, determined when the program runs

returns a Boolean value
Mod-C
called with parameters Par1 and Par3

Par3 is passed by reference

repeatedly calls Mod-F followed by Mod-G
Mod-D called with parameter Par2
Mod-E
called with parameter Par3

returns an integer value
Mod-F called with parameter Par3
Mod-G
called with parameter Par3

Par3 is passed by reference

Parameters in the table are as follows:

  • Par1 and Par3 are of type string.

  • Par2 is of type integer.

(a) (i) Identify the modules that would be implemented as functions. 1 mark

(ii) Modules Mod-F and Mod-G are both called with Par3 as a parameter. 2 marks

In the case of Mod-F, the parameter is passed by value. In the case of Mod-G, the parameter is passed by reference.

Explain the effect of the two different ways of passing the parameter Par3.

(b) Draw a structure chart to show the relationship between the seven modules and the parameters passed between them. 6 marks

Seven program modules form part of a program. A description of the relationship between the modules is summarised below. Any return values are stated in the description. |Module name|Description| |---|---| |Mod-A|calls Mod-B followed by Mod-C| |Mod-B|• <br>called with parameters Par1 and Par2<br>• <br>calls either Mod-D or Mod-E, determined when the program runs<br>• <br>returns a Boolean value| |Mod-C|• <br>called with parameters Par1 and Par3<br>• <br>Par3 is passed by reference<br>• <br>repeatedly calls Mod-F followed by Mod-G| |Mod-D|called with parameter Par2| |Mod-E|• <br>called with parameter Par3<br>• <br>returns an integer value| |Mod-F|called with parameter Par3| |Mod-G|• <br>called with parameter Par3<br>• <br>Par3 is passed by reference| Parameters in the table are as follows: - Par1 and Par3 are of type string. - Par2 is of type integer. **(a) (i)** Identify the modules that would be implemented as functions. <span class="part-marks">1 mark</span> #### (ii) Modules Mod-F and Mod-G are both called with Par3 as a parameter. <span class="part-marks">2 marks</span> In the case of Mod-F, the parameter is passed by value. In the case of Mod-G, the parameter is passed by reference. Explain the effect of the **two** different ways of passing the parameter Par3. ### (b) Draw a structure chart to show the relationship between the seven modules and the parameters passed between them. <span class="part-marks">6 marks</span>
Show mark scheme

7(a)(i) [2 marks]

Mod-B() and Mod-E()

7(a)(ii) [6 marks]

Points required: 1 any change made to the parameter value / within is Par3 Mod-G() reflected in the (subsequent) value in the calling module / (after Mod-C() terminates) Mod-G() 2 any change made to the parameter value / within is NOT Par3 Mod-F() reflected in the (subsequent) value in the calling module / (after Mod-C() terminates) Mod-F() Mark as follows: 1 mark for a reasonable attempt to explain 2 marks for full explanation including context

7(b) [7 marks]

One mark per bullet: 1 All modules correctly labelled and interconnected 2 Parameters between Mod-A and Mod-B and return value from Mod-B 3 Parameters between Mod-A and Mod-C 4 Diamond applied to Mod-B only 5 Iteration arrow applied to Mod-C only 6 All parameters at lower level and return value

Q7
Oct/Nov 2023 Paper 2 v1

An algorithm is represented by a state-transition diagram.

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

Current state Input Output Next state
S1 A1 X1 S2
S2 A3 none S1
S2 A2 X4 S5
S5 A1 X1 S5
S5 A4 X2 S2
S5 A3 none S3
S1 A9 X9 S3
S3 A9 X9 S4

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

5 marks

An algorithm is represented by a state-transition diagram. The table shows the inputs, outputs and states for the algorithm: |Current state|Input|Output|Next state| |---|---|---|---| |S1|A1|X1|S2| |S2|A3|none|S1| |S2|A2|X4|S5| |S5|A1|X1|S5| |S5|A4|X2|S2| |S5|A3|none|S3| |S1|A9|X9|S3| |S3|A9|X9|S4| Complete the state-transition diagram to represent the information given in the table. ![](../images/w23_21_q7_fig1.png) <span class="part-marks">5 marks</span>
Show mark scheme

7 [5 marks]

MP1 S2 labelled MP2 S3, S4 and S5 added MP3 Line from S1 to S3 MP4 All three lines between S2 and S5 (including S5 to S5) MP5 Line from S5 to S3 AND from S3 to S4 PROCEDURE SendFile(FileName, DestID : STRING, Port :

Q2
Oct/Nov 2023 Paper 2 v2

An algorithm will:

  1. input a sequence of integer values, one at a time
  2. ignore all values until the value 27 is input, then sum the remaining values in the sequence
  3. stop summing values when the value 0 is input and then output the sum of the values.

(a) Draw a program flowchart to represent the algorithm. 5 marks

An algorithm will: 1. input a sequence of integer values, one at a time 2. ignore all values until the value 27 is input, then sum the remaining values in the sequence 3. stop summing values when the value 0 is input and then output the sum of the values. ### (a) Draw a program flowchart to represent the algorithm. <span class="part-marks">5 marks</span> ![](../images/w23_22_q2_fig1.png)
Show mark scheme

2(a) [5 marks]

Example Solution One mark per point: 1 Initialise to zero Total 2 Check for only first input of 27 in a loop then attempt to sum values 3 Loop until 0 input 4 Sum values input (after input of first 27) in a loop 5 Output after a reasonable attempt Total

2(b) [2 marks]

One mark per point: 1 Name: (pre / post) conditional loop 2 Justification: the number of iterations is not known // loop ends following a specific input (in the loop)

Q7
Oct/Nov 2023 Paper 2 v2

A program contains six modules:

Pseudocode module header

    PROCEDURE Module-A()
    PROCEDURE Module-X(T1 : INTEGER, S2 : REAL)
    PROCEDURE Reset(BYREF Code : INTEGER)
    FUNCTION Restore(OldCode : INTEGER) RETURNS BOOLEAN
    FUNCTION Module-Y(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN
    FUNCTION Module-Z(SA : INTEGER) RETURNS INTEGER

Module-X() calls Reset() Module-Y() calls Restore()

(a) Complete the structure chart for these modules. 4 marks

Module-A()

(b) Explain the meaning of the diamond symbol as used in the diagram in part (a) . 2 marks

A program contains six modules: **Pseudocode module header** ``` PROCEDURE Module-A() PROCEDURE Module-X(T1 : INTEGER, S2 : REAL) PROCEDURE Reset(BYREF Code : INTEGER) FUNCTION Restore(OldCode : INTEGER) RETURNS BOOLEAN FUNCTION Module-Y(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN FUNCTION Module-Z(SA : INTEGER) RETURNS INTEGER ``` `Module-X()` calls `Reset()` `Module-Y()` calls `Restore()` ### (a) Complete the structure chart for these modules. <span class="part-marks">4 marks</span> |Module-A()||| |---|---|---| |||| |||| |||| ### (b) Explain the meaning of the diamond symbol as used in the diagram in part **(a)** . <span class="part-marks">2 marks</span>
Show mark scheme

7(a) [4 marks]

One mark per point: 1 Module names 2 Parameters with labels to Module-X and between Module-X and Reset 3 Parameter (with label) to Module-Z and return from Module-Z 4 Parameters with labels to Module-Y and Restore and return values from Module-Y

7(b) [2 marks]

Means that calls either one of , or Module-A Module-X Module-Y Module- (which one is called is decided at runtime). Z One mark for reference to selection One mark for naming all four modules correctly

Q7
Oct/Nov 2023 Paper 2 v3

A structure chart shows the modular structure of a program:

(a) Explain the meaning of the curved arrow symbol which begins and ends at Module-A(). 2 marks

(b) The structure chart shows that Sub-9() is a function.

A Boolean value is returned by Sub-9() for processing by Module-A().

The original parameter RA is of type integer and RB is of type string.

A record type MyType will be defined with three fields to store the values passed between the two modules.

(i) Write pseudocode to define MyType . 3 marks

(ii) The design is modified and Sub-9() is changed to a procedure. 2 marks

The procedure will be called with a single parameter of type MyType .

Write the pseudocode header for procedure Sub-9() .

A structure chart shows the modular structure of a program: ![](../images/w23_23_q7_fig1.png) ### (a) Explain the meaning of the curved arrow symbol which begins and ends at Module-A(). <span class="part-marks">2 marks</span> ### (b) The structure chart shows that Sub-9() is a function. A Boolean value is returned by Sub-9() for processing by Module-A(). The original parameter RA is of type integer and RB is of type string. A record type `MyType` will be defined with three fields to store the values passed between the two modules. #### (i) Write pseudocode to define `MyType` . <span class="part-marks">3 marks</span> #### (ii) The design is modified and Sub-9() is changed to a procedure. <span class="part-marks">2 marks</span> The procedure will be called with a single parameter of type `MyType` . Write the pseudocode header for procedure `Sub-9()` .
Show mark scheme

7(a) [2 marks]

MP1 iteration / looping MP2 naming all four modules correctly in the correct sequence // e.g. repeatedly calls then then Module-A Sub-Y1, SubY2 Sub-9 TYPE MyType

7(b)(i) [3 marks]

DECLARE RA : INTEGER DECLARE RB : STRING DECLARE RC : BOOLEAN ENDTYPE MP1 TYPE MyType... ENDTYPE MP2 as integer and as string RA RB3 MP3 as Boolean RC PROCEDURE Sub-9(BYREF Param : MyType)

7(b)(ii) [2 marks]

MP 1 One mark for BYREF MP 2 One mark for the rest of the statement PROCEDURE ReceiveFile(FileName : STRING)

Q7
May/Jun 2023 Paper 2 v1

A school has a computerised library system that allows students to borrow books for a fixed length of time. The system uses text files to store details of students, books and loans.

A new module is to be written which will generate emails to each student who has an overdue book.

(a) Decomposition will be used to break down the problem of designing the new module into sub-problems. 3 marks

Identify three program modules that could be used in the design and describe their use.

Module 1

Use

Module 2

Use

Module 3

Use

(b) The program designer produces a structure chart for the new module. Part of the structure chart is shown:

(i) Explain the relationship between the four modules shown. 2 marks

(ii) Two new modules are added: Module‑X() and Module‑Y() . 3 marks

  • Module‑X() has no parameters.

  • Module‑Y() will take a string and a real number as parameters and return a Boolean value.

  • Module‑D() will call either Module‑X() or Module‑Y() .

Draw only the part of the structure chart that represents the relationship between Module‑X(), Module‑Y() and Module‑D() .

A school has a computerised library system that allows students to borrow books for a fixed length of time. The system uses text files to store details of students, books and loans. A new module is to be written which will generate emails to each student who has an overdue book. ### (a) Decomposition will be used to break down the problem of designing the new module into sub-problems. <span class="part-marks">3 marks</span> Identify **three** program modules that could be used in the design **and** describe their use. Module 1 Use Module 2 Use Module 3 Use ### (b) The program designer produces a structure chart for the new module. Part of the structure chart is shown: ![](../images/s23_21_q7_fig1.png) #### (i) Explain the relationship between the four modules shown. <span class="part-marks">2 marks</span> #### (ii) Two new modules are added: `Module‑X()` and `Module‑Y()` . <span class="part-marks">3 marks</span> - `Module‑X()` has no parameters. - `Module‑Y()` will take a string and a real number as parameters and return a Boolean value. - `Module‑D()` will call either `Module‑X()` or `Module‑Y()` . Draw **only** the part of the structure chart that represents the relationship between `Module‑X()`, `Module‑Y()` and `Module‑D()` .
Show mark scheme

7(a) [2 marks]

Examples include: Module: GetOverdueLoan() Use: Identifies an overdue book Module: IdentifyStudent() Use: Identifies a student (with an overdue book)1 Module: GetStudentEmail() Use: Gets the email address of a student with an overdue book Module: CreateEmail() Use: Generates an email to a student with an overdue book Module: SendEmail() Use: Sends an email to a student with an overdue book One mark for name and use Note: Max 3 marks

7(b)(i)

One mark per point:  Module-A calls the other three modules  The process is repeated

7(b)(ii) [7 marks]

One mark per bullet point:  All rectangles correctly labelled and interconnected  All and only parameters as shown  Selection diamond FUNCTION IsNewSupp(ThisString : STRING) RETURNS BOOLEAN

Q7
May/Jun 2023 Paper 2 v2

A computer system for a shop stores information about each customer. The items of information include name and address (both postal and email) together with payment details and order history. The system also stores the product categories they are interested in and how they would like to be contacted.

(a) The shop wants to add a program module that will generate emails to be sent to customers who may be interested in receiving details of new products.

(i) State three items of information that the new module would need. Justify your choice in each case. 3 marks

Information

Justification

Information

Justification

Information

Justification

(ii) Identify two items of customer information that would not be required by the new module. 2 marks

Justify your choice in each case.

Information

Justification

Information

Justification

(b) The program includes a module to validate a Personal Identification Number (PIN). This is used when customers pay for goods using a bank card. 4 marks

A state‑transition diagram has been produced for this module.

The table show the inputs, outputs and states for this part of the program:

Current state Input Output Next state
S1 Input PIN S2
S2 Re‑input PIN Display error S2
S2 Cancel Re‑prompt S1
S2 Valid PIN Enable payment S4
S2 Too many tries Block Account S3

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

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

7(a)(i)

Correct answers include:  Information: customer name Justification: to personalise / address the email  Information: email address Justification: so that the email can be delivered correctly  Information: product category preference Justification: to check that the customer would be interested in the product  Information: contact preference Justification: to check that the customer will accept contact via email  Information: order history Justification: to send details of product similar to that already bought // to identify frequent shoppers  Information: new product information Justification: to include information about the new product in the email One mark for each piece of information and matching justification Note: Max 3 marks

7(a)(ii) [2 marks]

One mark for each piece of information and matching justification:  postal address Justification: sending an email, not a letter  payment details Justification: Nothing being bought / sold at this stage  order history Justification: Customer preference used to decide if new product is relevant Note: Max 2 marks

7(b) [7 marks]

One mark for each: 1 Line from S1 to S2 and label 2 S2 loop label 3 S3 circle and label on incoming 4 S4 circle and label on incoming FUNCTION CheckInfo(NewLine: STRING) RETURNS BOOLEAN

Q7
May/Jun 2023 Paper 2 v3

A school has a library system which allows students to borrow books for a length of time. Information relating to students and books is stored in text files. Student information includes name, home address, email address, date of birth, tutor and subject choices. Book information includes author, title, subject category, library location and the date that the book was borrowed.

A program helps the staff to manage the borrowing of books.

(a) A new module needs to be written to generate emails to send to students who have an overdue book. Students who are sent an email are prevented from borrowing any more books until the overdue book is returned.

The process of abstraction has been used when designing the new module.

(i) State the purpose of applying abstraction to this problem. 1 mark

(ii) Identify one item of information that is required and one item that is not required in the new module. Justify your choices. 2 marks

Item required

Justification

Item not required

Justification

(iii) Identify two operations that would be required to process data when an overdue book is returned. 2 marks

Operation 1

Operation 2

(b) Part of the library program contains program modules with headers as follows: 3 marks

Pseudocode module header

     PROCEDURE Module-X()
     PROCEDURE Module-Y(BYREF RA : INTEGER, SA : REAL)
     PROCEDURE Overlay()
     FUNCTION Replace(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN
     FUNCTION Reset(TA : STRING) RETURNS INTEGER

Module-X() and Module-Y() are both called from module Overlay() .

Complete the structure chart.

A school has a library system which allows students to borrow books for a length of time. Information relating to students and books is stored in text files. Student information includes name, home address, email address, date of birth, tutor and subject choices. Book information includes author, title, subject category, library location and the date that the book was borrowed. A program helps the staff to manage the borrowing of books. ### (a) A new module needs to be written to generate emails to send to students who have an overdue book. Students who are sent an email are prevented from borrowing any more books until the overdue book is returned. The process of abstraction has been used when designing the new module. #### (i) State the purpose of applying abstraction to this problem. <span class="part-marks">1 mark</span> #### (ii) Identify **one** item of information that is required and **one** item that is **not** required in the new module. Justify your choices. <span class="part-marks">2 marks</span> Item required Justification Item not required Justification #### (iii) Identify **two** operations that would be required to process data when an overdue book is returned. <span class="part-marks">2 marks</span> Operation 1 Operation 2 ### (b) Part of the library program contains program modules with headers as follows: <span class="part-marks">3 marks</span> **Pseudocode module header** ``` PROCEDURE Module-X() PROCEDURE Module-Y(BYREF RA : INTEGER, SA : REAL) PROCEDURE Overlay() FUNCTION Replace(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN FUNCTION Reset(TA : STRING) RETURNS INTEGER ``` `Module-X()` and `Module-Y()` are both called from module `Overlay()` . Complete the structure chart. ![](../images/s23_23_q7_fig1.png)
Show mark scheme

7(a)(i) [2 marks]

To filter out information (that is not necessary to solve the problem) // to include only essential information

7(a)(ii) [2 marks]

Required: Student : Student name / email (address) Loan: Return/Issue date Book: Book title Not Required: Student: Home address / DoB / tutor / subject choices Book: Library location / category / author / book title

7(a)(iii) [3 marks]

Max 2 marks Examples could include:  Clear the loan // indicate that the book has been returned // update loan history  Take the student off 'block' // allow the student to borrow further books  Send acknowledgement to the student when book is returned

7(b) [8 marks]

Max 3 marks MP1 All modules correctly labelled and interconnected. MP2 Correct parameters and return type to Module-X and Reset MP3 Correct parameters and return type to Module-Y and Replace MP4 Correct parameters and return type to Overlay and Module-Y FUNCTION ChangeSupp(Code1, Code2 : STRING) RETURNS

Q7
Oct/Nov 2022 Paper 2 v1

A simple arithmetic expression is stored as a string in the format:

<Value1><Operator><Value2>

An operator character is one of the following: ' + ' ' − ' ' * ' ' / '

Example arithmetic expression strings:

    "803+1904"
    "34/7"

(a) 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 ' − ').

(i) Write pseudocode for the procedure Calculate() . 7 marks

(ii) Calculate() is changed to a function that returns the value of the evaluated expression. 1 mark

Write the header for the function in pseudocode.

(b) A string representing an arithmetic expression could be in the correct format but be impossible to evaluate. 2 marks

Give an example of a correctly formatted string and explain why evaluation would be impossible.

Example string

Explanation

A simple arithmetic expression is stored as a string in the format: &lt;Value1&gt;&lt;Operator&gt;&lt;Value2&gt; An operator character is one of the following: ' + ' ' − ' ' * ' ' / ' Example arithmetic expression strings: ``` "803+1904" "34/7" ``` ### (a) 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 ' − '). #### (i) Write pseudocode for the procedure `Calculate()` . <span class="part-marks">7 marks</span> #### (ii) `Calculate()` is changed to a function that returns the value of the evaluated expression. <span class="part-marks">1 mark</span> Write the header for the function in pseudocode. ### (b) A string representing an arithmetic expression could be in the correct format but be impossible to evaluate. <span class="part-marks">2 marks</span> Give an example of a correctly formatted string and explain why evaluation would be impossible. Example string Explanation
Show mark scheme

7(a)(i) [7 marks]

One mark per point ( Max 7 ) as follows: 1 Declaration of local variables for and Par1 Par2 Par3 2 Loop to end of (parameter) string // until operator is found 3 Extract a character in a loop ... 4 Attempt at extraction of three parts of expression using substring functions 5 Completely correct extraction of all three parts of expression 6. Convert string to Integer using STR_TO_NUM() 7 Attempt to interpret at least two operators ( ): + - * / Par2 8 Corresponding correct calculation (all operators) and final Output of result PROCEDURE Calculate(Expression : STRING) DECLARE Val1, Val2, Index : INTEGER DECLARE Result : REAL DECLARE Par1, Par2, Par3 : STRING CONSTANT PLUS = '+' CONSTANT MINUS = '-' CONSTANT MULTIPLY = '*' CONSTANT DIVIDE = '/'  FOR Index 1 TO LENGTH(Expression) //search for operator  ThisChar MID(Expression, Index, 1) IF IS_NUM(ThisChar) = FALSE THEN  Par1 LEFT(Expression, Index – 1)  Par2 ThisChar  Par3 RIGHT(Expression, LENGTH(Expression) – Index) ENDIF NEXT Index  Val1 STR_TO_NUM(Par1)  Val2 STR_TO_NUM(Par3) CASE OF Par2  PLUS : Result Val1 + Val2  MINUS : Result Val1 - Val2  MULTIPLY : Result Val1 * Val2  DIVIDE : Result Val1 / Val2 ENDCASE OUTPUT Result ENDPROCEDURE FUNCTION Calculate(Expression : STRING) RETURNS REAL

7(b) [2 marks]

Example string : "23/0" (Any divide by zero example) Reason : The result is infinity / cannot be represented / is undefined // will cause the program to crash

Q7
Oct/Nov 2022 Paper 2 v2

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.

Index ErrCode ErrText

1 10 "Invalid identifier name"

2 20 "Bracket mismatch"

3 50 "Undeclared variable"

4 60 "Type mismatch in assignment"

500 999 <Undefined>

Note:

  • There may be less than 500 error numbers so corresponding elements in both arrays may be unused. Unused elements in ErrCode have the value 999 . The value of unused elements in ErrText is undefined.

  • Values in the ErrCode array are stored in ascending order but not all values may be present, for example, there may be no error code 31 .

The teacher has defined two program modules as follows:

Module Description
OutputError()
takes two parameters as integers:


a line number in the student’s program


an error number

searches for the error number in theErrCode array:


if found, outputs the corresponding error description and the
line number, for example:



"Bracket mismatch on line 34"


if not found, outputs the line number and a warning, for
example:



"Unknown error on line 34"
SortArrays()
sorts the arrays into ascending order ofErrCode

(a) Write efficient pseudocode for module OutputError() . 6 marks

(b) Write an efficient bubble sort algorithm in pseudocode for module SortArrays() . 8 marks

(c) Two 1D arrays were described at the beginning of the question. 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 two arrays will be replaced by a single array. A user-defined data type (record structure) has been declared as follows:

TYPE ErrorRec
DECLARE ErrCode : STRING
DECLARE ErrText : STRING
ENDTYPE

(i) State the error in the record declaration. 1 mark

(ii) State two benefits of using the single array of the user-defined data type. 2 marks

1

2

(iii) Write the declaration for the single array in pseudocode. 1 mark

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. **Index** **`ErrCode`** **`ErrText`** 1 `10` `"Invalid identifier name"` 2 `20` `"Bracket mismatch"` 3 `50` `"Undeclared variable"` 4 `60` `"Type mismatch in assignment"` … 500 `999` `<Undefined>` **Note:** - There may be less than 500 error numbers so corresponding elements in both arrays may be unused. Unused elements in `ErrCode` have the value `999` . The value of unused elements in `ErrText` is undefined. - Values in the `ErrCode` array are stored in ascending order but not all values may be present, for example, there may be no error code `31` . The teacher has defined two program modules as follows: |Module|Description| |---|---| |`OutputError()`|• <br>takes two parameters as integers:<br> <br>○<br>a line number in the student’s program<br> <br>○<br>an error number<br>• <br>searches for the error number in the`ErrCode` array:<br> <br>○<br>if found, outputs the corresponding error description and the<br>line number, for example:<br> <br> <br> <br>`"Bracket mismatch on line 34"`<br> <br>○<br>if not found, outputs the line number and a warning, for<br>example:<br> <br> <br> <br>`"Unknown error on line 34"`| |`SortArrays()`|<br>sorts the arrays into ascending order of`ErrCode`| ### (a) Write **efficient** pseudocode for module `OutputError()` . <span class="part-marks">6 marks</span> ### (b) Write an **efficient** bubble sort algorithm in pseudocode for module `SortArrays()` . <span class="part-marks">8 marks</span> ### (c) Two 1D arrays were described at the beginning of the question. 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 two arrays will be replaced by a single array. A user-defined data type (record structure) has been declared as follows: ``` TYPE ErrorRec ``` ``` DECLARE ErrCode : STRING DECLARE ErrText : STRING ``` ``` ENDTYPE ``` #### (i) State the error in the record declaration. <span class="part-marks">1 mark</span> #### (ii) State **two** benefits of using the single array of the user-defined data type. <span class="part-marks">2 marks</span> 1 2 #### (iii) Write the declaration for the single array in pseudocode. <span class="part-marks">1 mark</span>
Show mark scheme

7(a) [6 marks]

One mark per point ( Max 6 ): 1 Procedure heading and ending including parameters 2 Conditional loop containing incrementing ... Index 3 ...terminating when found ErrNum 4 ...terminating when (i.e. ErrCode[Index] > ErrNum ErrNum not found) 5 ... OR after element 500 tested 6 Test if found and OUTPUT 'Found' message 7 ...otherwise OUTPUT 'Not Found' message PROCEDURE OutputError(LineNum, ErrNum : INTEGER) DECLARE Index : INTEGER  Index 0 // Search until ErrNum found OR not present OR end of array REPEAT  Index Index + 1 UNTIL ErrCode[Index] >= ErrNum OR Index = 500 IF ErrCode[Index] = ErrNum THEN OUTPUT ErrText[Index], " on line ", LineNum //Found ELSE OUTPUT "Unknown error on line ", LineNum //Not found ENDIF ENDPROCEURE

7(b) [8 marks]

One mark per point ( Max 8 ): 1 Procedure heading and ending as shown 2 Conditional loop correctly terminated 3 An inner loop 4 Correct range for inner loop 5 Comparison (element J with J+1) in a loop 6 Swap elements in both arrays in a loop 7 'No-Swap' mechanism: • Conditional outer loop including flag reset • Flag set in inner loop to indicate swap 8 Efficiency (this scenario): terminate inner loop when ErrCode = 999 9 Reducing in the outer loop Boundary PROCEDURE SortArrays() DECLARE TempInt, J, Boundary : INTEGER DECLARE TempStr : STRING DECLARE NoSwaps : BOOLEAN  Boundary 499 REPEAT  NoSwaps TRUE  FOR J 1 TO Boundary IF ErrCode[J]> ErrCode[J+1] THEN //first swap ErrCode elements  TempInt ErrCode[J]  ErrCode[J] ErrCode[J+1]  ErrCode[J+1] TempInt //now swap corresponding ErrText elements  TempStr ErrText[J]  ErrText[J] ErrText[J+1]  ErrText[J+1] TempStr  NoSwaps FALSE ENDIF NEXT J  Boundary Boundary - 1 UNTIL NoSwaps = TRUE ENDPROCEDURE

7(c)(i) [1 mark]

should be an // should not be a ErrCode INTEGER ErrCode STRING

7(c)(ii) [2 marks]

Benefits include: 1 Array of records can store mixed data types / multiple data types under a single identifer 2 Tighter / closer association between and // simpler ErrCode ErrText code as fields may be referenced together // values cannot get out of step as with two arrays 3 Program easier to design / write / debug / test / maintain / understand One mark per point Note: Max 2 marks DECLARE Error : ARRAY[1:500] OF ErrorRec

Q7
Oct/Nov 2022 Paper 2 v3

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.

Index ErrCode ErrText

1 10 "Invalid identifier name"

2 20 "Bracket mismatch"

3 50 ""

4 60 "Type mismatch in assignment"

...

500 999 <Undefined>

Note:

  • There are less than 500 error codes so corresponding elements in both arrays may be unused. Unused elements in ErrCode have the value 999. These will occur at the end of the array. The value of unused elements in ErrText is undefined.

  • Values in the ErrCode array are stored in ascending order but not all values may be present. For example, there may be no error code 31.

  • Some error numbers are undefined. In these instances, the ErrCode array will contain a valid error number but the corresponding ErrText element will contain an empty string.

The teacher has defined one program module as follows:

Module Description
OutputRange() • Prompts for input of two error numbers
• Outputs a list of error numbers between the two numbers input
(inclusive) together with the corresponding error description
• Outputs a warning message when the error description is
missing as for error number 50 in the example
• Outputs a suitable header and a final count of error numbers
found
Output based on the example array data above:
List of error numbers from 1 to 60
10 : Invalid identifier name
20 : Bracket mismatch
50 : Error Text Missing
60 : Type mismatch in assignment
4 error numbers output

(a) Write pseudocode for module OutputRange() . Assume that the two numbers input represent a valid error number range. 8 marks 6 marks

Question 7 continues on the next page.

b) (i) Two additional m modules are defined:
Module Description
SortArrays() • Sorts the arrays into ascending order ofErrCode
AddError() • Takes two parameters:

an error number as an integer

an error description as a string
• Writes the error number and error description to the first
unused element of the two arrays. Ensures theErrCode
array is still in ascending order
• Returns the number of unused elementsafter the new error
number has been added
• Returns −1 if the new error number could not be added

Write pseudocode for the module AddError() . Assume that the error code is not already in the ErrCode array.

(ii) A new Module RemoveError() will remove a given error number from the array. 3 marks

Describe the algorithm that would be required. Do not include pseudocode statements in your answer.

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. **Index** **`ErrCode`** **`ErrText`** 1 `10` `"Invalid identifier name"` 2 `20` `"Bracket mismatch"` 3 `50` `""` 4 `60` `"Type mismatch in assignment"` ... 500 `999` `<Undefined>` **Note:** - There are less than 500 error codes so corresponding elements in both arrays may be unused. Unused elements in `ErrCode` have the value 999. These will occur at the end of the array. The value of unused elements in `ErrText` is undefined. - Values in the `ErrCode` array are stored in ascending order but not all values may be present. For example, there may be no error code 31. - Some error numbers are undefined. In these instances, the `ErrCode` array will contain a valid error number but the corresponding `ErrText` element will contain an empty string. The teacher has defined one program module as follows: |Module|Description| |---|---| |`OutputRange()`|• Prompts for input of two error numbers<br>• Outputs a list of error numbers between the two numbers input<br>(inclusive) together with the corresponding error description<br>• Outputs a warning message when the error description is<br>missing as for error number 50 in the example<br>• Outputs a suitable header and a final count of error numbers<br>found<br>Output based on the example array data above:<br>` List of error numbers from 1 to 60`<br>` 10 : Invalid identifier name`<br>` 20 : Bracket mismatch`<br>` 50 : Error Text Missing`<br>` 60 : Type mismatch in assignment`<br>` 4 error numbers output`| ### (a) Write pseudocode for module `OutputRange()` . Assume that the two numbers input represent a valid error number range. <span class="part-marks">8 marks</span> <span class="part-marks">6 marks</span> **Question 7 continues on the next page.** |b) (i) Two additional m|modules are defined:| |---|---| |**Module**|**Description**| |`SortArrays()`|• Sorts the arrays into ascending order of`ErrCode`| |`AddError()`|• Takes two parameters:<br>• <br>an error number as an integer<br>• <br>an error description as a string<br>• Writes the error number and error description to the first<br>unused element of the two arrays. Ensures the`ErrCode` <br>array is still in ascending order<br>• Returns the number of unused elements**after** the new error<br>number has been added<br>• Returns −1 if the new error number could not be added| Write pseudocode for the module `AddError()` . Assume that the error code is **not** already in the `ErrCode` array. #### (ii) A new Module `RemoveError()` will remove a given error number from the array. <span class="part-marks">3 marks</span> Describe the algorithm that would be required. Do **not** include pseudocode statements in your answer.
Show mark scheme

7(a) [8 marks]

One mark per point ( Max 8 ): 1 Declaration and initialisation of local integer for Count 2 Appropriate prompt and two inputs 3 (Conditional) loop while error number input is in range // error code 999 reached 4 …and not end of array 5 Check if this needs to be output in a loop ErrCode 6 if so check for blank error text in a loop 7 Output in both cases 8 ….and increment count in a loop 9 OUTPUT of header and summary including count PROCEDURE OutputRange() DECLARE First, Last, Count, Index, ThisErr : INTEGER DECLARE ThisMess : STRING DECLARE PastLast: BOOLEAN  Count 0  Index 1  PastLast FALSE OUTPUT "Please input first error number: " INPUT First OUTPUT "Please input last error number: " INPUT Last OUTPUT "List of error numbers from ", First, " to ", Last WHILE Index < 501 AND NOT PastLast  ThisErr ErrCode[Index] IF ThisErr > Last THEN  PastLast TRUE ELSE IF ThisErr >= First THEN  ThisMess ErrText[Index] IF ThisMess = "" THEN  ThisMess "Error Text Missing" ENDIF OUTPUT ThisErr, " : ", ThisMess  Count Count + 1 ENDIF ENDIF  Index Index + 1 ENDWHILE OUTPUT Count, " error numbers output" ENDPROCEDURE

7(b)(i) [6 marks]

One mark per point: 1 (Conditional) loop terminating when item added OR end of array reached 2 Test for unused element in a loop 3 Assignment of values to arrays // save index of first blank location and assign after loop 4 Set loop termination if empty element found in a loop 5 Call once SortArrays() Calculation of remaining unused elements and return Integer value (for 6 both cases) FUNCTION AddError(ErrNum : INTEGER, ErrMess : STRING) RETURNS INTEGER DECLARE Index, Remaining : INTEGER CONSTANT Unused = 999  Index 1  Remaining -1 REPEAT IF ErrCode[Index] = Unused THEN  ErrCode[Index] ErrNum  ErrText[Index] ErrMess CALL SortArrays()  Remaining 500 – Index ENDIF  Index Index + 1 UNTIL Remaining <> -1 OR Index > 500 RETURN Remaining ENDFUNCTION

7(b)(ii) [3 marks]

One mark per point ( Max 3 ): 1. Loop through 500 elements (while error number not found) 2. Compare for current element with the error number ErrCode 3. If same, set element value to 999 (and terminate loop) 4. ... and call (to move 999 to the end) – once only SortArrays()

Q2
May/Jun 2022 Paper 2 v1

Examine the following state-transition diagram.

Button-Y

Button-Z | Output-B

(a) Complete the table with reference to the diagram. 3 marks

Answer
The number of different inputs
The number of different outputs
The single input value that could result in S4

(b) The initial state is S1. 4 marks

Complete the table to show the inputs, outputs and next states.

Input Output Next state
Button-Y
none
Button-Z S2
none
Examine the following state-transition diagram. Button-Y ![](../images/s22_21_q2_fig1.png) Button-Z | Output-B ### (a) Complete the table with reference to the diagram. <span class="part-marks">3 marks</span> ||Answer| |---|---| |The number of different inputs|| |The number of different outputs|| |The single input value that could result in S4|| ### (b) The initial state is S1. <span class="part-marks">4 marks</span> Complete the table to show the inputs, outputs and next states. |Input|Output|Next state| |---|---|---| |Button-Y||| ||none|| |Button-Z||S2| ||none||
Show mark scheme

2(a) [4 marks]

One mark per row The number of different inputs 3 The number of different outputs 3 The single input value that could result in S4 Button-Y

2(b)

One mark per row Example answer Note : Accept other valid answers

Q3
May/Jun 2022 Paper 2 v2

(a) The module headers for five modules in a program are defined in pseudocode as follows:

Pseudocode module header

         FUNCTION Mod_V(S2 : INTEGER) RETURNS BOOLEAN
         PROCEDURE Mod_W(P4 : INTEGER)
         PROCEDURE Mod_X(T4 : INTEGER, BYREF P3 : REAL)
         PROCEDURE Mod_Y(W3 : REAL, Z8 : INTEGER)
         FUNCTION Mod_Z(F3 : REAL) RETURNS INTEGER

An additional module Head() repeatedly calls three of the modules in sequence.

A structure chart has been partially completed.

(i) Complete the structure chart to include the information given about the six modules. 3 marks

Do not label the parameters and do not write the module names.

### (a) The module headers for five modules in a program are defined in pseudocode as follows: **Pseudocode module header** ``` FUNCTION Mod_V(S2 : INTEGER) RETURNS BOOLEAN PROCEDURE Mod_W(P4 : INTEGER) PROCEDURE Mod_X(T4 : INTEGER, BYREF P3 : REAL) PROCEDURE Mod_Y(W3 : REAL, Z8 : INTEGER) FUNCTION Mod_Z(F3 : REAL) RETURNS INTEGER ``` An additional module `Head()` repeatedly calls three of the modules in sequence. A structure chart has been partially completed. #### (i) Complete the structure chart to include the information given about the six modules. <span class="part-marks">3 marks</span> Do **not** label the parameters and do **not** write the module names. ![](../images/s22_22_q3_fig1.png)
Show mark scheme

3 Use of to generate a character in a loop RandomChar()

3(a)(ii) [3 marks]

Label Module name A Head B Mod_W C Mod_X D Mod_V E Mod-Z F Mod_Y Two rows correct – one mark Four rows correct – two marks All rows correct – three marks

3(b) [6 marks]

Breaking a complex problem down makes it easier to understand / solve // smaller problems are easier to understand / solve Smaller problems are easier to program / test / maintain Sub-problems can be given to different teams / programmers with different expertise // can be solved separately

Q3
May/Jun 2022 Paper 2 v3

Four program modules are defined as follows:

Pseudocode module header

   PROCEDURE Sub1_A(XT : INTEGER, PB : STRING)
   FUNCTION Sub1_B(RA : INTEGER) RETURNS BOOLEAN
   PROCEDURE Sub1_C(SB : INTEGER, BYREF SA : STRING)
   PROCEDURE Section_1()

(a) A structure chart will be produced as part of the development process. 2 marks

Describe the purpose of a structure chart.

(b) Module Section_1() calls one of the other three modules. The module called will be selected when the program runs. 5 marks

Draw the structure chart.

Four program modules are defined as follows: **Pseudocode module header** ``` PROCEDURE Sub1_A(XT : INTEGER, PB : STRING) FUNCTION Sub1_B(RA : INTEGER) RETURNS BOOLEAN PROCEDURE Sub1_C(SB : INTEGER, BYREF SA : STRING) PROCEDURE Section_1() ``` ### (a) A structure chart will be produced as part of the development process. <span class="part-marks">2 marks</span> Describe the purpose of a structure chart. ### (b) Module `Section_1()` calls one of the other three modules. The module called will be selected when the program runs. <span class="part-marks">5 marks</span> Draw the structure chart.
Show mark scheme

3(a) [5 marks]

One mark per point to show:  module relationships / hierarchy / selection / repetition // how a problem is broken down  the parameters that are passed between the sub-tasks / modules // whether a module is a function or a procedure

3(b)

One mark for each: 1 Four boxes linked as shown correctly labelled (Order of lower 3 not important) 2 Parameters to Sub1_A 3 Parameter to Sub1_B and return value 4 Parameters to Sub1_C 5 Selection diamond

Q4
Oct/Nov 2021 Paper 2 v1

A program controls the heating system in a sports hall.

Part of the program involves reading a value from a sensor. The sensor produces a numeric value that represents the temperature. The value is an integer, which should be in the range 0 to 40 inclusive.

A program function has been written to validate the values from the sensor.

(a) A test plan is needed to test the function. 4 marks

Complete the table. The first line has been completed for you.

You can assume that the sensor will generate only integer data values.

Test Test data value Explanation Expected outcome
1 23 Normal data Data is accepted
2
3
4
5

(b) A program module controls the heaters. This module operates as follows: 3 marks

  • If the temperature is below 10, switch the heaters on.

  • If the temperature is above 20, switch the heaters off.

Complete the following state-transition diagram for the heating system:

The following data items will be record network: ded each time a student successfully logs
Data item Example data
Student ID "CJL404"
Host ID "Lib01"
Time and date "08:30, June 01, 2021"

The Student ID is six characters long. The other two data items are of variable length.

A single string will be formed by concatenating the three data items. A separator character will need to be inserted between items two and three.

For example:

    "CJL404Lib01<separator>08:30, June 01, 2021"

Each string represents one log entry.

A programmer decides to store the concatenated strings in a 1D array LogArray that contains 2000 elements. Unused array elements will contain an empty string.

(a) Suggest a suitable separator character and give a reason for your choice. 2 marks

Character

Reason

(b) The choice of data structure was made during one stage of the program development life cycle. 1 mark

Identify this stage.

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

  • count the number of lines added to the file

  • return this count.

Write pseudocode for the function LogEvents() .

A program controls the heating system in a sports hall. Part of the program involves reading a value from a sensor. The sensor produces a numeric value that represents the temperature. The value is an integer, which should be in the range 0 to 40 inclusive. A program function has been written to validate the values from the sensor. ### (a) A test plan is needed to test the function. <span class="part-marks">4 marks</span> Complete the table. The first line has been completed for you. You can assume that the sensor will generate only integer data values. |Test|Test data value|Explanation|Expected outcome| |---|---|---|---| |**1**|23|Normal data|Data is accepted| |**2**|||| |**3**|||| |**4**|||| |**5**|||| ### (b) A program module controls the heaters. This module operates as follows: <span class="part-marks">3 marks</span> - If the temperature is below 10, switch the heaters on. - If the temperature is above 20, switch the heaters off. Complete the following state-transition diagram for the heating system: ![](../images/w21_21_q4_fig1.png) |The following data items will be record network:|ded each time a student successfully logs| |---|---| |**Data item**|**Example data**| |Student ID|`"CJL404"`| |Host ID|`"Lib01"`| |Time and date|`"08:30, June 01, 2021"`| The Student ID is six characters long. The other two data items are of variable length. A single string will be formed by concatenating the three data items. A separator character will need to be inserted between items two and three. For example: ``` "CJL404Lib01<separator>08:30, June 01, 2021" ``` Each string represents one log entry. A programmer decides to store the concatenated strings in a 1D array `LogArray` that contains 2000 elements. Unused array elements will contain an empty string. ### (a) Suggest a suitable separator character **and** give a reason for your choice. <span class="part-marks">2 marks</span> Character Reason ### (b) The choice of data structure was made during one stage of the program development life cycle. <span class="part-marks">1 mark</span> Identify this stage. ### (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 <span class="part-marks">7 marks</span> - count the number of lines added to the file - return this count. Write pseudocode for the function `LogEvents()` .
Show mark scheme

4(a)

Test Test data value Explanation Expected Outcome 1 23 Normal Data Data is accepted 2 0 Boundary Data Data is accepted 3 40 Boundary Data Data is accepted 4

= 41 Abnormal Data Data is rejected 5 <= −1 Abnormal Data Data is rejected One mark per row for rows 2 to 5.

4(b) [3 marks]

One mark for each label: Temp < 10 (Heaters Off to Heaters On) • Temp > 20 (Heaters On to Heaters Off) • on BOTH loops (non-contradictory values) •

Q4
Oct/Nov 2021 Paper 2 v3

A program controls the heating system in a sports hall.

Part of the program involves reading a value from a sensor. The sensor produces a numeric value that represents the temperature. The value is an integer, which should be in the range 0 to 40 inclusive.

A program function has been written to validate the values from the sensor.

(a) A test plan is needed to test the function. 4 marks

Complete the table. The first line has been completed for you.

You can assume that the sensor will generate only integer data values.

Test Test data value Explanation Expected outcome
1 23 Normal data Data is accepted
2
3
4
5

(b) A program module controls the heaters. This module operates as follows: 3 marks

  • If the temperature is below 10, switch the heaters on.

  • If the temperature is above 20, switch the heaters off.

Complete the following state-transition diagram for the heating system:

The following data items will be record network: ded each time a student successfully logs
Data item Example data
Student ID "CJL404"
Host ID "Lib01"
Time and date "08:30, June 01, 2021"

The Student ID is six characters long. The other two data items are of variable length.

A single string will be formed by concatenating the three data items. A separator character will need to be inserted between items two and three.

For example:

    "CJL404Lib01<separator>08:30, June 01, 2021"

Each string represents one log entry.

A programmer decides to store the concatenated strings in a 1D array LogArray that contains 2000 elements. Unused array elements will contain an empty string.

(a) Suggest a suitable separator character and give a reason for your choice. 2 marks

Character

Reason

(b) The choice of data structure was made during one stage of the program development life cycle. 1 mark

Identify this stage.

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

  • count the number of lines added to the file

  • return this count.

Write pseudocode for the function LogEvents() .

A program controls the heating system in a sports hall. Part of the program involves reading a value from a sensor. The sensor produces a numeric value that represents the temperature. The value is an integer, which should be in the range 0 to 40 inclusive. A program function has been written to validate the values from the sensor. ### (a) A test plan is needed to test the function. <span class="part-marks">4 marks</span> Complete the table. The first line has been completed for you. You can assume that the sensor will generate only integer data values. |Test|Test data value|Explanation|Expected outcome| |---|---|---|---| |**1**|23|Normal data|Data is accepted| |**2**|||| |**3**|||| |**4**|||| |**5**|||| ### (b) A program module controls the heaters. This module operates as follows: <span class="part-marks">3 marks</span> - If the temperature is below 10, switch the heaters on. - If the temperature is above 20, switch the heaters off. Complete the following state-transition diagram for the heating system: ![](../images/w21_23_q4_fig1.png) |The following data items will be record network:|ded each time a student successfully logs| |---|---| |**Data item**|**Example data**| |Student ID|`"CJL404"`| |Host ID|`"Lib01"`| |Time and date|`"08:30, June 01, 2021"`| The Student ID is six characters long. The other two data items are of variable length. A single string will be formed by concatenating the three data items. A separator character will need to be inserted between items two and three. For example: ``` "CJL404Lib01<separator>08:30, June 01, 2021" ``` Each string represents one log entry. A programmer decides to store the concatenated strings in a 1D array `LogArray` that contains 2000 elements. Unused array elements will contain an empty string. ### (a) Suggest a suitable separator character **and** give a reason for your choice. <span class="part-marks">2 marks</span> Character Reason ### (b) The choice of data structure was made during one stage of the program development life cycle. <span class="part-marks">1 mark</span> Identify this stage. ### (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 <span class="part-marks">7 marks</span> - count the number of lines added to the file - return this count. Write pseudocode for the function `LogEvents()` .
Show mark scheme

4(a)

Test Test data value Explanation Expected Outcome 1 23 Normal Data Data is accepted 2 0 Boundary Data Data is accepted 3 40 Boundary Data Data is accepted 4

= 41 Abnormal Data Data is rejected 5 <= −1 Abnormal Data Data is rejected One mark per row for rows 2 to 5.

4(b) [3 marks]

One mark for each label: Temp < 10 (Heaters Off to Heaters On) • Temp > 20 (Heaters On to Heaters Off) • on BOTH loops (non-contradictory values) •

Q2
May/Jun 2021 Paper 2 v1

(a) Four program modules form part of a program for a library. 5 marks

A description of the relationship between the modules is summarised as follows:

Module name Description
UpdateLoan()
Calls eitherLoanExtend() orLoanReturn()
LoanExtend()
Called with parametersLoanID andBookID

CallsCheckReserve() to see whether the book has been
reserved for another library user

ReturnsTRUE if the loan has been extended, otherwise returns
FALSE
CheckReserve()
Called withBookID

ReturnsTRUE if the book has been reserved, otherwise returns
FALSE
LoanReturn()
Called with parametersLoanID andBookID

Returns aREAL (which is the value of the fine to be paid in the
case of an overdue loan)

Draw a structure chart to show the relationship between the four modules and the parameters passed between them.

### (a) Four program modules form part of a program for a library. <span class="part-marks">5 marks</span> A description of the relationship between the modules is summarised as follows: |Module name|Description| |---|---| |`UpdateLoan()`|• <br>Calls either`LoanExtend()` or`LoanReturn()`| |`LoanExtend()`|• <br>Called with parameters`LoanID` and`BookID`<br>• <br>Calls`CheckReserve()` to see whether the book has been<br>reserved for another library user<br>• <br>Returns`TRUE` if the loan has been extended, otherwise returns<br>`FALSE`| |`CheckReserve()`|• <br>Called with`BookID`<br>• <br>Returns`TRUE` if the book has been reserved, otherwise returns<br>`FALSE`| |`LoanReturn()`|• <br>Called with parameters`LoanID` and`BookID`<br>• <br>Returns a`REAL` (which is the value of the fine to be paid in the<br>case of an overdue loan)| Draw a structure chart to show the relationship between the four modules and the parameters passed between them.
Show mark scheme

2(a)

One mark for: 1 All four boxes correctly labelled and positioned 2 Selection diamond (only on and no iteration arrows) UpdateLoan 3 Parameters to and from LoanExtend() 4 Parameters to and from CheckReserve() 5 Parameters to and from LoanReturn()

2(b) [6 marks]

PROCEDURE LoanReturn (LoanID, BookID : STRING, BYREF Fine : REAL) One mark for each underlined part

2(c) [2 marks]

Explanation of mark points: 1 Initialise to first value input MAX 2 Set to zero Total 3 Input 49 more values (or 50 values in total) 4 Sum all values input 5 Set new when Input value in a loop MAX

MAX 6 Sum all but largest (or subtract from total), calculate and output MAX average

Q2
May/Jun 2021 Paper 2 v2

(a) Examine the following state-transition diagram.

Low level detected | Activate pump

(i) Complete the table with reference to the diagram. 4 marks

Answer
The number of transitions that result in a different state
The number of transitions with associated outputs
The label that should replace ‘X’
The final or halting state

(ii) The current state is S1. The following inputs occur. 2 marks

  1. Low level detected
  2. Low level detected
  3. Low level detected
  4. Low level detected

Give the number of outputs and the current state.

Number of outputs

Current state

### (a) Examine the following state-transition diagram. Low level detected | Activate pump ![](../images/s21_22_q2_fig1.png) #### (i) Complete the table with reference to the diagram. <span class="part-marks">4 marks</span> ||Answer| |---|---| |The number of transitions that result in a different state|| |The number of transitions with associated outputs|| |The label that should replace ‘X’|| |The final or halting state|| #### (ii) The current state is S1. The following inputs occur. <span class="part-marks">2 marks</span> 1. Low level detected 2. Low level detected 3. Low level detected 4. Low level detected Give the number of outputs and the current state. Number of outputs Current state
Show mark scheme

2(a)(i) [2 marks]

The number of transitions that result in a different state 3 The number of transitions with associated outputs 2 The label that should replace ‘X’ Start The final or halting state S3 One mark per row

2(a)(ii) [2 marks]

Number of outputs: 1 Current state: S2

2(b)(i) [1 mark]

Answers include: User ID / Username • Book ID • Date of loan / return date • One mark for 1 correct Two marks for all 3 correct Note: Max 2 marks

2(b)(ii)

Many examples but must be data that is NOT required for a loan, but which COULD be required somewhere by the library system. Note: must be data relating to users, books or loans Answers include: Users name / address / phone number / DOB • Book title / author / publisher / library rack number / ISBN number / • price Date of loan / return date (if not already given in part (i)) • The length of the loan (assumed to be the same for all books) •

2(b)(iii) [2 marks]

Many examples including: Create loan / borrow book • Return book • Send letter / email / contact a user ref an overdue book • View the loan history for a given book • View the loan history for a given user • One mark for each Note: Max 2 marks

Q2
May/Jun 2021 Paper 2 v3

(a) Four program modules form part of a program for a library. 5 marks

A description of the relationship between the modules is summarised as follows:

Module name Description
UpdateLoan()
Calls eitherLoanExtend() orLoanReturn()
LoanExtend()
Called with parametersLoanID andBookID

CallsCheckReserve() to see whether the book has been
reserved for another library user

ReturnsTRUE if the loan has been extended, otherwise returns
FALSE
CheckReserve()
Called withBookID

ReturnsTRUE if the book has been reserved, otherwise returns
FALSE
LoanReturn()
Called with parametersLoanID andBookID

Returns aREAL (which is the value of the fine to be paid in the
case of an overdue loan)

Draw a structure chart to show the relationship between the four modules and the parameters passed between them.

### (a) Four program modules form part of a program for a library. <span class="part-marks">5 marks</span> A description of the relationship between the modules is summarised as follows: |Module name|Description| |---|---| |`UpdateLoan()`|• <br>Calls either`LoanExtend()` or`LoanReturn()`| |`LoanExtend()`|• <br>Called with parameters`LoanID` and`BookID`<br>• <br>Calls`CheckReserve()` to see whether the book has been<br>reserved for another library user<br>• <br>Returns`TRUE` if the loan has been extended, otherwise returns<br>`FALSE`| |`CheckReserve()`|• <br>Called with`BookID`<br>• <br>Returns`TRUE` if the book has been reserved, otherwise returns<br>`FALSE`| |`LoanReturn()`|• <br>Called with parameters`LoanID` and`BookID`<br>• <br>Returns a`REAL` (which is the value of the fine to be paid in the<br>case of an overdue loan)| Draw a structure chart to show the relationship between the four modules and the parameters passed between them.
Show mark scheme

2(a)

One mark for: 1 All four boxes correctly labelled and positioned 2 Selection diamond (only on and no iteration arrows) UpdateLoan 3 Parameters to and from LoanExtend() 4 Parameters to and from CheckReserve() 5 Parameters to and from LoanReturn()

2(b) [6 marks]

PROCEDURE LoanReturn (LoanID, BookID : STRING, BYREF Fine : REAL) One mark for each underlined part

2(c) [2 marks]

Explanation of mark points: 1 Initialise to first value input MAX 2 Set to zero Total 3 Input 49 more values (or 50 values in total) 4 Sum all values input 5 Set new when Input value in a loop MAX

MAX 6 Sum all but largest (or subtract from total), calculate and output MAX average