Cambridge A Level Computer Science 9608 — 2021 May/June Paper 2 · Variant 2
9608/22/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.
Question paper20 pages




















Mark scheme20 pages
Answers below. Sit the paper first if you are practising.




















Paper as text
Question paper, page 1
This document has 20 pages. Any blank pages are indicated. Cambridge International AS & A Level COMPUTER SCIENCE 9608/22 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. * 8 3 0 3 8 3 5 5 8 0 * DC (CJ) 205021/2 © UCLES 2021 [Turn over
Question paper, page 2
2 9608/22/M/J/21 © UCLES 2021 BLANK PAGE
Question paper, page 3
3 9608/22/M/J/21 © UCLES 2021 [Turn over 1 (a) Maintenance of programs may be needed for a number of different reasons. State two types of maintenance and give a reason why each may be needed. Type … Reason … … Type … Reason … … [4] (b) State why characters need to be represented in ASCII or Unicode before they can be processed. … … [1] (c) Each line of a text file contains several data items. A special character is inserted between data items before the line is written to the file. Explain why a special character is used in this way. … … … … [2] (d) 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 page 18 for the list of built-in pseudocode functions and operators. Statement Error Code RIGHT("Cap" & "art", 4) Status MID("Computer", 7, 5) Size LENGTH("Password") * 2 NextChar CHR('A') Index Index & 3 [5]
Question paper, page 4
4 9608/22/M/J/21 © UCLES 2021 2 Study the following pseudocode. DECLARE Overload : BOOLEAN PROCEDURE LEM() DECLARE Status : BOOLEAN DECLARE Landed : INTEGER Overload FALSE Landed FALSE WHILE Landed = FALSE Status Sample() IF Status = TRUE THEN Landed SubA(42) ELSE Overload SubB(37) IF Overload = TRUE THEN CALL Display("Alarm 1202") ENDIF ENDIF ENDWHILE ENDPROCEDURE (a) Examine the pseudocode and complete the following table: Answer The identifier name of a global variable The name of the loop structure The identifier involved in a data type mismatch The name of a procedure that takes a parameter The name of a function [5]
Question paper, page 5
5 9608/22/M/J/21 © UCLES 2021 [Turn over (b) Draw a program flowchart to represent the pseudocode algorithm. Variable declarations are not required in program flowcharts. [5]
Question paper, page 6
6 9608/22/M/J/21 © UCLES 2021 3 (a) (i) Module names and parameters are features that may be represented on a structure chart. State two other features than can be represented on a structure chart. Feature 1 … Feature 2 … [2] (ii) The headers for three modules in a program are defined in pseudocode as follows: Pseudocode module header PROCEDURE Create(S2 : INTEGER, P3 : STRING) PROCEDURE Modify(S2 : INTEGER, BYREF P4 : STRING) FUNCTION Delete(P4 : INTEGER, M4 : STRING) RETURNS INTEGER A fourth module, Membership(), may call any one of the three modules. Draw a structure chart to represent the information given about the four modules. [5]
Question paper, page 7
7 9608/22/M/J/21 © UCLES 2021 [Turn over (b) Draw a diagram to show the stages of the program development cycle. Use arrows to indicate how the stages are linked. [2]
Question paper, page 8
8 9608/22/M/J/21 © UCLES 2021 4 (a) Using pseudocode, write a post-condition loop to output every odd number between 100 and 200. … … … … … … … … … … … [4] (b) A program contains a global 2D array XRef. The array consists of 100 rows and 3 columns. The array is of data type STRING. A function, Search(), takes two parameters Par1 and Par2 as string values and returns an integer value. The function returns: • the index number of the first row where: • the element in column 1 of that row matches Par1 and • either of the other two elements in that row match Par2 • –1 if no match found in any row.
Question paper, page 9
9 9608/22/M/J/21 © UCLES 2021 [Turn over Write program code for the function Search(). 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 … … … … … … … … … … … … … … … … … … … … … … … … [7]
Question paper, page 10
10 9608/22/M/J/21 © UCLES 2021 5 (a) An Integrated Development Environment (IDE) will be used to develop a program. (i) An IDE includes features for program presentation. State two of these presentation features. Feature 1 … … Feature 2 … … [2] (ii) Name two IDE features that can help with initial error detection. Feature 1 … … Feature 2 … … [2] (b) (i) A function, Verify(), is written in pseudocode. Write the two missing lines to complete the pseudocode. FUNCTION Verify(UserID : STRING) RETURNS BOOLEAN … DECLARE Password : STRING OUTPUT "Please Input your password: " INPUT Password Response Validate(UserID, Password) AND Today() … ENDFUNCTION [2]
Question paper, page 11
11 9608/22/M/J/21 © UCLES 2021 [Turn over (ii) The function, Verify(), is to be amended as follows: • if the UserID is "Guest", a password is not required and TRUE should be returned • output a message to try again if the password entered is not valid • return FALSE if the number of attempts to enter a valid password exceeds three. Write program code for the amended function Verify(). 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 … … … … … … … … … … … … … … … … … … … … … … [6]
Question paper, page 12
12 9608/22/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) "JBCD0002" "" Description STRING a description of the item (alphabetic characters only) "soap" "" Quantity INTEGER the number in stock 9 0 Cost REAL the cost of the item 1.45 0.0 • Each array contains 10 000 elements. • Elements with the same index relate to the same stock item. For example, StockID[3] contains the ID for the product whose description is in Description[3]. • The StockID array is not sorted. The program will be modified so that the data from the arrays can be stored in a text file for backup. You may assume that a backup file contains only valid stock data. The programmer has started to define program modules as follows: Module Description Unpack() • called with two parameters: • an array index • a string value read from one line of the backup file • extracts the four data values from the string and assigns each to the appropriate array Restore() • called with a string representing the name of a backup file • returns FALSE if the file is empty • sets all elements of each array to the initial data value as given in the table • reads the backup file line by line calls Unpack() to extract data from each line and assign values to the corresponding arrays • returns FALSE if the arrays are full but there are still lines in the file, otherwise returns TRUE StockSummary() For all items where StockID does not contain the initial value: • counts the number of stock entries in the StockID array • outputs the overall value of all items in stock (cost multiplied by the quantity) • outputs the number of stock entries
Question paper, page 13
13 9608/22/M/J/21 © UCLES 2021 [Turn over (a) Write program code for the module StockSummary(). 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 … … … … … … … … … … … … … … … … … … … … [5]
Question paper, page 14
14 9608/22/M/J/21 © UCLES 2021 (b) Write pseudocode for the module Restore(). … … … … … … … … … … … … … … … … … … … … … … … … … … …
Question paper, page 15
15 9608/22/M/J/21 © UCLES 2021 [Turn over … … … … … … … … … [8]
Question paper, page 16
16 9608/22/M/J/21 © UCLES 2021 (c) The module description of GetValidFilename() is as follows: Module Description GetValidFilename() • prompts and inputs a filename • validates the filename by checking that it: • is between 4 and 10 characters in length (inclusive) • contains only alphanumeric characters • if the filename is invalid, outputs a warning message and asks the user to try again • otherwise returns the valid filename Write program code for the module GetValidFilename(). 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 17
17 9608/22/M/J/21 © UCLES 2021 … … … … … … … … … … … … … … … … … … … … … … … … … [8]
Question paper, page 18
18 9608/22/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 LCASE(ThisChar : CHAR) RETURNS CHAR returns the character value representing the lower case equivalent of ThisChar If ThisChar is not an upper case alphabetic character, it is returned unchanged. Example: LCASE('W') returns 'w' ASC(ThisChar : CHAR) RETURNS INTEGER returns the ASCII value of character ThisChar Example: ASC('A') returns 65 CHR(x : INTEGER) RETURNS CHAR returns the character whose ASCII value is x Example: CHR(87) returns 'W' 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 19
19 9608/22/M/J/21 © UCLES 2021 BLANK PAGE
Question paper, page 20
20 9608/22/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 20 printed pages. © UCLES 2021 [Turn over Cambridge International AS & A Level COMPUTER SCIENCE 9608/22 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/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 2 of 20 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/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 3 of 20 Mechanics of Marking: Every mark given should have a corresponding tick on the script. Every part question must be annotated to show that it has been read. There are four pages that appear at the start of the script (including the Appendix page) that must be annotated with the SEEN icon. The easiest way to do this is to go the first question and select Zoom > ‘fit height’ then all six can be annotated at the same time without scrolling. Do not put comments on the scripts. When scripts are returned to centres all the annotations including comments, are visible. If work has been crossed out and something written in its place, the replacement work is marked even if the crossed-out work is correct. If the crossed-out work has not been replaced, mark the crossed- out answer. For single mark answers, mark the first answer on the line, unless there is a note to the contrary on the mark scheme. If a candidate writes something that is not enough (NE) for a mark, but is not actually incorrect, continue reading, even if the mark scheme says, for example, mark first two answers. The use of NR (No Response) is described in this extract from the RM Assessor guide: For questions requiring program code, if the only thing that is written is the name of the program language then award NE. Annotation requirement for multi-page responses: Question 6(b) and Question 6(c) In each case, if the second page of the response (page 15 and page 17 respectively) is blank then add the annotation ‘SEEN’ to the second page.
Mark scheme, page 4
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 4 of 20 Question Answer Marks 1(a) One mark for each type and one mark for corresponding reason (not dependant) Type: Corrective Reason: Because the program does not function as intended / contains a bug Type: Adaptive Reason: Change the program due to a requirement / specification / legislative change Type: Perfective Reason: Improve the performance of the program / to enhance the program Type: Preventive Reason: Improve maintainability or reliability 4 1(b) One mark for: • Program / computer / CPU can only process / store binary values. • Standard encoding recognised by all programs / used to exchange information Note: Max 1 mark 1 1(c) One mark per bullet point: • To provide a separator (or implied) between the data items • Algorithm to extract / locate individual items from a line of text is simplified • The special character does not appear in the data Note: Max 2 marks 2
Mark scheme, page 5
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 5 of 20 Question Answer Marks 1(d) Statement Error Code ← RIGHT("Cap" & "art", 4) NO ERROR Status ← MID("Computer", 7, 5) Not enough characters Size ← LENGTH("Password") * 2 NO ERROR NextChar ← CHR('A') CHR() param should be integer // CHR() should be ASC() Index ← Index & 3 3 is not character (should be ‘3’) // and is not an arithmetic operator One mark for each line 5 Question Answer Marks 2(a) Answer The identifier name of a global variable Overload The name of the loop structure Pre-condition loop The identifier involved in a type mismatch Landed The name of a procedure that takes a parameter Display() The name of a function Sample() // SubA() // SubB() One mark per row 5
Mark scheme, page 6
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 6 of 20 Question Answer Marks 2(b) 5
Mark scheme, page 7
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 7 of 20 Question Answer Marks 3(a)(i) One mark for each: Module... • Hierarchy / relationships • Selection • Repetition / Iteration • Sequence Note: Max 2 marks 2 3(a)(ii) One mark for each of: 1 Diagram with all boxes correctly labelled, positioned as shown 2 Selection diamond as shown 3 (P3 and S2) and (P4 and M4) (Parameters to Create and Delete) 4 S2 and P4 (double arrow) (Parameters to Modify) 5 Return parameter from Delete() 5
Mark scheme, page 8
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 8 of 20 Question Answer Marks 3(b) One mark for: • Design, Coding and Testing (in sequence) • Arrows as shown // Alternative 'waterfall model' where each stage loops back to the previous stage 2 Question Answer Marks 4(a) DECLARE Num : INTEGER Num ← 101 REPEAT OUTPUT Num Num ← Num + 2 UNTIL Num > 199 Mark as follows: 1 Counter declaration and initialisation to sensible value before the loop 2 REPEAT ... UNTIL <condition> 3 Correct selection of number to be output (use of MOD() or +2 or other) 4 Correct range of numbers output 4 Design Coding Testing
Mark scheme, page 9
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 9 of 20 Question Answer Marks 4(b) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. FUNCTION Search(Par1, Par2 : STRING) RETURNS INTEGER DECLARE Index, RetVal : INTEGER Index ← 1 RetVal ← -1 WHILE Index <= 100 AND RetVal = -1 IF XRef[Index, 1] = Par1 _ AND (XRef[Index, 2] = Par2 OR XRef[Index, 3] = Par2) THEN RetVal ← Index ENDIF Index ← Index + 1 ENDWHILE RETURN RetVal ENDFUNCTION Mark as follows: 1 Function heading and ending including parameters 2 Declaration of local variable for array index (Index) but not of global XRef array 3 Any loop for 100 elements 4 Use of correct XRef 2D array syntax in a loop 5 Logical test of array elements in a loop 6 Exit loop if match found (following attempt at MP5) Return index number or −1 if not found 7 Question Answer Marks 5(a)(i) One mark per point: • Pretty print / Colour-coding of keywords / variables • (Auto) indentation • (Auto) Expansion / collapsing of data structures / code blocks // thumbnail overview Max 2 marks 2 5(a)(ii) One mark per point: • Dynamic syntax checking / highlighting syntax errors as code is typed • Type checking • Checking for used variables not declared / unused variables which are declared Max 2 marks 2
Mark scheme, page 10
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 10 of 20 Question Answer Marks 5(b)(i) DECLARE Response : BOOLEAN DECLARE Password : STRING OUTPUT "Please Input your password: " INPUT Password Response ←Validate(UserID, Password) AND Today() RETURN Response One mark per line in bold 2 5(b)(ii) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. FUNCTION Verify(UserID : STRING) RETURNS BOOLEAN DECLARE Count : INTEGER DECLARE Response : BOOLEAN DECLARE Password : STRING Count ← 1 Response ← FALSE IF UserID = "Guest" THEN Response ← TRUE ENDIF WHILE Response = FALSE AND Count < 4 OUTPUT "Please input your password: " INPUT Password Response ← Validate(UserID, Password) AND TODAY() IF Response = FALSE THEN IF Count < 3 THEN OUTPUT "Incorrect password – please try again" ENDIF Count ← Count + 1 ENDIF ENDWHILE RETURN Response ENDFUNCTION 1 mark for each of the following: 1 If parameter matches "Guest" then skip to Return (MP7) 2 Loop for max 3 attempts and terminate if valid password input 3 Prompt and Input first password attempt 4 Evaluate result of Validate() AND TODAY() in a loop... 5 Test result and increment count for incorrect password in a loop... 6 ...output 'try again' message and re-input password in a loop... 7 Return Boolean (correctly in all 3 cases) Note: Max 6 marks 6
Mark scheme, page 11
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 11 of 20 Question Answer Marks 6(a) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. PROCEDURE StockSummary() DECLARE Index, Count : INTEGER DECLARE Total : REAL Count ← 0 Total ← 0.0 FOR Index ← 1 TO 10000 IF StockID[Index]) <> "" THEN Count ← Count + 1 Total ← Total + (Quantity[Index] * Cost[Index]) ENDIF ENDFOR OUTPUT "Total Value is ", Total OUTPUT "Number of Stock Entries is ", Count ENDPROCEDURE One mark for each of the following: 1 Declaration and initialisation of Count and Total (by comment in Python) 2 Loop for 10000 elements 3 Skip row when StockID element = "" in a loop 4 Increment Count and sum Total in a loop 5 OUTPUT the total and the count after the loop (following a reasonable attempt at MP4) 5
Mark scheme, page 12
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 12 of 20 Question Answer Marks 6(b) FUNCTION Restore(Filename : STRING) RETURNS BOOLEAN DECLARE Index : INTEGER DECLARE FileLine : STRING DECLARE Success : BOOLEAN Success ← TRUE OPENFILE Filename FOR READ READFILE Filename, FileLine IF FileLine = "" THEN //alt: IF EOF(filename) CLOSEFILE Filename RETURN FALSE //file is empty ENDIF FOR Index ← 1 TO 10000 //first initialise arrays StockID[Index] ← "" Description[Index] ← "" Quantity[Index] ← 0 Cost[Index] ← 0.0 // 0 ENDFOR Index ← 1 //starts loop with first FileLine WHILE NOT EOF(Filename) AND Index <= 10000 CALL Unpack(Index, FileLine) Index ← Index + 1 READFILE Filename, FileLine ENDWHILE IF Index = 10001 AND NOT EOF(Filename) THEN Success ← FALSE ENDIF CLOSEFILE Filename RETURN Success ENDFUNCTION 1 mark for each of the following: 1 Function heading including input parameter and function End 2 Declare local variable for line read from file 3 OPEN file in READ mode and CLOSE 4 Check whether file is empty and return FALSE if it is (no restore 5 Loop through all 10 000 elements initialising arrays 6 Loop until EOF(Filename) OR Index > 10000 7 Call Unpack() correctly for each line from the file in a loop 8 Return FALSE if more than 10000 lines in file, otherwise returns TRUE 8
Mark scheme, page 13
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 13 of 20 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 GetValidFilename() RETURNS STRING DECLARE Filename : STRING DECLARE Valid : BOOLEAN DECLARE Index : INTEGER DECLARE NextChar : CHAR REPEAT Valid ← TRUE OUTPUT "Please input the name for the backup file " INPUT Filename IF LENGTH(Filename) < 4 OR LENGTH(Filename) > 10 THEN Valid ← FALSE ELSE Index ← 1 WHILE Index <= LENGTH(Filename) AND Valid = TRUE NextChar ← MID(Filename, Index, 1) IF NOT ((NextChar >='a' AND NextChar <='z') OR (NextChar >='A' AND NextChar <='Z') OR (NextChar >='0' AND NextChar <='9')) THEN Valid ← FALSE //not alphanumeric ENDIF Index ← Index + 1 ENDWHILE ENDIF IF Valid = FALSE THEN OUTPUT "Invalid filename – please try again" ENDIF UNTIL Valid = TRUE RETURN Filename ENDFUNCTION One mark for each of the following: 1 Conditional loop until valid filename input 2 Prompt and Input of filename in a loop 3 Test length is within range 4 Loop through filename: 5 Extract a single character 6 Test that character is numeric in a loop 7 Test that character is alphabetic in a loop 8 If filename invalid, output warning and repeat, if valid then return filename 8 *** End of Mark Scheme – example program code solutions follow *** Program Code Example Solutions
Mark scheme, page 14
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 14 of 20 Question 4(b): Visual Basic Function Search(Par1, Par2 As STRING) As INTEGER Dim Index, RetVal As INTEGER Index = 1 RetVal = -1 While Index <= 100 And RetVal = -1 If XRef(Index, 1) = Par1 _ AND (XRef(Index, 2) = Par2 OR XRef(Index, 3) = Par2) Then RetVal = Index End If Index = Index + 1 End While Return RetVal End Function Question 4(b): Pascal function Search(Par1, Par2 : string) : integer; var Index : integer; RetVal : integer; begin Index := 1; RetVal := -1; While Index <= 100 And RetVal = -1 do begin if XRef[Index, 1] = Par1 and (XRef[Index, 2] = Par2 or XRef[Index, 3] = Par2) then RetVal := Index; Index := Index + 1; end; Search := RetVal // result := RetVal end;
Mark scheme, page 15
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 15 of 20 Question 4(b): Python def Search(Par1, Par2): ## Index, RetVal As INTEGER Index = 1 RetVal = -1 while Index <= 100 and RetVal = -1: if XRef[Index][1] == Par1 \ and XRef[Index][2] == Par2 or XRef[Index][3] == Par2: RetVal = Index Index = Index + 1 return RetVal Question 5(b)(ii): Visual Basic Function Verify(UserID As String) As Boolean Dim Count As INTEGER Dim Response As BOOLEAN Dim Password As STRING Count = 1 Response = FALSE If UserID = "Guest" Then Return TRUE End If While Response = FALSE And Count < 4 Console.Writeline("Please input your password: ") Password = Console.Readline() Response = Validate(UserID, Password) AND TODAY() If Response = FALSE Then Count = Count + 1 If Count < 4 Then Console.Writeline("Incorrect password – please try again") End If End If End While Return Response End Function
Mark scheme, page 16
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 16 of 20 Question 5(b)(ii): Pascal function Verify(UserID : string) : boolean; var Count : integer; Response : boolean; Password : string; begin Count := 1; if UserID = "Guest" then Verify := TRUE // result := TRUE; while Response = FALSE And Count < 4 begin writeln('Please input your password: '); readln(Password); Response := Validate(UserID, Password) and TODAY(); if Response = FALSE then begin Count := Count + 1; if Count < 4 then writeln('Incorrect password – please try again'); end; end; Verify := Response // result := Response end; Question 5(b)(ii): Python def Verify(UserID): ## Count As INTEGER ## Response As BOOLEAN ## Password As STRING Count = 1 if UserID == "Guest": return TRUE while Response == FALSE and Count < 4: Password = input("Please input your password: ") Response = Validate(UserID, Password) and TODAY() if Response == FALSE: Count = Count + 1 if Count < 4: print("Incorrect password – please try again") return Response
Mark scheme, page 17
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 17 of 20 Question 6(a): Visual Basic Sub StockSummary() Dim Index, Count As Integer Dim Total As Real Count = 0 Total = 0.0 For Index = 1 To 10000 If StockID(Index) <> "" then Count = Count + 1 Total = Total + (Quantity(Index)) * Cost(Index)) End If Next Index Console.writeline("Total Value is " & Total.toString) Console.writeline("Number of Stock Entries is " & Count.toString) End Sub Question 6(a): Pascal procedure StockSummary(); var Index, Count : Integer; Total : Real; begin Count := 0; Total := 0.0; for Index := 1 TO 10000 do begin if StockID[Index] <> "" then begin Count := Count + 1; Total := Total + (Quantity[Index]) * Cost[Index]); end; end; writeln('Total Value is ', Total); writeln('Number of Stock Entries is ', Count); end;
Mark scheme, page 18
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 18 of 20 Question 6(a): Python def StockSummary(): ## Index, Count : Integer ## Total : Real Count = 0 Total = 0.0 for Index in range(1, 10001): if StockID[Index] <> "": Count = Count + 1 Total = Total + (Quantity[Index]) * Cost[Index]) print("Total Value is ", Total) print("Number of Stock Entries is ", Count) Question 6(c): Visual Basic Function GetValidFilename() As String Dim Filename As String Dim Valid As Boolean Dim Index As Integer Dim NextChar as Char Valid = FALSE Do Valid = TRUE Console.writeline("Please input the name for the backup file ") Filename = Console.readline() If Len(Filename) < 4 Or Len(Filename) > 10 Then Valid = FALSE Else Index = 1 While Index <= Len(Filename) And Valid = TRUE NextChar = MID(Filename, Index, 1) If Not ((NextChar >='a' AND NextChar <='z') _ Or (NextChar >='A' AND NextChar <='Z')_ Or (NextChar >='0' AND NextChar <='9')) Then Valid = FALSE //not alphanumeric End If Index = Index + 1 End While End If If Valid = FALSE Then Console.writeline("Invalid filename – please try again") End If Loop Until Valid = TRUE Return Filename End Function
Mark scheme, page 19
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 19 of 20 Question 6(c): Pascal function GetValidFilename() : String; var Filename : String; Valid : Boolean; Index : Integer; NextChar : Char; begin Valid := FALSE; repeat Valid := TRUE; writeln('Please input the name for the backup file '); readln(Filename); if length(Filename) < 4 Or length(Filename) > 10 then Valid := FALSE else begin Index := 1; while Index <= length(Filename) And Valid = TRUE do begin NextChar := MidStr(Filename, Index, 1); if Not ((NextChar >='a' AND NextChar <='z') Or (NextChar >='A' AND NextChar <='Z' Or (NextChar >='0' AND NextChar <='9')) then Valid := FALSE; //not alphanumeric Index := Index + 1; end; end; If Valid = FALSE then writeln('Invalid filename – please try again'); until Valid = TRUE; result := Filename; // GetValidFilename := Filename end; Question 6(c): Python def GetValidFilename(): ## Filename As String ## Valid As Boolean ## Index As Integer ## NextChar As Char Valid = FALSE while not Valid: Valid = TRUE Filename = input("Please input the name for the backup file ") if Len(Filename) < 4 or Len(Filename) > 10: Valid = FALSE else: Index = 0 while Index <= Len(Filename) and Valid = TRUE: NextChar = FileName[Index] if not ((NextChar >= '0' and NextChar <= '9' or (NextChar >= 'a' and NextChar <= 'z') or (NextChar >= 'A' and NextChar <= 'Z'):
Mark scheme, page 20
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 20 of 20 Valid = FALSE Index = Index + 1 if Valid == FALSE: print("Invalid filename – please try again") return Filename
What you needed in this session
Cambridge’s own grade thresholds for 2021 May/June, Paper 2 · Variant 2. A higher threshold means an easier paper — the bar moves with how the cohort did.