Skip to content

11.3 Structured Programming

AS Level · 11 questions found

  • Define and use procedures; pass parameters by value or by reference
  • Define and use functions; return values used in expressions
  • Terminology: header, interface, parameter, argument, return value
  • Write efficient pseudocode
Q4
May/Jun 2024 Paper 2 v1
Question 4 — page 1Question 4 — page 2Question 4 — page 3
4 A function Check() will: • total the element values in odd index locations (1, 3, 5 ... 97, 99) • total the element values in even index locations (2, 4, 6 ... 98, 100) • return one of three strings ‘Odd’, ‘Even’ or ‘Same’ to indicate which total is the greater, or whether the totals are the same. Write pseudocode for the function Check(). .................................................................................................................................................... [6] BLANK PAGE
Show mark scheme
4
Example:
FUNCTION Check() RETURNS STRING
DECLARE Odd, Even, Index : INTEGER

Odd
0

Even
0

FOR Index
1 TO 100
IF Index MOD 2 = 0 THEN

Even
Even + Data[Index]
ELSE

Odd
Odd + Data[Index]
ENDIF
NEXT Index
ENDFUNCTION
Mark as follows:
1. Function heading, ending and return type
2. Declare local variables
and
as integers
Odd, Even
Index
3. Initialise
and
Odd
Even
4. Loop for 100
// through array
iterations
5. Sum
and
element values
in a loop
Odd
Even
6. Compare
and
after the loop and Return appropriate string
Odd
Even
Q5
May/Jun 2024 Paper 2 v1 12 marks
Question 5 — page 1Question 5 — page 2Question 5 — page 3
5 A global 1D array of strings contains three elements which are assigned values as shown: Data[1] "aaaaaa" Data[2] "bbbbbb" Data[3] "cccccc" Procedure Process() manipulates the values in the array. The procedure is written in pseudocode as follows: PROCEDURE Process(Format : STRING) DECLARE Count, Index, L : INTEGER DECLARE Result : STRING DECLARE C : CHAR Result "****" FOR Count 1 TO LENGTH(Format) STEP 2 C MID(Format, Count, 1) L STR_TO_NUM(MID(Format, Count + 1, 1)) Index (Count + 1) DIV 2 CASE OF C 'X' : Result TO_UPPER(Data[Index]) 'Y' : Result TO_LOWER(Data[Index]) 'Z' : Result "**" & Data[Index] ENDCASE Data[Index] LEFT(Result, L) NEXT Count ENDPROCEDURE (a) Complete the trace table by dry running the procedure when it is called as follows: CALL Process("X3Y2W4") Count C L Index Result Data[1] Data[2] Data[3] [6] (b) The procedure is to be modified. If variable C is assigned a value other than 'X', 'Y' or 'Z', then procedure Error() is called and passed the value of variable C as a parameter. This modification can be implemented by adding a single line of pseudocode. (i) Write the single line of pseudocode. ..................................................................................................................................... [1] (ii) State where this new line should be placed. ..................................................................................................................................... [1]
Show mark scheme
5(a) [6 marks]
One mark per zone.
OTHERWISE : CALL Error(C)
5(b)(ii) [6 marks]
After the '
' clause in the
construct // before the
Z
CASE
ENDCASE
FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS
Q7
May/Jun 2024 Paper 2 v1 17 marks
Question 7 — page 1Question 7 — page 2Question 7 — page 3Question 7 — page 4Question 7 — page 5Question 7 — page 6Question 7 — page 7Question 7 — page 8Question 7 — page 9Question 7 — page 10Question 7 — page 11Question 7 — page 12Question 7 — page 13
x 7 6 5 4 1 0 2 3 4 5 6 7 8 9 10 A C B 3 2 1 A triangle is said to be right-angled if the following test is true (where A is the length of the longest side): A2 = B2 + C2 A2 means A multiplied by A, for example 32 means 3 × 3 which evaluates to 9 You can calculate A2, B2 and C2 by using the coordinates of the endpoints of each line. For example, B2 is calculated as follows: 10 y x 9 8 7 6 5 4 1 0 2 3 4 5 6 7 8 9 10 B P2 P2 P1 P1 3 2 1 (x1, y1) (x1, y1) (x2, y2) (x2, y2) The endpoints, P1 and P2, have the coordinates (3, 2) and (6, 6). The value B2 is given by the formula: B2 = (x1 − x2)2 + (y1 − y2)2 In this example: B2 = (3 − 6)2 + (2 − 6)2 B2 = (–3)2 + (–4)2 B2 = 9 + 16 B2 = 25 (a) A function IsRA() will: • take three sets of integers as parameters representing the coordinates of the three endpoints that form a triangle • return TRUE if the endpoints form a right-angled triangle, otherwise return FALSE. In pseudocode, the operator ‘^’ represents an exponent, which is the number of times a value is multiplied by itself. For example, the expression Value2 may be written in pseudocode as Value ^ 2 Complete the pseudocode for the function IsRA(). FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS BOOLEAN ENDFUNCTION [6] (b) The test used to check if a triangle is right-angled can be written in two ways: A2 = B2 + C2 or A = √(B2 + C2) The symbol √ represents the square root operation. For example, √81 = 9 A new function SQRT() is written to perform the square root operation. The function takes an integer number as a parameter and returns a positive real value representing the square root of the number. During testing it is found that the SQRT() function returns a value that is only accurate to 4 decimal places. For example, SQRT(25) returns 5.0000125 rather than the correct value of 5.0 The function IsRA() from part (a) is modified to use the new SQRT() function to test if a triangle is right-angled. Describe a problem that might occur when using the modified IsRA() function and suggest a solution that still allows the SQRT() function to be used. Problem .................................................................................................................................... Solution ..................................................................................................................................... [2] BLANK PAGE 7 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] (ii) Identify three items of information that will be required by the new module. Justify your choices with reference to the given scenario. Item 1 required .................................................................................................................. Justification ....................................................................................................................... Item 2 required .................................................................................................................. Justification ....................................................................................................................... Item 3 required .................................................................................................................. Justification ....................................................................................................................... [3] (iii) Identify two operations that would be required to process data when the new module receives a text message back from a member. Operation 1 ....................................................................................................................... Operation 2 ....................................................................................................................... [2] (b) The structure chart illustrates part of the membership program: Sub-A Sub-B P1 T1 P2 Name Update Sub-C A 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] (ii) Write the pseudocode module headers for Sub-A and Sub-B. Sub-A Sub-B [4] 8 A teacher is designing a program to process pseudocode projects written by her students. Each student project is stored in a text file. The process is split into a number of stages. Each stage performs a different task and creates a new file named as shown: File name Comment MichaelAday_src.txt student project file produced by student Michael Aday MichaelAday_S1.txt file produced by stage 1 MichaelAday_S2.txt file produced by stage 2 The teacher has defined the first program module as follows: Module Description DeleteComment() • called with a parameter of type string representing a line of pseudocode from a student’s project file • returns the line after removing any comments Note on comments: A comment starts with two forward slash characters and includes all the remaining characters on the line. The following example shows a string before and after the comment has been removed: Before: IF X2 > 13 THEN //check if limit exceeded After: IF X2 > 13 THEN (a) Complete the pseudocode for module DeleteComment(). FUNCTION DeleteComment(Line : STRING) RETURNS STRING ENDFUNCTION [8] (b) A second module is defined: Module Description Stage_1() • called with a parameter of type string representing a student name • creates a new stage 1 file • copies each line from the student’s project file to the stage 1 file after removing any comment from each line • does not write blank lines to the stage 1 file • returns the number of lines written to the stage 1 file Write pseudocode for module Stage_1(). Module DeleteComment() must be used in your solution. ............................................................................................................................................. [7] BLANK PAGE BLANK PAGE Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity. To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cambridgeinternational.org after the live examination series. Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge BLANK PAGE
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
Q8
May/Jun 2024 Paper 2 v1 7 marks
Question 8
8
Show mark scheme
8(a) [7 marks]
DECLARE NewLine, TwoChars : STRING
DECLARE Count, TrimTo : INTEGER
CONSTANT Comment = "//"

NewLine
Line

TrimTo
0

Count
1
WHILE Count < LENGTH(Line) AND TrimTo = 0

TwoChars
MID(Line, Count, 2) // extract 2 chars
IF TwoChars = Comment THEN

TrimTo
Count
ENDIF

Count
Count + 1
ENDWHILE
IF TrimTo <> 0 THEN

NewLine
LEFT(Line, TrimTo - 1)
ENDIF
RETURN NewLine
ENDFUNCTION
Mark as follows:
1
Loop to length of
(parameter) // length of
Line
Line -1
2
Terminate loop on first double slash
3
Attempt to extract one/two characters
in a loop
4
Check for "//" after attempt at extraction
in a loop
5
Record start position of comment // Calculate amount of trim required
6
Attempt to trim
from start of comment
Line
7
Completely correct trimmed
from start of comment
Line
8
Return
after a reasonable overall attempt
Line
8(b)
Example:
FUNCTION Stage_1(StudentName : STRING) RETURNS INTEGER
DECLARE OldFile, NewFile, Line : STRING
DECLARE Count : INTEGER

OldFile
StudentName & "_src.txt"

NewFile
StudentName & "_S1.txt"
OPENFILE OldFile FOR READ
OPENFILE NewFile FOR WRITE

Count
0
WHILE NOT EOF(OldFile)
READFILE OldFile, Line

Line
DeleteComment(Line)
IF LENGTH(Line) <> 0 THEN
WRITEFILE NewFile, Line

Count
Count + 1
ENDIF
ENDWHILE
CLOSEFILE OldFile
CLOSEFILE NewFile
RETURN Count
ENDFUNCTION
Mark as follows:
1
Generate filenames condone missing “_”
2
Open both files in correct modes
and
subsequently close
3
Loop to
EOF(OldFile)
4
Read a line from
and
execute
in a loop
OldFile
DeleteComment()
5
Skip blank lines after
in a loop
DeleteComment()
6
Write
to stage 1 file
and
increment Count
Line
7
Return the number of lines after a reasonable attempt at counting
Q7
May/Jun 2024 Paper 2 v2 7 marks
Question 7 — page 1Question 7 — page 2Question 7 — page 3
7 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). 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 ........................................................................................................................................... [3] (b) A different part of the program is represented by the following state‑transition diagram. S1 START S4 S3 Input-B | Output-W Input-A | Output-X Input-B | Output-Y Input-A | Output-W Input-B Input-B Input-A Input-A S2 S5 (i) Complete the table to show the inputs, outputs and next states. 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 [5] (ii) Identify the input sequence that will cause the minimum number of state changes in the transition from S1 to S4. ..................................................................................................................................... [1]
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
Q8
May/Jun 2024 Paper 2 v2 14 marks
Question 8 — page 1Question 8 — page 2Question 8 — page 3Question 8 — page 4Question 8 — page 5Question 8 — page 6Question 8 — page 7
8 A teacher is designing a program to process pseudocode projects written by her students. Each student project is stored in a text file. The process is split into a number of stages. Each stage performs a different task and creates a new file. For example: File name Comment MichaelAday_src.txt Student project file produced by student Michael Aday MichaelAday_S1.txt File produced by stage 1 MichaelAday_S2.txt File produced by stage 2 (a) Suggest a reason why the teacher’s program has been split into a number of stages and give the benefit of producing a different file from each stage. Reason ..................................................................................................................................... Benefit ...................................................................................................................................... [2] (b) The teacher has defined the first program module as follows: Module Description DeleteSpaces() • called with a parameter of type string representing a line of pseudocode from a student’s project file • returns the line after removing any leading space characters The following example shows a string before and after the leading spaces have been removed: Before: " IF X2 > 13 THEN" After: "IF X2 > 13 THEN" Complete the pseudocode for module DeleteSpaces(). FUNCTION DeleteSpaces(Line : STRING) RETURNS STRING ENDFUNCTION [6] (c) Two modules are defined: Module Description DeleteComment() (already written) • called with a parameter of type string representing a line of pseudocode from a student’s project file • returns the line after removing any comment Stage_2() • called with two parameters: ○ a string representing an input file name ○ a string representing an output file name • copies each line from the input file to the existing output file having first removed all leading spaces and comments from that line • does not write blank lines to the output file • outputs a final message giving the number of blank lines removed Write pseudocode for module Stage_2(). Modules DeleteComment() and DeleteSpaces() must be used in your solution. ............................................................................................................................................. [8] BLANK PAGE BLANK PAGE Permission to reproduce items where third‑party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity. To avoid the issue of disclosure of answer‑related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cambridgeinternational.org after the live examination series. Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge BLANK PAGE
Show mark scheme
8(a) [6 marks]
One mark for reason, one for benefit
Reason: (Program is) easier to design / implement / test / debug / modify
Benefit: Easier to check that
each stage
works as expected
8(b) [8 marks]
Example algorithm based on finding position of first non-space character and
then using substring function:
FUNCTION DeleteSpaces(Line : STRING) RETURNS STRING
DECLARE NewLine : STRING
DECLARE EndOfLeading : BOOLEAN
DECLARE Count, NumSpaces : INTEGER
DECLARE NextChar : CHAR
CONSTANT Space = " "

NumSpaces
0

EndOfLeading
FALSE

FOR Count
1 TO LENGTH(Line)

NextChar
MID(Line, Count, 1)
IF NextChar <> Space AND EndOfLeading = FALSE
THEN

NumSpaces
Count - 1 // the number to trim
EndOfLeading = TRUE
ENDIF
NEXT Count

NewLine
RIGHT(Line, LENGTH(Line) - NumSpaces)
RETURN NewLine
ENDFUNCTION
Mark as follows:
1
Loop to length of parameter
// Loop until first non-space
character in Line
2
Extract a character
in a loop
3
Identify first non-space character
in a loop
4
Attempt at removing leading spaces in
Line
5
Leading spaces removed from
/ / Create new string without leading
Line
space
6
Return a string following a reasonable attempt at removing leading spaces
in
Line
8(c)
Example:
PROCEDURE Stage_2(F1, F2 : STRING)
DECLARE Line : STRING
DECLARE Count : INTEGER

Count
0
OPEN F1 FOR READ
OPEN F2 FOR APPEND
WHILE NOT EOF(F1)
READFILE F1, Line

Line
DeleteSpaces(Line)

Line
DeleteComment(Line)
IF Line <> "" THEN
WRITEFILE F2, Line // skip blank lines
ELSE

Count
Count + 1
ENDIF
ENDWHILE
CLOSEFILE F1
CLOSEFILE F2
OUTPUT Count, " blank lines were removed"
ENDPROCEDURE
Mark as follows:
1
Procedure heading, parameters, ending
2
Open both files in correct modes
and
subsequently close
3
Loop to
EOF(F1)
4
Read a line from
in a loop
F1
5
Assign return values from
and
DeleteComment()
DeleteSpaces()
in a loop
6
Check return value following both MP5 function calls is not an empty
string and if so write to
in a loop
F2
7
Count the blank lines
in a loop
8
Output number of blank lines removed following a reasonable attempt
after the loop
Q1
May/Jun 2024 Paper 2 v3 9 marks
Question 1 — page 1Question 1 — page 2Question 1 — page 3
1 A program uses many complex algorithms. One algorithm is repeated in several places. The code for the algorithm is the same wherever it is used, but the calculations within the algorithm may operate on different data. The result of each calculation is used by the code that follows it. It is decided to modify the program and implement the algorithm as a separate module. (a) (i) State two benefits of this modification to the existing program. 1 ........................................................................................................................................ 2 ........................................................................................................................................ [2] (ii) Describe how the modification would be implemented. ..................................................................................................................................... [3] (b) Four of the expressions used in the program are represented by pseudocode in the table. Complete each pseudocode expression with a function or operator so that it evaluates to the value shown. Any functions and operators used must be defined in the insert. Pseudocode expression Evaluates to ........................................ ("Random", 2, 3) "and" 5 + ........................................ (10/11/2023) 15 ........................................ ("45000") TRUE (20 ........................................ 3) + 1 3 [4] ,  , ,  ,
Show mark scheme
1(a)(i)
Two marks for the benefits:
1. The code can be called when needed
2. Any subsequent change to the algorithm / calculation needs to be made
once only // Easier to manage / maintain (the program)
3. Less code / no code duplication
4. The algorithm / code / calculation can be designed / coded / tested
once
Note: Max 2 marks
1(a)(ii) [4 marks]
One mark per point:
1. Create a module / function / procedure / subroutine
using the (old) code /
algorithm
2. Replace the old code / algorithm wherever it appears with a call to the
module / function / procedure / subroutine
3. Pass the data as parameter(s) // Use of global variable(s)
4. Return the result (of the calculation) // Assign result to global variable(s) /
BYREF parameter(s)
5. Create local variables as needed (to perform the calculation)
Note: Max 3 marks
1(b) [5 marks]
Pseudocode expression
Evaluates to
"and"
MID
("Random", 2, 3)
15
DAY
5 +
(10/11/2023)
TRUE
IS_NUM
("45000")
3
MOD
(20
3) + 1
One mark per row
Q5
May/Jun 2024 Paper 2 v3 10 marks
Question 5 — page 1Question 5 — page 2Question 5 — page 3
5 A program is being designed in pseudocode. The program contains the following declaration: DECLARE Data : ARRAY[1:1000] OF STRING A procedure ArrayInitialise() is written to initialise the values in the array: PROCEDURE ArrayInitialise(Label : STRING) DECLARE Index : INTEGER Index 1 WHILE Index <= 1000 CASE OF (Index MOD 2) 0 : Data[Index] FormatA(Label) Index Index + 1 1 : Data[Index] FormatB(Label) Index Index + 1 ENDCASE ENDWHILE ENDPROCEDURE Functions FormatA() and FormatB() apply fixed format case changes to the parameter string. (a) The design of the procedure does not use the most appropriate loop construct. Suggest a more appropriate construct that could be used and explain your choice. Construct .................................................................................................................................. Explanation ............................................................................................................................... [2] (b) The algorithm calls one of the functions FormatA() and FormatB() each time within the loop. Explain why this is not efficient and suggest a more efficient solution. ............................................................................................................................................. [4] BLANK PAGE ,  , ,  ,
Show mark scheme
5(a) [4 marks]
One mark per point

Count-controlled loop

the number of iterations is known
5(b) [6 marks]
Two mark for Statement of Problem:
1
The functions will return the same value every time they are called
2
... because
/ the parameter value does not change within the loop
Label
Two marks for Solution:
3
Assign
and
to two (local) variables
FormatA(Label)
FormatB(Label)
before the loop
4
Use the (new) variables in place of the function calls / in the loop //
Replace the references to
and
in the
FormatA()
FormatB()
CASE
clauses with the new variable names
Q7
May/Jun 2024 Paper 2 v3 15 marks
Question 7 — page 1Question 7 — page 2Question 7 — page 3
7 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] (ii) Modules Mod-F and Mod-G are both called with Par3 as a parameter. 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. ..................................................................................................................................... [2] (b) Draw a structure chart to show the relationship between the seven modules and the parameters passed between them. [6] ,  , ,   ,
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
Q8
May/Jun 2024 Paper 2 v3 8 marks
Question 8 — page 1Question 8 — page 2Question 8 — page 3Question 8 — page 4Question 8 — page 5Question 8 — page 6Question 8 — page 7
8 A teacher is designing a program to process pseudocode projects written by her students. The program analyses a student project and extracts information about each module that is defined (each procedure or function). This information is stored in a global 2D array ModInfo of type string. A module header is the first line of a module definition and starts with either of the keywords PROCEDURE or FUNCTION. An example of part of the array is given below. Row 10 of the array shows that a procedure header occurs on line 27 and row 11 shows that a function header occurs on line 35. "P" represents a procedure and "F" represents a function: x = 1 x = 2 x = 3 ModInfo[10, x] "27" "P" "MyProc(Z : CHAR)" ModInfo[11, x] "35" "F" "MyFun(Y : CHAR) RETURNS BOOLEAN" The string stored in column 3 is called the module description. This is the module header without the keyword. A valid module header will: • be at least 13 characters long • start with the keyword PROCEDURE or FUNCTION. The keyword may appear in either upper or lower case (or a mix of both) and must be followed by a space character. The teacher has defined the first program module as follows: Module Description Header() • called with a parameter of type string representing a line of pseudocode • if the line is a valid procedure header, returns a string: "P<Module description>" • if the line is a valid function header, returns a string: "F<Module description>" • otherwise, returns an empty string For example, given the string: "FUNCTION Zap(X : INTEGER) RETURNS CHAR" Header()returns the string: "FZap(X : INTEGER) RETURNS CHAR" (a) Write pseudocode for module Header(). ............................................................................................................................................. [7] ,   , (b) A new module is required: Module Description FindModules() • called with a parameter of type string representing a student project file name • uses module Header() to check each line of the project • assigns values to the ModInfo array for each module declaration in the student project As a reminder, the previous example of part of the array is repeated below: x = 1 x = 2 x = 3 ModInfo[10, x] "27" "P" "MyProc(Z : CHAR)" ModInfo[11, x] "35" "F" "MyFun(Y : CHAR) RETURNS BOOLEAN" Write pseudocode for module FindModules(). Assume that the array contains enough rows for the number of modules in each project. ,  , ............................................................................................................................................. [8] ,  , BLANK PAGE ,  , BLANK PAGE ,  , Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity. To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cambridgeinternational.org after the live examination series. BLANK PAGE ,  ,
Show mark scheme
8(a) [8 marks]
Example:
FUNCTION Header(Line : STRING) RETURNS STRING
IF LENGTH(Line) >= 13 THEN
IF TO_UPPER(LEFT(Line, 9)) = "FUNCTION " THEN
RETURN "F" & RIGHT(Line, LENGTH(Line) - 9)
ENDIF
IF TO_UPPER(LEFT(Line, 10)) = "PROCEDURE " THEN
RETURN "P" & RIGHT(Line, LENGTH(Line) - 10)
ENDIF
ENDIF
RETURN ""
ENDFUNCTION
Mark as follows:
1
Function heading, parameter, return type and ending
2
Check that the line is at least 13 characters long before attempting to
extract and return empty string
3
Attempt at: Extract characters, 9 or 10 characters, corresponding to
keyword plus space and compare with appropriate keyword plus space
4
Completely correct MP3
Use of type case conversion to allow for 'any case'
5
6
Calculation of 'rest of line' and concatenation with 'P or 'F'
7
Return string
8(b)
Example:
PROCEDURE FindModules(FileName : STRING)
DECLARE Line : STRING
DECLARE Index, LineNum : INTEGER
OPENFILE FileName FOR READ

Index
1

LineNum
0
WHILE NOT EOF(FileName)
READFILE FileName, Line

LineNum
LineNum + 1

Line
Header(Line)
IF Line <> "" THEN

ModInfo[Index, 1]
NUM_TO_STR(LineNum)

ModInfo[Index, 2]
LEFT(Line, 1)

ModInfo[Index, 3]
RIGHT(Line, LENGTH(Line) -
1)

Index
Index + 1
ENDIF
ENDWHILE
CLOSEFILE FileName
ENDPROCEDURE
Mark as follows:
1
Open file in
mode
and
subsequently close
READ
2
Loop to
EOF(FileName)
3
Read a line from the file and maintain
in
a loop
LineNum
4
Call
and use return value
in a loop
Header()
5
Test return value for ""
in a loop
6
Attempt at all three-array assignment for all columns in correct row
7
Correct values assigned to all columns of array
8
Maintain correct array row index
Q11
May/Jun 2024 Paper 2 v3
Question 11 — page 1Question 11 — page 2Question 11 — page 3Question 11 — page 4Question 11 — page 5
11 BargraphA-11.bmp A procedure Progress() will: • be called with two parameters: ○ an integer representing the percentage progress (0 to 100 inclusive) ○ a string representing the image filename root • generate the full image filename • call a procedure Display() using the full image filename as the parameter. (a) Write pseudocode for procedure Progress(). ............................................................................................................................................. [6] ,  , (b) The definition of procedure Progress() is provided here for reference: A procedure Progress() will: • be called with two parameters: ○ an integer representing the percentage progress (0 to 100 inclusive) ○ a string representing the image filename root • generate the full image filename • call a procedure Display() using the full image filename as the parameter. Progress() will be rewritten and a new module Progress2() produced with these requirements: • an additional parameter of type integer will specify the total number of steps • the image filename will be returned (procedure Display() will not be called from within Progress2()). (i) Write pseudocode for the new module header. ..................................................................................................................................... [2] (ii) State one benefit of increasing the number of steps. ..................................................................................................................................... [1] ,  , BLANK PAGE ,  , ,  ,