Cambridge A Level Computer Science 9608 — 2021 May/June Paper 2 · Variant 1
9608/21/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 paper24 pages
























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

















Paper as text
Question paper, page 1
This document has 24 pages. Any blank pages are indicated. DC (RW/FC) 205023/2 © UCLES 2021 [Turn over * 0 0 1 5 2 6 0 8 2 1 * COMPUTER SCIENCE 9608/21 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. Cambridge International AS & A Level
Question paper, page 2
2 9608/21/M/J/21 © UCLES 2021 1 (a) (i) State how characters are represented using the ASCII character set. … … … … [2] (ii) String values may be represented by a sequence of ASCII characters. The following table shows consecutive memory locations. Complete the table by adding the values to show how the string "FADED" may be stored in memory using the ASCII character set. Refer to the Appendix on pages 22–23 for the list of built-in pseudocode functions and operators, which includes a reference to the ASC() function. Memory location ASCII character value 100 101 102 103 104 [2] (b) Individual elements in a 1D array are referenced using an integer value. In the pseudocode expression StockID[n], the integer value is represented by the variable n. (i) Give the technical terms for the minimum and maximum values for the variable n. Minimum value … Maximum value … [1] (ii) Give the correct term for the variable n in the pseudocode expression StockID[n]. … [1]
Question paper, page 3
3 9608/21/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–23 for the list of built-in pseudocode functions and operators. Statement Error Code LEFT("Cat", 4) Status MID("Aardvark", 0, 5) Size LENGTH("Password) Stock[n] Stock[n+1] Result 3 OR 4 [5]
Question paper, page 4
4 9608/21/M/J/21 © UCLES 2021 2 (a) The following pseudocode algorithm counts the number of each alphabetic character in the string Msg. The character count values are stored in an array CharCount. Variable declarations are not shown. FOR Index 1 TO 26 CharCount[Index] 0 ENDFOR FOR Index 1 TO LENGTH(Msg) ThisChar MID(Msg, Index, 1) ThisChar LCASE(ThisChar) IF ThisChar >= 'a' AND ThisChar <= 'z' THEN ThisIndex ASC(ThisChar) – 96 // value from 1 to 26 CharCount[ThisIndex] CharCount[ThisIndex] + 1 ENDIF ENDFOR
Question paper, page 5
5 9608/21/M/J/21 © UCLES 2021 [Turn over Draw a program flowchart to represent the algorithm. Variable declarations are not required in program flowcharts. [5]
Question paper, page 6
6 9608/21/M/J/21 © UCLES 2021 (b) The character count values have been assigned to the array in part (a). Use structured English to describe an algorithm to: • search the array • output the alphabetic character that occurs most often (the highest character count value) • output a suitable message if more than one alphabetic character has the same highest count value. … … … … … … … … … … … … … … … … … … … … … … … … [6]
Question paper, page 7
7 9608/21/M/J/21 © UCLES 2021 [Turn over BLANK PAGE
Question paper, page 8
8 9608/21/M/J/21 © UCLES 2021 3 (a) The following table contains information about five modules in a program. It describes the calls made and the parameters passed. Module Description Module_X • repeatedly calls Module_Y then Module_Z • passes a parameter of type REAL to Module_Y • passes two parameters of type INTEGER to Module_Z Module_Y calls either Module_YA or Module_YB Module_Z called with two parameters of type INTEGER Module_YA • called with a parameter of type REAL • parameter is passed by reference Module_YB • called with a parameter of type INTEGER • returns a BOOLEAN value Complete the structure chart to include the information given about the five modules. Module_X Module_Y Module_Z Module_YA Module_YB [5]
Question paper, page 9
9 9608/21/M/J/21 © UCLES 2021 [Turn over (b) Two more modules are added to the chart below Module_Z as shown: Module_Z ParX ParZ ParX ParY Module_ZA Module_ZB Parameter data types are: ParX : REAL ParY : INTEGER ParZ : STRING (i) State whether Module_ZA() is a function or a procedure and justify your choice. … … … [2] (ii) Write the pseudocode header for Module_ZB(). … … … [3]
Question paper, page 10
10 9608/21/M/J/21 © UCLES 2021 4 The following is part of a program written in pseudocode: DECLARE ThisArray : ARRAY[1:1000] OF STRING DECLARE ArrayResult : INTEGER PROCEDURE ScanArray(SearchString : STRING) DECLARE Index, Total : INTEGER DECLARE Error : BOOLEAN Index 1 Total 0 Error FALSE WHILE Index <= 1000 AND Error <> TRUE IF LENGTH(ThisArray[Index]) > 5 THEN IF ThisArray[Index] = SearchString THEN Total Total + LENGTH(ThisArray[Index]) ENDIF Index Index + 1 ELSE Error TRUE ENDIF ENDWHILE ArrayResult INT(Total / (Index - 1)) ENDPROCEDURE The procedure ScanArray() is amended as follows: • SearchString is compared with just the first four characters of each array element. • The total ignores the first five characters of each array element. • When calculating ArrayResult, prevent any possible division by zero. Refer to the Appendix on pages 22–23 for the list of built-in pseudocode functions and operators.
Question paper, page 11
11 9608/21/M/J/21 © UCLES 2021 [Turn over (a) Write program code to implement this amended procedure ScanArray(). 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/21/M/J/21 © UCLES 2021 (b) Context-sensitive prompts are a feature of a typical Integrated Development Environment (IDE). Explain the term context‑sensitive prompt. … … … … [2] (c) (i) Identify the first stage in the program development cycle. State the tasks that are completed during this stage. First stage … Tasks … … … … … [3] (ii) A program will be translated using a compiler. Identify the stage of the program development cycle where a syntax error may occur. … [1]
Question paper, page 13
13 9608/21/M/J/21 © UCLES 2021 [Turn over BLANK PAGE
Question paper, page 14
14 9608/21/M/J/21 © UCLES 2021 5 Alice is developing an algorithm for a game. The game will count the number of attempts by a player to guess the secret number generated by the built-in random number function. She will use pseudocode to develop a procedure, GuessNum(), that will: 1. generate a secret number that is a random integer in the range 1 to 20 inclusive 2. prompt and input the player’s guess 3. output a message if the guess is not the same as the secret number and repeat from step 2 4. count the number of attempts it takes to guess the secret number 5. output a message when the secret number has been guessed correctly, giving the number of attempts. (a) (i) Write pseudocode for the procedure GuessNum(). Refer to the Appendix on pages 22–23 for the list of built-in pseudocode functions and operators. … … … … … … … … … … … … … … … … … … … … [5]
Question paper, page 15
15 9608/21/M/J/21 © UCLES 2021 [Turn over (ii) Suggest two different validation checks that could be applied to the input of the procedure GuessNum() to ensure invalid guesses are not counted. 1 … … … 2 … … … [2] (b) Alice is converting her pseudocode into a high-level language for use in a larger modular program. She wants to start testing the program before all the subroutines (procedures and functions) have been implemented. (i) Identify this type of testing. … [1] (ii) Her program contains a function Status() that she has not yet written, but will be called from several places within the program. Explain what Alice needs to do to allow the program to be tested. … … … … … [2] (iii) Alice compiles her program. Explain the function of the compiler. … … [1]
Question paper, page 16
16 9608/21/M/J/21 © UCLES 2021 6 A program stores stock data in four global arrays as follows: Array Data type Description Example data value Initial data value StockID STRING The stock item ID (Eight alpha-numeric characters) "HWDM0001" "" Description STRING A description of the item (Alphabetic characters only) "Candle" "" Quantity INTEGER The number in stock 4 0 Cost REAL The cost of the item 2.75 0 • Each array contains 10 000 elements. • Elements with the same index relate to the same stock item. For example, StockID[4] contains the ID for the product whose description is in Description[4]. • 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 program is to be modified so that the data from the arrays can be stored in a text file for backup. The programmer has started to define program modules as follows: Module Description GetValidFilename() • prompts, inputs and returns a valid filename Check() • called with an array index as a parameter • checks that the data values for the stock item with the given index are valid • returns TRUE if the values are valid, otherwise returns FALSE Backup() • calls GetValidFilename() to get the name of the backup file • combines the data values for each stock item to form a single string. Inserts an asterisk character '*' as a separator between data values • writes the string to the backup file • calls Check() to validate the data values. If there is an error then also writes the string to the file "ERRORLOG.TXT" • repeats for all stock items • returns TRUE if nothing was written to "ERRORLOG.TXT", otherwise returns FALSE Unpack() • called with two parameters: o an array index o 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
Question paper, page 17
17 9608/21/M/J/21 © UCLES 2021 [Turn over (a) Write program code for the module Check(). Data values relating to an individual stock item are valid if: • the StockID element is of length 8 • the Description is not an empty string • the Quantity is zero or above. 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 … … … … … … … … … … … … … [4]
Question paper, page 18
18 9608/21/M/J/21 © UCLES 2021 (b) Write pseudocode for the module Backup(). … … … … … … … … … … … … … … … … … … … … … … … … … … …
Question paper, page 19
19 9608/21/M/J/21 © UCLES 2021 [Turn over … … … … … … [8]
Question paper, page 20
20 9608/21/M/J/21 © UCLES 2021 (c) The module description of Unpack() is repeated here for reference. Module Description Unpack() • called with two parameters: o an array index o 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 Write program code for the module Unpack(). You may assume that the backup file contains only valid stock information. 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/21/M/J/21 © UCLES 2021 … … … … … … … … … … … … … … … … … … … [8]
Question paper, page 22
22 9608/21/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 RAND(x : INTEGER) RETURNS REAL returns a real number in the range 0 to x (not inclusive of x). Example: RAND(87) could return 35.43 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"
Question paper, page 23
23 9608/21/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/21/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 17 printed pages. © UCLES 2021 [Turn over Cambridge International AS & A Level COMPUTER SCIENCE 9608/21 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/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 2 of 17 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/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 3 of 17 Question Answer Marks 1(a)(i) One mark for each part statement: • Each character is assigned... • ...a unique value • …using 7 bits Max 2 marks 2 1(a)(ii) One mark for two correct, 2 marks for all correct Memory location ASCII character value 100 70 101 65 102 68 103 69 104 68 2 1(b)(i) One mark for both answers correct. Exact terms only. • Lower bound • Upper bound 1 1(b)(ii) index / subscript 1 1(c) One mark for each error Statement Error Code ← LEFT("Cat", 4) Only 3 characters in string Status ← MID("Aardvark", 0, 5) Second parameter should start from 1 Size ← LENGTH("Password) Missing closing quote / Opening quote should be removed Stock[n] ← Stock[n+1] NO ERROR / n may not be integer value / n out of bound Result ← 3 OR 4 Not Boolean types 5
Mark scheme, page 4
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 4 of 17 Question Answer Marks 2 Mark as follows: First mark for START, Initialisation of Index and END Then one mark per area outlined, in correct place. At least one decision box label (YES / NO) must be present. 5
Mark scheme, page 5
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 5 of 17 Question Answer Marks 2(b) One mark per point. Algorithm should mention: 1 Initialise variable to hold Max value 2 Loop through 26 elements of array 3 Test if element > Max ….and if so set new Max value 4 Method of checking for duplicates 5 Output a messge giving alphabetic char with largest count value - needs use of CHR() 6 Output a suitable message if largets count value is shared 6 Question Answer Marks 3(a) 1 mark for each of: 1 Iteration arrow 2 Selection diamond 3 Both sets of parameters from Module_X 4 Parameter ByReferene to Module_YA 5 Parameter (ByValue) and return Boolean from Module_YB 5 3(b)(i) One mark for each statement: • it is a function • because it returns a value 2
Mark scheme, page 6
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 6 of 17 Question Answer Marks 3(b)(ii) PROCEDURE Module ZB (BYVALUE ParX : REAL, BYREF ParZ : STRING) One mark for: • Procedure declaration • ParX : REAL and ParZ : STRING • ByRef for ParZ Condone missing BYVALUE for ParX 3
Mark scheme, page 7
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 7 of 17 Question Answer Marks 4(a) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language solutions appear in the Appendix. PROCEDURE ScanArray(SearchString STRING) DECLARE Index, Total : INTEGER DECLARE Error : BOOLEAN Index ← 1 Total ← 0 Error ← FALSE WHILE Index <= 1000 AND Error <> TRUE IF LENGTH(ThisArray[Index]) > 5 THEN IF LEFT(ThisArray[Index], 4) = SearchString THEN Total ← Total + LENGTH(ThisArray[Index]) - 5 ENDIF Index ← Index + 1 ELSE Error ← TRUE ENDIF ENDWHILE IF Index > 1 THEN ArrayResult ← INT(Total / (Index - 1)) ENDIF ENDPROCEDURE Mark as follows: 1 Procedure header including parameter and end (where required) 2 Local variable declarations and initialisation of Index, Total and Error but no local declaration of ArrayResult 3 WHILE / ENDWHILE loop 4 Nested IF statement comparing first four character of array element with SearchString 5 Summation of Total using appropriate LENGTH function and subtracting 5 6 Assignment to ArrayResult using appropriate INT function AND check for division by zero 6 4(b) One mark for each: • The IDE displays hints / choice of keywords / available identifiers • (Appropriate to) the current cursor position / insertion point 2
Mark scheme, page 8
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 8 of 17 Question Answer Marks 4(c)(i) One mark for Name, max 2 for Tasks (one per underlined term): Name: Design Tasks: To define the data structures and algorithms (of the solution) ALTERNATIVE Name: Analysis Tasks: Feasibility study // Problem definition / investigation // Requirement spec 3 4(c)(ii) Coding / Implementation / Programming 1 Question Answer Marks 5(a)(i) PROCEDURE GuessNum() DECLARE Count: INTEGER DECLARE RndNumber : INTEGER DECLARE MyGuess : INTEGER RndNumber ← 1 + INT(RAND(20)) Count ← 1 REPEAT OUTPUT "Input your guess" INPUT MyGuess IF MyGuess <> RndNumber THEN Count ← Count + 1 OUTPUT "Incorrect – try again" ENDIF UNTIL MyGuess = RndNumber OUTPUT "You took ", Count, " guesses." ENDPROCEDURE 1 mark for each of the following: 1 Use of RAND()to generate an integer between 1 and 20 2 Conditional loop until random number is guessed 3 Prompt and input a guess …in a loop 4 Comparison and increment Count and 'Try again' output message…in a loop 5 Final output message…not in a loop 5
Mark scheme, page 9
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 9 of 17 Question Answer Marks 5(a)(ii) One mark per point. Check for: • Integer / number out of range <1 OR > 20 • Real number entered • Non-numeric value entered Max 2 marks 2 5(b)(i) • Stub testing 1 5(b)(ii) One mark for each: • A simplified version of Status()/ a dummy function is written • that returns a typical / expected value. 2 5(b)(iii) A compiler is used to translate / convert the source code / program / high-level language code into object code / machine code / an executable file 1 Question Answer Marks 6(a) 'Pseudocode' solution included here for development and clarification of the mark scheme. Programming language example solutions appear in the Appendix. FUNCTION Check(Index : INTEGER) RETURNS BOOLEAN IF LENGTH(StockID[Index]) <> 8 OR __ Description[Index]) = "" OR __ Quantity[Index] < 0 THEN RETURN FALSE ELSE RETURN TRUE ENDIF ENDFUNCTION One mark for each of the following: 1 Function heading and ending (where appropriate) 2 Three comparisons... 3 ... connected by logical OR // AND / correct nested IF 4 RETURN value in both cases 4
Mark scheme, page 10
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 10 of 17 Question Answer Marks 6(b) FUNCTION Backup() RETURNS BOOLEAN DECLARE Index : INTEGER DECLARE FileName, FileLine : STRING DECLARE AllOK : BOOLEAN CONSTANT ASTERISK = '*' AllOK ← TRUE FileName ← GetValidFileName() OPENFILE Filename FOR WRITE OPENFILE "ERRORLOG.TXT" FOR WRITE FOR Index ← 1 TO 10000 IF StockID[Index]<> “” THEN FileLine ← StockID[Index] & ASTERISK FileLine ← FileLine & Description[Index] & ASTERISK FileLine ← FileLine & NUM_TO_STRING(Quantity[Index]) & ASTERISK FileLine ← FileLine & NUM_TO_STRING(Cost[Index]) WRITEFILE FileName, FileLine //now check for sensible data IF Check(Index) <> TRUE THEN WRITEFILE, "ERRORLOG.TXT", FileLine AllOK ← FALSE ENDIF ENDIF ENDFOR CLOSEFILE FileName CLOSEFILE "ERRORLOG.TXT" RETURN AllOK ENDFUNCTION 1 mark for each of the following: 1 Declare local variable for backup filename and index 2 Call to function GetValidFileName() 3 OPEN and CLOSE both files 4 Loop all 10 000 elements 5 Form FileLine using at least one correct array index expression and asterisk 6 Use of NUM_TO_STRING() to convert at least one of QUANTITY or COST 7 Write line to backup file 8 Call Check() to determine whether values are valid and if not, write to ERRORLOG.TXT 9 Return AllOK Max 8 marks from possible 10 mark points 8
Mark scheme, page 11
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 11 of 17 Question Answer Marks 6(c) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. PROCEDURE Unpack(Index : INTEGER, FileLine : STRING) DECLARE Pointer : INTEGER DECLARE NextChar : CHAR DECLARE TempString : STRING CONSTANT ASTERISK = '*' StockID[Index] ← LEFT(FileLine, 8) // the only fixed length field Pointer ← 10 // Point to start of Description (skip the '*') NextChar ← MID(FileLine, Pointer, 1) TempString ← "" WHILE NextChar <> ASTERISK TempString ← TempString & NextChar Pointer ← Pointer + 1 NextChar ← MID(FileLine, Pointer, 1) ENDWHILE Description[Index] ← TempString Pointer ← Pointer + 1 NextChar ← MID(FileLine, Pointer, 1) TempString ← "" WHILE NextChar <> ASTERISK TempString ← TempString & NextChar Pointer ← Pointer + 1 NextChar ← MID(FileLine, Pointer, 1) ENDWHILE Quantity[Index] ← STRING_TO_NUM(TempString) TempString ← RIGHT(FileLine, LENGTH(FileLine) – Pointer) Cost[Index] ← STRING_TO_NUM(TempString) ENDFUNCTION 1 mark for each of the following: 1 Procedure heading with parameters 2 Extract first 8 chars of FileLine 3 Assign to StockID 4 Search for asterisk for place separator 5 Extract Description string and assign to Description array 6 Extract Quantity string, and assign to Quantity array... 7 Extract Cost string and assign to Cost array 8 Type conversion for Cost and Quantity 8 *** End of Mark Scheme – example program code solutions follow ***
Mark scheme, page 12
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 12 of 17 Program Code Example Solutions Q4 (a): Visual Basic Sub ScanArray(SearchString As String) Dim Index, Total As Integer Dim Error As Boolean Index = 1 Total = 0 Error = FALSE While Index <= 1000 And Error <> TRUE If Len(ThisArray(Index)) > 5 Then If Left(ThisArray(Index), 4) = SearchString Then Total = Total + Len(ThisArray(Index)) - 5 End If Index = Index + 1 Else Error = TRUE End If End While If Index > 1 Then ArrayResult = Int(Total / (Index - 1)) End If End Sub
Mark scheme, page 13
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 13 of 17 Q4 (a): Pascal procedure ScanArray(SearchString : string); var Index, Total : integer; Error : boolean; begin Index := 1; Total := 0; Error := FALSE; while Index <= 1000 And Error <> TRUE do begin if Length(ThisArray[Index]) > 5 then begin if LeftStr(ThisArray[Index], 4) = SearchString then Total := Total + Length(ThisArray[Index]) – 5; Index := Index + 1; else Error := TRUE; end; end; if Index > 1 then ArrayResult := int(Total / (Index - 1)); end; Q4(a): Python def ScanArray(SearchString): ## Index, Total As Integer ## Error As Boolean Index = 1 Total = 0 Error = FALSE while Index <= 1000 and Error <> TRUE: if len(ThisArray[Index]) > 5: ThisElement = ThisArray[Index] if ThisElement[:4] == SearchString: Total = Total + len(ThisArray[Index]) - 5 Index = Index + 1 else: Error = TRUE if Index > 1: ArrayResult = int(Total / (Index - 1))
Mark scheme, page 14
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 14 of 17 Q6 (a): Visual Basic Function Check(Index As Integer) As Boolean If Len(StockID(Index)) <> 8 Or _ Description(Index)) = "" Or _ Quantity(Index) < 0 Then Return FALSE Else Return TRUE End If End Function Q6(a): Pascal function Check(Index : Integer) : boolean; begin if Length(StockID[Index]) <> 8 Or Description[Index]) = "" Or Quantity[Index] < 0 then Check := FALSE // result := FALSE else Check := TRUE // result := TRUE end; end Q6(a): Python def Check(Index): if len(StockID[Index]) <> 8 or \ Description[Index]) == "" or \ Quantity[Index] < 0: return FALSE else: return TRUE
Mark scheme, page 15
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 15 of 17 Q6(c): Visual Basic Sub Unpack(Index As Integer, FileLine As String) Dim Pointer As Integer Dim NextChar As Char Dim TempString As String Const ASTERISK = '*' StockID(Index) = LEFT(FileLine, 8) Pointer = 10 'point to start of Description (skip the '*') NextChar = Mid(FileLine, Pointer, 1) TempString = "" While NextChar <> ASTERISK TempString = TempString & NextChar Pointer = Pointer + 1 NextChar = Mid(FileLine, Pointer, 1) End While Description(Index) = TempString Pointer = Pointer + 1 NextChar = Mid(FileLine, Pointer, 1) TempString = "" While NextChar <> ASTERISK TempString = TempString & NextChar Pointer = Pointer + 1 NextChar = Mid(FileLine, Pointer, 1) End While Quantity(Index) = CInt(TempString) TempString = Right(FileLine, Len(FileLine) – Pointer) Cost(Index) = CDec(TempString) End Sub Q6(c): Pascal procedure Unpack(Index : Integer, FileLine : String); var Pointer : integer; NextChar : char; TempString : string; const ASTERISK = '*'; begin StockID[Index] := LeftStr(FileLine, 8); Pointer := 10; //point to start of Description (skip the '*') NextChar := MidStr(FileLine, Pointer, 1); TempString := ""; while NextChar <> ASTERISK do
Mark scheme, page 16
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 16 of 17 begin TempString := TempString & NextChar; Pointer := Pointer + 1; NextChar := MidStr(FileLine, Pointer, 1); end; Description[Index] := TempString; Pointer := Pointer + 1; NextChar := MidStr(FileLine, Pointer, 1); TempString := ""; while NextChar <> ASTERISK do begin TempString := TempString & NextChar; Pointer := Pointer + 1; NextChar := MidStr(FileLine, Pointer, 1); end; Quantity[Index] := StrToInt(TempString); TempString := RightStr(FileLine, Length(FileLine) – Pointer); Cost[Index] := StrToFloat(TempString); end; Q6(c): Python def Unpack(Index, FileLine): ## Pointer As Integer ## NextChar As Char ## TempString As String ASTERISK = '*' StockID[Index] = FileLine[:8] #characters 0 to 7 Pointer = 9 #point to start of Description (skip the '*') NextChar = FileLine[Pointer] TempString = "" while NextChar <> ASTERISK: TempString = TempString + NextChar Pointer = Pointer + 1 NextChar = FileLine[Pointer] Description[Index] = TempString Pointer = Pointer + 1 NextChar = FileLine[Pointer] TempString = "" while NextChar <> ASTERISK: TempString = TempString + NextChar Pointer = Pointer + 1 NextChar = FileLine[Pointer] Quantity[Index] = int(TempString) TempString = FileLine[Len(FileLine) – Pointer - 1:)
Mark scheme, page 17
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2021 © UCLES 2021 Page 17 of 17 Cost[Index] = float(TempString) Alternative def Unpack(Index, FileLine): ## TempString As String StockID[Index] = FileLine[:8] TempString = FileLine[8:] // remove first 8 characters Description[Index], Quantity[Index], Cost[Index] = (TempString.split(‘*’))
What you needed in this session
Cambridge’s own grade thresholds for 2021 May/June, Paper 2 · Variant 1. A higher threshold means an easier paper — the bar moves with how the cohort did.