Cambridge A Level Computer Science 9608 — 2021 Oct/Nov Paper 2 · Variant 2
9608/22/O/N/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 scheme19 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. DC (RW) 206327/4 © UCLES 2021 [Turn over * 8 4 9 4 3 7 7 8 0 0 * COMPUTER SCIENCE 9608/22 Paper 2 Fundamental Problem-solving and Programming Skills October/November 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/22/O/N/21 © UCLES 2021 1 (a) Design and coding are stages of the program development cycle. State two activities from each of these stages. Design stage Activity 1 … Activity 2 … Coding stage Activity 1 … Activity 2 … [4] (b) The following is part of a procedure to manage the stock in a shop: 100 PROCEDURE InitVars() 101 DECLARE Vs : STRING // program version 102 DECLARE Pe : REAL // stock item purchase price 103 DECLARE Exp : STRING // date when item expires 104 DECLARE S_lr: STRING // supplier ID 105 DECLARE Rp : REAL // low stock value 106 DECLARE OUT : BOOLEAN // any items in stock ? … 180 ENDPROCEDURE (i) Give two reasons why the identifier names used in the procedure InitVars() are not examples of good practice. Reason 1 … … Reason 2 … … [2]
Question paper, page 3
3 9608/22/O/N/21 © UCLES 2021 [Turn over (ii) Complete the following table by writing an appropriate identifier name for each of these four lines in the procedure InitVars(). Line Appropriate identifier name 102 103 105 106 [4] (iii) Line 101 of the procedure needs to be changed because: • the identifier should be declared as a fixed value that does not change during program execution • the identifier name is not appropriate • the program version should be ver1.5.8 Write the new correct statement for line 101. … … [2] (c) A program can store characters using either the ASCII or the Unicode character set. Give two reasons why Unicode is preferred to the ASCII character set for storing characters. Reason 1 … … … Reason 2 … … … [2]
Question paper, page 4
4 9608/22/O/N/21 © UCLES 2021 2 A café manager needs a program for a loyalty scheme. A customer is awarded one loyalty point for each purchase. When a customer has ten or more points, the customer is offered a free slice of cake. (a) During the program design, a decision is made to store the loyalty data in a text file called LOYALTY.txt. This file holds the membership number and total number of points for each customer on a single line. Part of the program will check whether a particular customer has enough points for a free slice of cake. Describe the algorithm for this part of the program using structured English. … … … … … … … … … … … [5]
Question paper, page 5
5 9608/22/O/N/21 © UCLES 2021 [Turn over (b) In another part of the program, the following statements assign values to variables. DayOfMonth "15" IsMember TRUE DOB "22042001" Firstname "Seanna" Lastname "Adamson" Points 12 Complete the table by writing the pseudocode expression that matches the description given and the value that each expression evaluates to. Refer to the Appendix on pages 18–19 for a list of built-in pseudocode functions and operators. Description of expression Pseudocode expression Evaluates to Evaluates to TRUE if DayOfMonth is within the first seven days of the month Concatenates the second and third letters of Firstname with the last three letters of Lastname Evaluates to TRUE if DOB contains eight characters Evaluates to TRUE if the customer is a member and has enough points for a free slice of cake [4]
Question paper, page 6
6 9608/22/O/N/21 © UCLES 2021 (c) Another part of the loyalty scheme program will need to access additional files. A filename contains a three-letter extension that represents its file type. For example, the filename "thisfile.txt" has the extension "txt" and file type "Text". The filename will always be in lower case. A function GetFileType() returns a string containing the description of the file type. The function uses selection constructs as follows: FUNCTION GetFileType(Filename : STRING) RETURNS STRING DECLARE FileExt : STRING DECLARE FileType : STRING FileExt RIGHT(Filename, 3) IF FileExt = "rtf" THEN FileType "Rich text format" ENDIF IF FileExt = "csv" THEN FileType "Comma separated values" ENDIF IF FileExt = "txt" THEN FileType "Text" ELSE FileType "Unknown" ENDIF RETURN FileExt ENDFUNCTION Rewrite the function as follows: • Replace the IF structures with a CASE structure. • Correct the logic error in the function. Refer to the Appendix on pages 18–19 for a list of built-in pseudocode functions and operators. … … … … … …
Question paper, page 7
7 9608/22/O/N/21 © UCLES 2021 [Turn over … … … … … … … … … … [4] 3 (a) Describe the term decomposition when used to develop algorithms. … … … … … … [3] (b) Explain the term transferable skills and state how these skills are used in program development. … … … … [2]
Question paper, page 8
8 9608/22/O/N/21 © UCLES 2021 4 A global 1D array Flower represents the flowers in a field and is defined as follows: • The array contains 20 elements of type integer. • Each element of the array contains a number associated with each flower. (a) A procedure, InitialiseArray(), initialises the array Flower by setting the value of each element to –1. Write pseudocode for the procedure InitialiseArray(). … … … … … … … … … [4]
Question paper, page 9
9 9608/22/O/N/21 © UCLES 2021 [Turn over (b) A procedure called RandomPath() assigns values to the array Flower to store a path through the flowers in the fields as follows: • the first flower to be visited is flower number 10 • randomly select the next flower to be visited between 1 and 20 • store the index of the next flower to be visited in the current element of the array Flower if the flower has not been visited • visit each flower only once • repeat until the path has been completed through all flowers. An element of –1 indicates that a flower has not been visited. Write program code for the procedure RandomPath(). 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/O/N/21 © UCLES 2021 (c) The procedure RandomPath() executes but gives an unexpected result. (i) State the type of program error that has occurred and identify how this error can be detected. Type of program error … Method of detection … … [2] (ii) Assume that the random number has been incorrectly generated in the procedure RandomPath(). State two possible consequences of the incorrect use of the random number function. 1 … … 2 … … [2] 5 The pseudocode for a procedure FormatYear() is written as follows: PROCEDURE FormatYear(Year : INTEGER, UseSuffix : BOOLEAN) DECLARE OutYear : STRING CONSTANT SUFFIX1 = "BCE" CONSTANT SUFFIX2 = "CE" OutYear NUM_TO_STRING(Year) IF UseSuffix = TRUE THEN IF Year < 0 THEN OutYear OutYear & SUFFIX1 ELSE OutYear OutYear & SUFFIX2 ENDIF ENDIF OUTPUT OutYear ENDPROCEDURE
Question paper, page 11
11 9608/22/O/N/21 © UCLES 2021 [Turn over (a) Draw a program flowchart to represent the algorithm for the module. Variable and constant declarations are not required in program flowcharts. [5]
Question paper, page 12
12 9608/22/O/N/21 © UCLES 2021 (b) For each of the following tests, choose three values of the parameters Year and UseSuffix that test three different aspects of the procedure FormatYear(). State the expected output in each case. Test 1 Parameter Value Expected output Year UseSuffix Test 2 Parameter Value Expected output Year UseSuffix Test 3 Parameter Value Expected output Year UseSuffix [6] (c) (i) Describe two features of black-box testing. … … … … [2] (ii) Describe two features of white-box testing. … … … … [2]
Question paper, page 13
13 9608/22/O/N/21 © UCLES 2021 [Turn over BLANK PAGE
Question paper, page 14
14 9608/22/O/N/21 © UCLES 2021 6 A geocode string consists of four characters that are followed by: • the character '+' • two more characters • a comma • a description of the location. For example: • The geocode string for Cambridge, UK is "646A+6R,CambridgeUK". • The geocode string for Chicago, USA is "V9PG+3P,ChicagoUSA". A program uses two 1D arrays to store data about the locations in which photographs were taken. • An array GeoCodeData contains a geocode string for each location. A geocode string is added to this array if it does not exist in the array. • An array GeoCodeLog contains the first seven characters of the geocode string for each photograph, followed by a space and the date when the photograph was taken. The date format is DD/MM/YYYY. For example, a photograph taken in Cambridge, UK on 21/12/2020 is represented as: "646A+6R 21/12/2020" Assume that: • both arrays contain 20 000 elements • new data is added to the next unused element • unused array elements are indicated by the string "AAAA+0A". (a) A programmer has started to define the program module SearchLog(). Module Description SearchLog() • takes the first seven characters of a geocode as a parameter • counts the number of times this parameter occurs in the array GeoCodeLog • extracts the date the last photograph was taken at the geocode location • returns a string formed by concatenating the count, a single space and the date Write pseudocode for the module SearchLog(). … … … … … …
Question paper, page 15
15 9608/22/O/N/21 © UCLES 2021 [Turn over … … … … … … … … … … … … … … … … … … … … … … … … … … … … [6]
Question paper, page 16
16 9608/22/O/N/21 © UCLES 2021 (b) A text file, Locations.txt, stores data from the array GeoCodeData combined with data extracted from the array GeoCodeLog. Each line of the text file contains three items of data in the following format: • The geocode stored in each element of the array GeoCodeData followed by a hash symbol (#). • The number of times each geocode is found in the array GeoCodeLog followed by the hash symbol. • The date of the last photograph taken at that location. For example, twelve photographs were taken at geocode V9PG+3P,ChicagoUSA. The last photograph was taken on 09/10/2020. The corresponding entry in the file Locations.txt is: "V9PG+3P,ChicagoUSA#12#09/10/2020" The program module ExtractArrays() is defined as follows: Module Description ExtractArrays() • creates the text file Locations.txt • uses SearchLog() to obtain the string of the count and the date of the last photograph for each geocode location • writes the entry in the text file Locations.txt You may assume that unused elements of GeoCodeData array are not added to the file Locations.txt. Write program code for the module ExtractArrays(). 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/O/N/21 © UCLES 2021 [Turn over … … … … … … … … … … … … … … … … … … … … … … … … … … … … [7]
Question paper, page 18
18 9608/22/O/N/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 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
Question paper, page 19
19 9608/22/O/N/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 20
20 9608/22/O/N/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 19 printed pages. © UCLES 2021 [Turn over Cambridge International AS & A Level COMPUTER SCIENCE 9608/22 Paper 2 Fundamental Problem-Solving and Programming Skills October/November 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 October/November 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 October/November 2021 © UCLES 2021 Page 2 of 19 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 October/November 2021 © UCLES 2021 Page 3 of 19 Question Answer Marks 1(a) One mark per bullet point to Max 4 e.g. Design stage activities: • create / produce / define identifier table // decide on identifiers • create / produce / define data structures // data types • create / produce / define file structures • create / produce / define test plan / strategy • create pseudocode • create flowchart etc. • identify inputs/outputs/processes • decomposing the problem into sub-problems • choose a suitable programming language Coding stage activities: • write program code // coding the algorithms (from design) 'write code' on its own is NE • define data structures • use a translator to check and run the code • initial debugging // testing • any example of actions performed when programming 4 1(b)(i) One mark per bullet point to Max 2 • names are not meaningful (or equivalent) // name does not reflect the identifier's use • makes the program/variables more difficult to understand // difficult for non-technical/other person to understand the program/variables • makes the program more difficult to debug / modify / test 2 1(b)(ii) One mark for each correct row. Line Appropriate identifier name 102 Price / ItemPrice / StockPrice 103 ExpiryDate / ItemExpiryDate / EndDate 105 LowStockValue / LowValue / LowStock 106 IsOutOfStock / IsInStock 4 1(b)(iii) One mark each • (Constant) declaration with appropriate identifier for program version (as String) • Storing correct value in the variable (equals or arrow) e.g. CONSTANT ProgramVersion = "ver1.5.8" 2 1(c) One mark each to Max 2 • wider range of character can be represented • symbols from (more) languages can be represented • pictograms / emoticons can be represented 2
Mark scheme, page 4
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 4 of 19 Question Answer Marks 2(a) One mark each of the following to max 5: • Input the membership number • Open the file LOYALTY.txt for read and close the file • Loop until end of file (and membership number not found) • …read each line from the file • Extract stored membership number and points • If number of points is 10 or more, return/output free cake • If membership number not found, return/output appropriate value/message • If number of points is below 10, return / output no free cake • Subtract 10 points from their points and store 5 2(b) One mark for each correct row. Description of expression Pseudocode expression Evaluates to Evaluates to TRUE if DayOFMonth is within the first seven days of the month STRING_TO_NUM(DayOfMonth) <= 7 // DayOfMonth <= "7" FALSE Concatenates the second and third letters of Firstname and concatenate with the last three letters of Lastname MID(Firstname,2,2) & RIGHT(Lastname, 3) // MID(Firstname,2,2) & MID(Lastname, LENGTH(Lastname)-3, 3) "eason" Evaluates to TRUE if DOB contains eight characters LENGTH(DOB) = 8 TRUE Evaluates to TRUE if the customer is a member and has enough points for a free slice of cake IsMember AND Points >= 10 IsMember = TRUE AND Points >= 10 TRUE 4
Mark scheme, page 5
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 5 of 19 Question Answer Marks 2(c) One mark for each bullet point • CASE statement has correct structure (all key words and format) • Correct assignment/identification of all 3 file types in case statement • Assignment/return of "Unknown" as default • Return FileType instead of FileExt // Correct return value for all file types and Unknown FUNCTION GetFileType(Filename : STRING) RETURNS STRING DECLARE FileExt : STRING DECLARE FileType: STRING FileExt ← RIGHT(Filename, 3) CASE OF FileExt 'rtf' : FileType ← "Rich text format" 'csv' : FileType ← "Comma separated values" 'txt' : FileType ← "Text" OTHERWISE : FileType ← "Unknown" ENDCASE RETURN FileType ENDFUNCTION 4 Question Answer Marks 3(a) One mark each to max 3 • break the problem/algorithm (not program / code) into smaller steps / parts/ subproblems • ... repeatedly only if MP1 given • … until all subproblems small/detailed enough to solve • … to identify program modules // to identify repeated elements // for modular programming • … to identify subroutines 3 3(b) 1 mark for definition of term e.g. • apply current knowledge to an unfamiliar scenario 1 mark for how the skills are used in program development e.g. • use current knowledge of a familiar programming language in a new language 2
Mark scheme, page 6
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 6 of 19 Question Answer Marks 4(a) One mark for each bullet point • Procedure heading and ending • Loop from 1 to 20 // Loop from 0 to 19 Allow NEXT for ENDFOR • Assign −1 to array at loop counter • All logic correct, does not override Flower array, all 20 elements assigned −1 e.g. PROCEDURE InitialiseArray() DECLARE Index : INTEGER FOR Index ← 1 TO 20 Flower[Index] ← -1 ENDFOR ENDPROCEDURE 4
Mark scheme, page 7
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 7 of 19 Question Answer Marks 4(b) One mark for each bullet point: • Declare variable to store first flower visited and initialise to 10 // Store flower 10 in first array index • Loop until all 20 flowers are stored • Generate random number between 1 and 20 in the loop … • … Check if array at random number is −1 // Check if random number is already in flower array • … If it is not −1 / already in array, generate another random number • … repeatedly until −1 / not in array • … otherwise assign Flower at previous flower to random number // otherwise assign random number to next array element and increment counter 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear at the end. Example 1: PROCEDURE RandomPath() DECLARE New : INTEGER DECLARE Previous : INTEGER New ← 10 Previous ← 10 FOR X ← 0 TO 19 WHILE NOT(Flower[New] = -1) New ← INT(RAND(20)+1) Flower[Previous] ← New ENDWHILE ENDFOR ENDPROCEDURE Example 2: PROCEDURE RandomPath() DECLARE Current : INTEGER DECLARE Counter: INTEGER DECLARE Next : INTEGER Current ← 10 Counter ← 1 WHILE Counter <= 20 Next ← INT(RAND(20)+1) IF Flower[Next] = -1 THEN Flower[Current] ← Next Current ← Next Counter ← Counter + 1 ENDIF ENDWHILE ENDPROCEDURE 7
Mark scheme, page 8
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 8 of 19 Question Answer Marks 4(c)(i) 1 mark for error type: • Logic // run-time 1 mark for method of detection e.g. • Testing the program with a range of data • Whitebox testing • Blackbox testing 2 4(c)(ii) 1 mark each to max 2 e.g. • Program crashes • Error as number is out of array bounds // number below 1 will produce error // number above 20 will produce error • Not all elements will be accessed/used • Error if decimal generated • Error if negative number generated • Infinite loop may be generated 2 Question Answer Marks 5(a) 1 mark each • Start and end Start/begin End/stop Procedure/end procedure • For each circled area (Max 4) 5
Mark scheme, page 9
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 9 of 19 Question Answer Marks 5(b) 1 mark for values, 1 mark for result from: • Year >= 0 UseSuffix = TRUE • Matching Year value with "CE" • Year >= 0 UseSuffix = FALSE • Matching Year value • Year < 0 UseSuffix = TRUE • Matching Year value with "BCE" • Year < 0 UseSuffix = FALSE • Matching Year value 6 5(c)(i) One mark each to max 2. • code is unknown/not considered • data is chosen to test boundaries // test with normal, extreme and erroneous • compare expected output with actual output // testing whether the inputs produce the correct/expected outputs • testing if the program meets the requirements 2 5(c)(ii) One mark each to max 2. • data is chosen to test algorithm/code • tests every path in the code • test each line of code/structure • internal structure is being tested • tester can view code 2
Mark scheme, page 10
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 10 of 19 Question Answer Marks 6(a) One mark each to max 6: • Function declared taking the string to search for as a parameter, string return (and array) • (Declare and) initialise a variable (0) to count number times code occurs • Loop through 20 000 elements … // looping until unused element • … IF Left 7 from GeoCodeLog[loop counter] = parameter … • … if true, increment number times occurs • … if true, RIGHT 10 from GeoCodeLog[loop counter] … • … if true compare to last date and replace if after // store in variable for last date • Return concatenated number times & " " & last date … • … converting number to string Example 1: FUNCTION SearchLog(SearchGeoCode : STRING) RETURNS STRING DECLARE AccessCount : INTEGER DECLARE LatestDate : STRING DECLARE DateAccess : DATE LatestDate ← "01/01/1500" FOR Index ← 0 TO 19999 IF LEFT(GeoCodeLog[Index], 7) THEN AccessCount ← AccessCount + 1 DateAccess ← (RIGHT(GeoCodeLog[Index], 10)).TODATE IF DateAccess > LatestDate THEN LatestDate ← DateAccess ENDIF ENDIF ENDFOR RETURN NUM_TO_STRING(AccessCount) & " " & DATE_TO_STRING(LatestDate) ENDFUNCTION 6
Mark scheme, page 11
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 11 of 19 Question Answer Marks 6(a) Example 2: FUNCTION SearchLog(SearchGeoCode : STRING) RETURNS STRING DECLARE Index : INTEGER DECLARE AccessCount : INTEGER DECLARE LogGeoCode : STRING DECLARE LastDate : STRING DECLARE CountDateLine : STRING CONSTANT SPACE = ' ' Index ← 1 AccessCount ← 0 LogGeoCode ← "" LastDate ← "" WHILE Index <= 20000 AND LogGeoCode <> "AAAA+0A" LogGeoCode ← LEFT(GeoCodeLog[Index], 7) IF LogGeoCode = SearchGeoCode THEN AccessCount ← AccessCount + 1 LastDate ← RIGHT(GeoCodeLog[Index], 10) ENDIF Index ← Index + 1 ENDWHILE CountDateLine ← NUM_TO_STRING(AccessCount) & SPACE & LastDate RETURN CountDateLine ENDFUNCTION
Mark scheme, page 12
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 12 of 19 Question Answer Marks 6(b) 1 mark each to max 7 • Procedure header • Open file "Locations.txt" in WRITE mode and close the file • Loop through 20 000 elements // looping until unused element … • … if GeoCodeData[loop counter] = "AAAA+0A" loop again/exit • … if not empty call SearchLog() with LEFT(GeoCodeData[DataIndex], 7) … FT invalid/missing if • … use/store returned value • … replace the space with a # • … concatenate GeoCodeData[loop counter] & "#" & returned data inside the loop … • … writing this value to file inside the loop 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear at the end. Example 1: PROCEDURE ExtractArrays() DECLARE DataIndex : INTEGER DECLARE ShortCode, CountAndDate, LocationLine, TempCode : STRING CONSTANT FILENAME = "Locations.txt" DataIndex ← 1 ShortCode ← "" TempCode ← "" OPENFILE FILENAME FOR WRITE FOR Count ← 0 TO 19999 ShortCode ← LEFT(GeoCodeData[DataIndex], 7) IF NOT(ShortCode = "AAAA+0A") THEN CountAndDate ← SearchLog(ShortCode) FOR Index ← 0 TO LENGTH(CountAndDate)-1 IF NOT(MID(CountAndDate,Index,1) = " ") THEN TempCode = TempCode & MID(CountAndDate,Index,1) ELSE TempCode = TempCode & "#" ENDIF ENDFOR LocationLine ← GeoCodeData[DataIndex] & "#" & TempCode WRITEFILE(FILENAME, LocationLine) 7
Mark scheme, page 13
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 13 of 19 Question Answer Marks 6(b) ENDIF ENDFOR CLOSEFILE FILENAME ENDPROCEDURE Example 2: PROCEDURE ExtractArrays() DECLARE DataIndex : INTEGER DECLARE ShortCode, CountAndDate, LocationLine : STRING CONSTANT HASH = '#' CONSTANT FILENAME = "Locations.txt" DataIndex ← 1 ShortCode ← "" OPENFILE FILENAME FOR WRITE WHILE DataIndex <= 20000 AND ShortCode <> "AAAA+0A" ShortCode ← LEFT(GeoCodeData[DataIndex], 7) IF ShortCode <> "AAAA+0A" THEN CountAndDate ← SearchLog(ShortCode) LocationLine ← GeoCodeData[DataIndex] & HASH & CountAndDate WRITEFILE (FILENAME, LocationLine) ENDIF DataIndex ← DataIndex + 1 ENDWHILE CLOSEFILE FILENAME ENDPROCEDURE
Mark scheme, page 14
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 14 of 19 Program Code Example Solutions Q4 (b): Visual Basic Sub RandomPath() ' alternative solution Dim Index, Current, NextFlower As Integer Dim AllFlowersVisited As Boolean Dim RandomFlower As New Random Current = 10 AllFlowersVisited = False Do While AllFlowersVisited = False NextFlower = RandomFlower.Next(1, 20) If Flower(NextFlower) = 0 Then If Flower(Current) = 0 Then Flower(Current) = NextFlower End If Current = NextFlower End If AllFlowersVisited = True For Index = 1 To 20 If Flower(Index) = 0 Then AllFlowersVisited = False End If Next Loop End Sub
Mark scheme, page 15
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 15 of 19 Q4 (b): Pascal procedure RandomPath(); // alternative solution var Index, Current, Next: integer; AllFlowersVisited : boolean; begin Current := 10; AllFlowersVisited := False; while (AllFlowersVisited = False) do begin Randomize; Next := RandomRange(1, 21); if (Flower[Next] = 0) then begin if (Flower[Current] = 0) then Flower[Current] := Next; Current := Next; end; AllFlowersVisited := True; for Index := 1 to 20 do begin if Flower[Index] = 0 then AllFlowersVisited := False; end; end; end;
Mark scheme, page 16
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 16 of 19 Q4 (b): Python from random import seed from random import randint def RandomPath(): # alternative solution #DECLARE Index : INTEGER #DECLARE Current : INTEGER #DECLARE Next : INTEGER #DECLARE AllFlowersVisited : BOOLEAN Current = 10 #start at flower 10 in the field AllFlowersVisited = False while AllFlowersVisited == False: #loop until all flowers visited Next = randint(20) if Flower[Next] == 0: if Flower[Current] == 0: #do not revisit a flower Flower[Current] = Next Current = Next AllFlowersVisited = True #assume all visited unless... for Index in range(1, 20): if Flower[Index] == 0: AllFlowersVisited = False #... proved otherwise
Mark scheme, page 17
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 17 of 19 Q6 (b): Visual Basic Sub ExtractArrays() Dim DataIndex As Integer Dim ShortCode, CountAndDate, LocationLine, CountHashDate As String Dim Sr As StreamWriter = New StreamWriter("Locations") Const HASH = "#" DataIndex = 1 ShortCode = "" CountHashDate = "" Do While DataIndex <= 20000 And ShortCode <> "AAAA+0A" CountHashDate = "" ShortCode = GeoCodeData(DataIndex).SubString(0, 7) If ShortCode <> "AAAA+0A" Then CountAndDate = SearchLog(ShortCode) For Index = 0 To CountAndDate.Length()-1 If (MID(CountAndDate, Index, 1) = " ") Then CountHashDate = CountHashDate & "#" Else CountHashDate = CountHashDate & MID(CountAndDate, Index, 1) = "" End If Next Index LocationLine = GeoCodeData(DataIndex) & HASH & CountHashDate Sr.WriteLine(LocationLine) End If DataIndex = DataIndex + 1 Loop Sr.Close() End Sub
Mark scheme, page 18
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 18 of 19 Q6 (b): Pascal procedure ExtractArrays(); var DataIndex: integer; ShortCode, CountAndDate, LocationLine, CountHashDate: string; Locations: textfile; const HASH = '#'; begin DataIndex := 1; ShortCode := ''; assign(Locations,'M:\Locations'); rewrite(Locations); while (DataIndex <= 20000) and (ShortCode <> 'AAAA+0A') do begin CountHashDate := ""; ShortCode := LeftStr(GeoCodeData[DataIndex], 7); if ShortCode <> 'AAAA+0A' then begin CountAndDate := SearchLog(ShortCode); for Index := 0 to Length(CountAndDate)-1 do begin if CountAndDate[Index] = " " then CountHashDate := CountHashDate + "#" else CountHashDate := CountHashDate + CountAndDate[Index]; end; LocationLine := GeoCodeData[DataIndex] + HASH + CountHashDate; writeln(Locations, LocationLine); end; DataIndex := DataIndex + 1; end; close(Locations); end;
Mark scheme, page 19
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2021 © UCLES 2021 Page 19 of 19 Q6 (b): Python def ExtractArrays(): #DECLARE DataIndex : INTEGER #DECLARE ShortCode, CountAndDate, LocationLine, CountHashDate : STRING HASH = "#" FILENAME = "Locations" DataIndex = 1 ShortCode = "" filehandle = open(FILENAME, 'w') while dataIndex <= 20000 and ShortCode <> "AAAA+0A": ShortCode = GeoCodedata[DataIndex][:7] CountHashDate = "" if ShortCode <> "AAAA+0A": CountAndDate = SearchLog(ShortCode) for Index in range(0, Len(CountAndDate): if (CountAndDate[Index] == " "): CountHashDate += "#" else: CountHashDate += CountAndDate[Index] LocationLine = GeoCodeData[DataIndex] + HASH + CountHashDate filehandle.write(LocationLine) DataIndex += 1 filehandle.close()
What you needed in this session
Cambridge’s own grade thresholds for 2021 Oct/Nov, Paper 2 · Variant 2. A higher threshold means an easier paper — the bar moves with how the cohort did.