Cambridge A Level Computer Science 9608 — 2021 May/June Paper 2 · Variant 3

9608/23/M/J/21 · 75 marks · ≈84 min

The question paper and its mark scheme, free to read here and free to download. This is Cambridge’s own paper, exactly as it was sat.

← All Computer Science papersWhat was in this paper?

Question paper24 pages

Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 1 of 24
Page 1 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 2 of 24
Page 2 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 3 of 24
Page 3 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 4 of 24
Page 4 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 5 of 24
Page 5 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 6 of 24
Page 6 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 7 of 24
Page 7 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 8 of 24
Page 8 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 9 of 24
Page 9 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 10 of 24
Page 10 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 11 of 24
Page 11 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 12 of 24
Page 12 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 13 of 24
Page 13 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 14 of 24
Page 14 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 15 of 24
Page 15 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 16 of 24
Page 16 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 17 of 24
Page 17 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 18 of 24
Page 18 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 19 of 24
Page 19 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 20 of 24
Page 20 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 21 of 24
Page 21 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 22 of 24
Page 22 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 23 of 24
Page 23 of 24
Cambridge A Level Computer Science 9608 2021 May/June Paper 2 · Variant 3 question paper, page 24 of 24
Page 24 of 24

Mark scheme16 pages

Answers below. Sit the paper first if you are practising.

Mark scheme, page 1 of 16
Page 1 of 16
Mark scheme, page 2 of 16
Page 2 of 16
Mark scheme, page 3 of 16
Page 3 of 16
Mark scheme, page 4 of 16
Page 4 of 16
Mark scheme, page 5 of 16
Page 5 of 16
Mark scheme, page 6 of 16
Page 6 of 16
Mark scheme, page 7 of 16
Page 7 of 16
Mark scheme, page 8 of 16
Page 8 of 16
Mark scheme, page 9 of 16
Page 9 of 16
Mark scheme, page 10 of 16
Page 10 of 16
Mark scheme, page 11 of 16
Page 11 of 16
Mark scheme, page 12 of 16
Page 12 of 16
Mark scheme, page 13 of 16
Page 13 of 16
Mark scheme, page 14 of 16
Page 14 of 16
Mark scheme, page 15 of 16
Page 15 of 16
Mark scheme, page 16 of 16
Page 16 of 16

Paper as text

Question paper, page 1

This document has 24 pages. Any blank pages are indicated. Cambridge International AS & A Level DC (PQ/FC) 205019/2 © UCLES 2021 [Turn over * 3 6 5 9 0 7 9 7 1 3 * COMPUTER SCIENCE 9608/23 Paper 2 Fundamental Problem-solving and Programming Skills May/June 2021 2 hours You must answer on the question paper. No additional materials are needed. INSTRUCTIONS ● Answer all questions. ● Use a black or dark blue pen. ● Write your name, centre number and candidate number in the boxes at the top of the page. ● Write your answer to each question in the space provided. ● Do not use an erasable pen or correction fluid. ● Do not write on any bar codes. ● You may use an HB pencil for any diagrams, graphs or rough working. ● Calculators must not be used in this paper. INFORMATION ● The total mark for this paper is 75. ● The number of marks for each question or part question is shown in brackets [ ]. ● No marks will be awarded for using brand names of software packages or hardware.

Question paper, page 2

2 9608/23/M/J/21 © UCLES 2021 1 (a) Algorithms usually consist of three different types of activity. Complete the following table. Write each example statement in program code and state the programming language used. The third activity has already been given. Activity Example statement in program code Programming language OUTPUT [5] (b) An algorithm searches a 1D array to find the first index of an element that contains a given value. If the value is found, the index of that element is returned. (i) State an appropriate loop structure for this algorithm. Justify your choice. Loop structure … Justification … … [2] (ii) Give two possible reasons why the search for the value in part (b)(i) would end. You should assume there is no error. 1 … … 2 … … [2]

Question paper, page 3

3 9608/23/M/J/21 © UCLES 2021 [Turn over (c) Each pseudocode statement in the following table may contain an error due to the incorrect use of the function or operator. Describe the error in each case, or write 'NO ERROR' if the statement contains no error. Refer to the Appendix on pages 22 and 23 for the list of built-in pseudocode functions and operators. Statement Error Code RIGHT("Cap" * 3, 2) Valid IS_NUM(3.14159) NextChar MID(ThisString, Index), 1 [3]

Question paper, page 4

4 9608/23/M/J/21 © UCLES 2021 2 (a) After using a program for some time, a user notices a fault in the program. Describe the term program fault. … … … … [2] (b) Good programming practice may help to avoid faults. The use of sensible identifier names is one example of good practice. (i) Explain the reason for using sensible identifier names. … … [1] (ii) State three other examples of good programming practice. 1 … 2 … 3 … [3] (c) A programmer chooses data to test each path through her program. Identify the type of testing that the programmer has decided to perform. … [1]

Question paper, page 5

5 9608/23/M/J/21 © UCLES 2021 [Turn over 3 (a) The process of decomposition is often applied to a programming problem. Describe the process of decomposition. … … … … … … [2] (b) Result is a 1D array of type STRING. It contains 100 elements. Draw a program flowchart for an algorithm that will output each element in the array. [4]

Question paper, page 6

6 9608/23/M/J/21 © UCLES 2021 (c) The program flowchart for part of an algorithm from a mobile phone program is shown. Identifier Active is a global variable of type BOOLEAN. START END CALL Sync() CALL Reset() CALL Error("No Signal") CALL ReCheck() Set Online to TRUE Set Online to FALSE Is Active = FALSE ? Is Online = FALSE ? Is Active = TRUE ? YES YES YES NO NO NO

Question paper, page 7

7 9608/23/M/J/21 © UCLES 2021 [Turn over Write pseudocode to implement the algorithm represented by the flowchart. … … … … … … … … … … … … … … … … … … … … … [6]

Question paper, page 8

8 9608/23/M/J/21 © UCLES 2021 4 Study the following pseudocode for a string handling function Check(). Refer to the Appendix on pages 22 and 23 for the list of built-in pseudocode functions and operators. FUNCTION Check(InString : STRING) RETURNS INTEGER DECLARE Index, Result, Count : INTEGER DECLARE NextChar : CHAR Result 0 Count 1 FOR Index 1 TO LENGTH(InString) NextChar MID(InString, Index, 1) IF (NextChar >= '0' AND NextChar <= '9') OR NextChar = '.' THEN Result Result + 1 ELSE IF NextChar = ',' THEN Count Count + 1 ELSE Result -1 ENDIF ENDIF ENDFOR IF Count < 3 THEN RETURN -1 ELSE RETURN Result ENDIF ENDFUNCTION

Question paper, page 9

9 9608/23/M/J/21 © UCLES 2021 [Turn over (a) (i) Complete the trace table by performing a dry run of the function when it is called as follows: Answer Check("74.0,4.6,3x2") Note, there are no space characters in the string shown. Result Count Index NextChar [5] (ii) State the value returned by the function when it is called as shown in part (a)(i). … [1]

Question paper, page 10

10 9608/23/M/J/21 © UCLES 2021 (b) A number group is a string of characters that represents an integer or decimal value. A comma separates number groups. For example, "74.0" is a number group in the string "74.0,4.6,3x2". The function Check() is intended to analyse the number groups in the parameter passed. The function returns: • a count of the number groups in the parameter passed or • −1 if there are less than three number groups in the string or if any non-numeric characters occur in the string (other than decimal point and comma). There is an error in the algorithm causing an incorrect value to be returned by the function. (i) Explain why this error can occur. … … … … [2] (ii) Describe how the algorithm could be amended to correct the error. … … … … [1] (c) A dry run of a pseudocode algorithm may help to locate logic errors. Give another type of program error and describe how it can occur. Type of error … Description … … … … [2]

Question paper, page 11

11 9608/23/M/J/21 © UCLES 2021 [Turn over BLANK PAGE

Question paper, page 12

12 9608/23/M/J/21 © UCLES 2021 5 A program stores a contact list of telephone numbers. Each telephone number is stored as a string of six or more numeric characters. Before they are displayed, number strings are formatted to make them easier to read. This involves forming the characters into groups, separated by the space character. The maximum length of a number group is five characters. Different numbers may have different groupings. A template string is used to define the grouping. For example: Number string Template string Formatted string "01223553998" "53" "01223 553 998" "509700101" "222" "50 97 00 101" "4044496128" "33" "404 449 6128" For the first row, template "53" results in a formatted string comprising: • the first five characters in the first group • a space character • the next three characters in the second group • a space character • the remaining characters from the number string. (a) Write pseudocode for a function GroupNum(), which takes a telephone number and a template as parameter strings and returns a formatted string. You may assume that the template and telephone number are valid. Refer to the Appendix on pages 22 and 23 for the list of built-in pseudocode functions and operators. … … … … … … … … … … …

Question paper, page 13

13 9608/23/M/J/21 © UCLES 2021 [Turn over … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … [8]

Question paper, page 14

14 9608/23/M/J/21 © UCLES 2021 (b) The function GroupNum() is to be extended to include parameter checking. State one check that could be applied to each parameter. Give an example of test data that could be used to demonstrate that each check identifies invalid data. The type of check must be different for each parameter. Telephone number check … … … … Test data … Template check … … … … Test data … [4]

Question paper, page 15

15 9608/23/M/J/21 © UCLES 2021 [Turn over BLANK PAGE

Question paper, page 16

16 9608/23/M/J/21 © UCLES 2021 6 A program stores data about stock items in four global 1D arrays as follows: Array Data type Description Example data value Initial data value StockID STRING the stock item ID (eight alpha-numeric characters) "ABLK0001" "" Description STRING a description of the item (alphabetic characters only) "torch" "" Quantity INTEGER the number in stock 6 0 Cost REAL the cost of the item 4.80 0.0 • Each array contains 10 000 elements. • Elements with the same index relate to the same stock item. For example, StockID[5] contains the ID for the product whose description is in Description[5]. • The StockID array is not sorted and unused elements may occur at any index position. • Unused elements are assigned the initial data value shown in the table above. • The first four characters of the StockID represent a product group. The last four characters represent the item within the group. The program is to be modified so that: • data from the arrays are stored in a text file for backup purposes. Data from unused elements are not stored in the file. • a Summary array is added. This will be a global 1D array of 500 elements of type STRING. Each product group will occur once in the array, for example "ABLK" for the item in the table above. The programmer has started to define program modules as follows: Module Description GetValidFilename() • prompts and inputs a filename • returns a valid filename as a STRING CheckBackupFile() • calls GetValidFilename() for a filename • checks if the file is empty • If the file is not empty ask the user to confirm that overwrite is intended. If not intended allow the user to re-input a different filename. • returns the filename.

Question paper, page 17

17 9608/23/M/J/21 © UCLES 2021 [Turn over (a) Write pseudocode for the module CheckBackupFile(). … … … … … … … … … … … … … … … … … … … … … … … … … … … … [8]

Question paper, page 18

18 9608/23/M/J/21 © UCLES 2021 (b) Write program code for a module GroupReport(), which will summarise the stock data for a given product group. The product group will be passed to the module as a string. The total value of items is calculated by multiplying the cost by the quantity. An example of the output for group ABLK is as follows: Group: ABLK Number of items in Group: 11 Total value of items in Group: 387.89 If no items are found for group ABLK, the output is as follows: There are no items in Group: ABLK Visual Basic and Pascal: You should include the declaration statements for variables. Python: You should show a comment statement for each variable used with its data type. Programming language … Program code … … … … … … … … … … … … … … … … …

Question paper, page 19

19 9608/23/M/J/21 © UCLES 2021 [Turn over … … … … … … … … … … [6]

Question paper, page 20

20 9608/23/M/J/21 © UCLES 2021 (c) Two additional modules are required: Module Description Lookup() • called with a STRING representing a product group (for example, "ABLK") • searches the Summary array for the group • returns the index position or returns −1 if not found GroupSummary() • stores each product group name (found in the StockID array) into the Summary array, if not there already • calls Lookup() to check whether the name is already in the Summary array • returns the number of product groups added to the Summary array You can assume: • all elements of the Summary array have been initialised to the value "" before GroupSummary() is called • there will be no more than 500 product groups. Write program code for the module GroupSummary(). Visual Basic and Pascal: You should include the declaration statements for variables. Python: You should show a comment statement for each variable used with its data type. Programming language … Program code … … … … … … … … … … … …

Question paper, page 21

21 9608/23/M/J/21 © UCLES 2021 … … … … … … … … … … … … … … [7]

Question paper, page 22

22 9608/23/M/J/21 © UCLES 2021 Appendix Built-in functions (pseudocode) Each function returns an error if the function call is not properly formed. MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING returns a string of length y starting at position x from ThisString Example: MID("ABCDEFGH", 2, 3) returns "BCD" LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of ThisString Example: LENGTH("Happy Days") returns 10 LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING returns leftmost x characters from ThisString Example: LEFT("ABCDEFGH", 3) returns "ABC" RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING returns rightmost x characters from ThisString Example: RIGHT("ABCDEFGH", 3) returns "FGH" INT(x : REAL) RETURNS INTEGER returns the integer part of x Example: INT(27.5415) returns 27 NUM_TO_STRING(x : REAL) RETURNS STRING returns a string representation of a numeric value. Note: This function will also work if x is of type INTEGER Example: NUM_TO_STRING(87.5) returns "87.5" STRING_TO_NUM(x : STRING) RETURNS REAL returns a numeric representation of a string. Note: This function will also work if x is of type CHAR Example: STRING_TO_NUM("23.45") returns 23.45 IS_NUM(ThisString : STRING) RETURNS BOOLEAN returns the value TRUE if ThisString contains only numeric characters ('0' to '9'). Example: IS_NUM("123a") returns FALSE

Question paper, page 23

23 9608/23/M/J/21 © UCLES 2021 Operators (pseudocode) Operator Description & Concatenates (joins) two strings Example: "Summer" & " " & "Pudding" produces "Summer Pudding" AND Performs a logical AND on two Boolean values Example: TRUE AND FALSE produces FALSE OR Performs a logical OR on two Boolean values Example: TRUE OR FALSE produces TRUE

Question paper, page 24

24 9608/23/M/J/21 © UCLES 2021 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 the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge. BLANK PAGE

Mark scheme, page 1

This document consists of 16 printed pages. © UCLES 2021 [Turn over Cambridge International AS & A Level COMPUTER SCIENCE 9608/23 Paper 2 Fundamental Problem-solving and Programming Skills May/June 2021 MARK SCHEME Maximum Mark: 75 Published This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the details of the discussions that took place at an Examiners’ meeting before marking began, which would have considered the acceptability of alternative answers. Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for Teachers. Cambridge International will not enter into discussions about these mark schemes. Cambridge International is publishing the mark schemes for the May/June 2021 series for most Cambridge IGCSE™, Cambridge International A and AS Level components and some Cambridge O Level components.

Mark scheme, page 2

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 2 of 16 Generic Marking Principles These general marking principles must be applied by all examiners when marking candidate answers. They should be applied alongside the specific content of the mark scheme or generic level descriptors for a question. Each question paper and mark scheme will also comply with these marking principles. GENERIC MARKING PRINCIPLE 1: Marks must be awarded in line with: • the specific content of the mark scheme or the generic level descriptors for the question • the specific skills defined in the mark scheme or in the generic level descriptors for the question • the standard of response required by a candidate as exemplified by the standardisation scripts. GENERIC MARKING PRINCIPLE 2: Marks awarded are always whole marks (not half marks, or other fractions). GENERIC MARKING PRINCIPLE 3: Marks must be awarded positively: • marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit is given for valid answers which go beyond the scope of the syllabus and mark scheme, referring to your Team Leader as appropriate • marks are awarded when candidates clearly demonstrate what they know and can do • marks are not deducted for errors • marks are not deducted for omissions • answers should only be judged on the quality of spelling, punctuation and grammar when these features are specifically assessed by the question as indicated by the mark scheme. The meaning, however, should be unambiguous. GENERIC MARKING PRINCIPLE 4: Rules must be applied consistently, e.g. in situations where candidates have not followed instructions or in the application of generic level descriptors. GENERIC MARKING PRINCIPLE 5: Marks should be awarded using the full range of marks defined in the mark scheme for the question (however; the use of the full mark range may be limited according to the quality of the candidate responses seen). GENERIC MARKING PRINCIPLE 6: Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should not be awarded with grade thresholds or grade descriptors in mind.

Mark scheme, page 3

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 3 of 16 Question Answer Marks 1(a) One mark per bullet point. • INPUT • Example input statement in language stated • PROCESS • Example process statement in language stated • Example OUTPUT statement in language stated 5 1(b)(i) One mark per bullet point. • conditional loop • the number of iterations is not known 2 1(b)(ii) One mark per bullet point. • the value is found • the end of the array is reached (and value not found) 2 1(c) One mark for each row Statement Error Code ← RIGHT("Cap" * 3, 2) Cannot multiply a string (by 3) Valid ← IS_NUM(3.14159) Parameter should be a string NextChar ← MID(ThisString, Index), 1 Closing bracket in wrong place 3 Question Answer Marks 2(a) • (A program fault is) when the program does not do what it is supposed to do / expected to do • … under certain circumstances One mark per point or equivalent 2 2(b)(i) Makes it easier to understand the purpose of each identifier / what the identifier is used for / the purpose of the program 1

Mark scheme, page 4

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 4 of 16 Question Answer Marks 2(b)(ii) One mark per point: 1 The use of modular programming (to avoid repeated code) 2 The use of library / tried and tested subroutines 3 Good formatting to make the code easier to read (indentation, white space) 4 Use of local variables 5 Use of constants 6 Use of comments to explain functionality of code Max 3 marks 3 2(c) One mark per point: • white box • dry-run testing / use of trace table / walk through Max 1 mark 1 Question Answer Marks 3(a) • To break the problem down into sub-tasks • where each sub-task can be implemented by a program module / is easier to solve. One mark for each phrase (or equivalent) 2

Mark scheme, page 5

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 5 of 16 Question Answer Marks 3(b) 1 mark for each of the following: 1 Initialise Index 2 Test index for 100 elements 3 End when 100 elements output 4 Output, increment and repeat 4 Is Index = 101 ? END START Set Index to Index + 1 NO Set Index to 1 OUTPUT Result[Index] YES

Mark scheme, page 6

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 6 of 16 Question Answer Marks 3(c) OnLine ← FALSE WHILE Online = FALSE IF Active = TRUE THEN Call Sync() ELSE Call Reset() IF Active = FALSE THEN Call Error("No Signal") ELSE Online ← TRUE ENDIF ENDIF Call ReCheck() ENDWHILE 1 mark for each of the following: 1 Initialise Online 2 WHILE .. ENDWHILE loop, terminated when Online = TRUE 3 IF Active = TRUE THEN .. ELSE .. ENDIF 4 Nested IF Active = FALSE THEN .. ELSE .. ENDIF 5 Call Sync() and Call Reset()and Call Error() and assignment to Online in appropriate place in pseudocode 6 Final call to ReCheck()in appropriate place 6

Mark scheme, page 7

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 7 of 16 Question Answer Marks 4(a)(i) Result Count Index NextChar 0 1 1 1 ‘7’ 2 2 ‘4’ 3 3 ‘.’ 4 4 ‘0’ 5 ‘,’ 2 5 6 ‘4’ 6 7 ‘.’ 7 8 ‘6’ 9 ‘,’ 3 8 10 ‘3’ -1 11 ‘x’ 0 12 ‘2’ Note: One mark per region indicated If no marks by zone then mark by column (max 3) Values in column 4 must be in quotes 5 4(a)(ii) 0 (zero) Allow FT from final value in ‘Result’ column 1

Mark scheme, page 8

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 8 of 16 Question Answer Marks 4(b)(i) Final IN ... ENDIF errors: • Test needs to check Count AND Result • Returns Result instead of Count OR FOR loop error: • The loop continues after the illegal character is detected • So the error condition (Result = -1) can be lost 2 4(b)(ii) • Change RETURN Result to RETURN Count • Change final if to IF Count < 3 and Result <> -1 • Terminate the loop as soon as an illegal character is encountered Max 1 mark 1 4(c) • Syntax error • Rules of the language are not followed OR • Run-time error • Program performs an illegal operation or enters an infinite loop 2

Mark scheme, page 9

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 9 of 16 Question Answer Marks 5(a) FUNCTION GroupNum(TelNum, Template : STRING) RETURNS STRING DECLARE FString : STRING DECLARE Index, ThisDigit, ThisGroup : INTEGER CONSTANT SPACE = ‘ ‘ FString ← "" ThisDigit ← 1 FOR Index ← 1 TO LENGTH(Template) ThisGroup ← STRING_TO_NUM(MID(Template, Index, 1)) FString ← FString & MID(TelNum, ThisDigit, ThisGroup) FString ← FString & SPACE ThisDigit ← ThisDigit + ThisGroup ENDFOR FString ← FString & RIGHT(TelNum, LENGTH(TelNum) – ThisDigit) RETURN FString ENDFUNCTION Mark as follows: 1 Function header and end including parameters and RETURN type 2 Local variable declaration and initialisation of FString (return string) 3 Loop to go through each char of Template (each group) 4 Extract character from template in a loop 5 Use of STRING_TO_NUM()on extracted character in a loop 6 Substring statement to pick up current group from TelNum and concatenate with FString in a loop 7 Concatenate SPACE separator in a loop 8 Concatenate final characters from TelNum after the loop (+ or – 1 characters) 9 Return the formatted string after reasonable attempt Max 8 Max 7 for not fully working solutions 8

Mark scheme, page 10

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 10 of 16 Question Answer Marks 5(b) One mark for check plus one for corresponding test data example. Test data must be invalid to prove that the check is working. Telephone number: • Length check // Check that the telephone number string is at least six characters e.g. number of "127" OR • Check it is a number // Check that the telephone number string only contains characters from ‘0’ to ‘9’ e.g. number of "12A" Template: • Check it is a number in range 1 to 5 //Check that the template string only contains characters from ‘1’ to ‘5’ e.g. template of "127" OR • Check that there are enough characters in the TelNum string so that the template can be applied e.g. Telnum = "123456", Template = "66" 4

Mark scheme, page 11

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 11 of 16 Question Answer Marks 6(a) FUNCTION CheckBackupFile() RETURNS STRING DECLARE Filename, FileLine, Response : STRING Filename ← "" WHILE Filename = "" Filename ← GetValidFilename() OPENFILE Filename FOR READ READFILE Filename, FileLine CLOSEFILE Filename IF FileLine <> "" //check if data in file THEN OUTPUT "File already exists – do you want to overwrite? " INPUT Response IF Response <> "Yes" THEN Filename ← "" OUTPUT "Please input a different filename " ENDIF ENDIF ENDWHILE RETURN Filename ENDFUNCTION One mark for each of the following: 1 Conditional loop 2 Use of GetValidFilename()in a loop 3 OPEN file in READ mode and CLOSE in a loop 4 Test if file not empty (using EOF() or READ empty string) 5 If not empty, prompt and input (in case of a non-empty file) in a loop 6 …. and process response 7 Set loop termination condition by checking for new file or overwrite confirmed in a loop 8 Return Filename 8

Mark scheme, page 12

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 12 of 16 Question Answer Marks 6(b) ‘Pseudocode’ solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix PROCEDURE GroupReport(Group : STRING) DECLARE Total : REAL DECLARE Count, Index : INTEGER Total ← 0 Count ← 0 FOR Index ← 1 TO 10000 IF LEFT(StockID[Index], 4) = Group THEN Count ← Count + 1 Total ← Total + (Quantity[Index] * Cost[Index]) ENDIF ENDFOR IF Count = 0 THEN OUTPUT "There are no items in Group: ", Group ELSE OUTPUT "Group: ", Group OUTPUT "Number of items in Group: ", Count OUTPUT "Total value of items in Group: ", Total ENDIF ENDPROCEDURE 1 mark for each of the following: 1 Procedure heading and ending including input parameter 2 Declare and initialise local variables for Total and Count 3 Loop through all 10 000 elements (allow LEN(StockID) 4 Check for required group using substring function in a loop 5 ...Increment Count and sum Total using correct array notation 6 Generate both sets of output as appropriate after loop 6

Mark scheme, page 13

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 13 of 16 Question Answer Marks 6(c) ‘Pseudocode’ solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix FUNCTION GroupSummary() RETURNS INTEGER DECLARE Index, GroupIndex Total : INTEGER DECLARE ThisGroup : STRING Total ← 0 FOR Index ← 1 TO 10000 IF StockID[Index] <> "" THEN ThisGroup ← LEFT(StockID[Index], 4) GroupIndex ← Lookup(ThisGroup) IF GroupIndex = -1 //ThisGroup not found THEN //add new group Summary[Total + 1] ← ThisGroup Total ← Total + 1 ENDIF ENDIF ENDFOR RETURN Total ENDFUNCTION 1 mark for each of the following: 1 Function heading and ending and final return of Total 2 Declare and initialise Total 3 Loop through all 10 000 elements 4 Skip empty StockID in a loop 5 Extract ThisGroup from StockID and pass to Lookup() 6 … if Lookup() returns −1 (following reasonable attempt at MP5) 7 …….Store ThisGroup to Summary[Total] and increment Total 7

Mark scheme, page 14

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 14 of 16 Program Code Example Solutions Question 6(b): Visual Basic Sub GroupReport(Group As String) Dim Total As Double Dim Count, Index As Integer Total = 0 Count = 0 For Index = 0 To 3 ‘1 to 10000 If Left(StockID(Index), 4) = Group Then Count = Count + 1 Total = Total + (Quantity(Index) * Cost(Index)) End If Next Index If Count = 0 Then Console.WriteLine("There are no items in Group: " & Group) Else Console.WriteLine("Group: " & Group) Console.WriteLine("Number of items in Group: " & Count) Console.WriteLine("Total value of items in Group: " & Total) End If End Sub Question 6(b): Pascal procedure GroupReport(Group : string); var Total : real; Count, Index : integer; begin Total := 0; Count := 0; for Index := 1 TO 10000 do begin if LeftStr(StockID[Index], 4) = Group then begin Count := Count + 1; Total := Total + (Quantity[Index] * Cost[Index]); end; end; if Count = 0 then writeLn(‘There are no items in Group: ‘, Group) else begin writeLn(‘Group: ‘, Group); writeLn(‘Number of items in Group: ‘, Count); writeLn(‘Total value of items in Group: ‘, Total); end; end;

Mark scheme, page 15

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 15 of 16 Question 6(b): Python def GroupReport(Group): ## Total As Real ## Count, Index As Integer ## ThisID As String Total = 0 Count = 0 for Index in range(1, 10001): ThisID = StockID[Index] if ThisID[:4] == Group: Count = Count + 1 Total = Total + (Quantity[Index] * Cost[Index]) if Count == 0: print("There are no items in Group: ", Group) else: print("Group: ", Group) print("Number of items in Group: ", Count) print("Total value of items in Group: ", Total) Question 6(c): Visual Basic Function GroupSummary() As Integer Dim Index, GroupIndex, Total As Integer Dim ThisGroup As String Total = 0 For Index = 1 TO 10000 If StockID(Index) <> "" Then ThisGroup = Left(StockID(Index), 4) GroupIndex = Lookup(ThisGroup) If GroupIndex = -1 Then // ThisGroup not found Summary(Total + 1) = ThisGroup // Add new Group Total = Total + 1 End If End If Next Index Return Total End Function

Mark scheme, page 16

9608/23 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 16 of 16 Question 6(c): Pascal function GroupSummary() : Integer; var Index, GroupIndex, Total : Integer; ThisGroup : String; begin Total := 0; for Index := 1 TO 10000 do begin if StockID[Index] <> "" then begin ThisGroup := LeftStr(StockID[Index], 4); GroupIndex := Lookup(ThisGroup); If GroupIndex = -1 then //ThisGroup not found begin Summary[Total + 1] := ThisGroup; //Add new Group Total := Total + 1; end; end; end; GroupSummary := Total; // result := Total; end; Question 6(c): Python def GroupSummary(): ## Index, GroupIndex, Total As Integer ## ThisGroup, ThisID As String Total = 0 for Index in range(1, 10001): ThisID = StockID[Index] if ThisID != "": ThisGroup = ThisId[:4] GroupIndex = Lookup(ThisGroup) if GroupIndex == -1: #ThisGroup not found Summary[Total + 1] = ThisGroup #Add new Group Total = Total + 1 return Total

What you needed in this session

Cambridge’s own grade thresholds for 2021 May/June, Paper 2 · Variant 3. A higher threshold means an easier paper — the bar moves with how the cohort did.

A43/75
B35/75
C28/75
D21/75
E14/75