Cambridge A Level Computer Science 9608 — 2020 Oct/Nov Paper 2 · Variant 2
9608/22/O/N/20 · 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 scheme24 pages
Answers below. Sit the paper first if you are practising.
























Paper as text
Question paper, page 1
Cambridge International AS & A Level This document has 20 pages. Blank pages are indicated. COMPUTER SCIENCE 9608/22 Paper 2 Fundamental Problem-solving and Programming Skills October/November 2020 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. * 7 1 8 7 0 7 4 0 4 6 * DC (CJ) 188580/2 © UCLES 2020 [Turn over
Question paper, page 2
2 9608/22/O/N/20 © UCLES 2020 1 (a) Algorithms usually consist of three different stages. One stage is INPUT. Name the other stages. 1 … 2 … [1] (b) An algorithm may be documented using different methods. These include structured English, a program flowchart, and pseudocode. State what a program designer represents using one or more of these methods. … … [2] (c) Programming languages support different data types. Complete the table by giving four different data types together with an example data value for each. Data type Example data value [4]
Question paper, page 3
3 9608/22/O/N/20 © UCLES 2020 [Turn over (d) Draw lines to connect each of the following computing terms with the appropriate description. Term Description Black-box testing A structure for the temporary storage of data File A method used when the structure of the program is unknown Assignment A method of setting the value of a variable Array A structure for the permanent storage of data [3] (e) A pseudocode algorithm assigns values to three variables as follows: FlagA TRUE FlagB FALSE FlagC TRUE Evaluate the expressions given in the following table: Expression Evaluates to NOT FlagB AND FlagC NOT (FlagB OR FlagC) (FlagA AND FlagB) OR FlagC NOT (FlagA AND FlagB) OR NOT FlagC [2]
Question paper, page 4
4 9608/22/O/N/20 © UCLES 2020 2 (a) The following pseudocode is an attempt to define an algorithm that takes two numbers as input and outputs the larger of the two numbers. DECLARE A, B : INTEGER INPUT A INPUT B IF A > B THEN OUTPUT A ELSE OUTPUT B ENDIF The algorithm needs to be amended to include the following changes: 1. Input three values, ensuring that each value input is unique. 2. Output the average. 3. Output the largest value. Write the pseudocode for the amended algorithm. … … … … … … … … … … … … … … … … … …
Question paper, page 5
5 9608/22/O/N/20 © UCLES 2020 [Turn over … … … … … … [6] (b) Complete the pseudocode expressions in the following table. Use only functions and operators described in the Appendix on pages 18–19. Expression Evaluates to "ALARM: " & … ("Time: 1202" , …) "ALARM: 1202" … ("Stepwise." , … , …) "wise" 1.5 * … ("OnePointFive") 18 … (27.5) "27.5" … (9, 4) 2 [5] (c) A problem may be decomposed into sub-tasks when designing an algorithm. Give three benefits of using sub-tasks. 1 … … 2 … … 3 … … [3]
Question paper, page 6
6 9608/22/O/N/20 © UCLES 2020 3 A car has the ability to detect a skid by monitoring the rate of rotation (the rotational speed) of each wheel. If the rate of rotation of any wheel is not within 10% of the average of all four wheels, the car skids. A function, CheckSkid(), is being developed. The function will: • simulate real-time data acquisition, by prompting for the input of four integer values in the range 0 to 1000 inclusive, representing the rate of rotation of each wheel • calculate the average value • check whether any individual value is more than 10% greater than the average or more than 10% less than the average • return TRUE if any individual value is more than 10% greater than the average or more than 10% less than the average and FALSE otherwise • output a suitable warning message. (a) Write program code for the function CheckSkid(). 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 7
7 9608/22/O/N/20 © UCLES 2020 [Turn over … … … … … … … … … … … … … … … … … [8] (b) Give two sets of test data that could be used to test the function. Test 1 – No skid detected Value1 Value2 Value3 Value4 Test 2 – Skid detected Value1 Value2 Value3 Value4 [2]
Question paper, page 8
8 9608/22/O/N/20 © UCLES 2020 4 (a) The following structured English describes an algorithm used to count the number of odd and even digits in an input sequence. 1. Initialise variables OddCount and EvenCount to zero. 2. Prompt and input an integer. 3. If the integer is not in the range 0 to 9 then go to step 7. 4. If the integer is an even number then add 1 to EvenCount. 5. Otherwise add 1 to OddCount. 6. Repeat from step 2. 7. Output "Same" if there are the same number of odd and even integers. 8. Output "Odd" if there are more odd than even integers. 9. Output "Even" if there are more even than odd integers. Draw a flowchart on the following page to represent the algorithm.
Question paper, page 9
9 9608/22/O/N/20 © UCLES 2020 [Turn over [7]
Question paper, page 10
10 9608/22/O/N/20 © UCLES 2020 (b) The following pseudocode is an attempt to check whether two equal-length strings consist of identical characters. Refer to the Appendix on pages 18–19 for the list of built-in functions and operators. FUNCTION Compare(String1, String2 : STRING) RETURNS BOOLEAN DECLARE x, y, Len1, Len2 : INTEGER DECLARE RetFlag : BOOLEAN DECLARE NextChar : CHAR DECLARE New : STRING Len1 LENGTH(String1) RetFlag TRUE FOR x 1 TO Len1 // for each char in String1 Len2 LENGTH(String2) NextChar MID(String1, x, 1) // get NextChar from String1 New "" FOR y 1 TO Len2 // for each char in String2 IF NextChar <> MID(String2, y, 1) // no match THEN New New & MID(String2, y, 1) // save this char from String2 ENDIF ENDFOR String2 New // replace String2 with New ENDFOR IF LENGTH(String2) <> 0 // anything left in String2 ? THEN RetFlag FALSE ENDIF RETURN RetFlag ENDFUNCTION
Question paper, page 11
11 9608/22/O/N/20 © UCLES 2020 [Turn over (i) Complete the trace table below by performing a dry run of the function when it is called as follows: Result Compare("SUB", "BUS") The first row has been completed for you. String1 String2 Len1 RetFlag x Len2 NextChar New y "SUB" "BUS" 3 TRUE 1 [5] (ii) State the value returned. … [1]
Question paper, page 12
12 9608/22/O/N/20 © UCLES 2020 (iii) There is an error in the algorithm, which means that under certain circumstances, the function will return an incorrect value. Describe the problem. Give two test strings that would demonstrate it. Problem … … … … … Test String1 … Test String2 … [2] (iv) Describe the modification that needs to be made to the algorithm to correct the error. Do not use pseudocode or program code in your answer. … … … … … [1] (v) State the name given to the type of testing that makes use of a trace table. … [1] (vi) State two features found in a typical Integrated Development Environment (IDE) that may be used for debugging a program. 1 … 2 … [2]
Question paper, page 13
13 9608/22/O/N/20 © UCLES 2020 [Turn over Question 5 begins on the next page.
Question paper, page 14
14 9608/22/O/N/20 © UCLES 2020 5 A hashtag is used on a social media network. A hashtag is a string consisting of a hash character ‘#’ followed by one or more alphanumeric characters. A program is being developed to monitor the use of hashtags. The program will include two global arrays each containing 10 000 elements: • A 1D array, TagString, of type STRING stores each hashtag in a single element. All unused array elements contain an empty string (""). • A 1D array, TagCount, of type INTEGER stores a count of the number of times each hashtag is used. The count value at a given index relates to the element stored at the corresponding index in the TagString array. The contents of the two arrays will be stored in a text file Backup.txt. The format of each line of the file is: <Hashtag><','><Count> For example: "#ComputerScienceClass,978" A developer has started to define the modules as follows: Module Description InitArrays() • Initialise the arrays SaveArrays() • The contents of the two arrays are stored in the text file Backup.txt Existing file contents will be overwritten • Each hashtag and count are stored in one line of the file, as in the example above • Unused TagString elements are not added to the file • Returns the total number of unused TagString elements LoadArrays() • Values from the text file Backup.txt are stored in the two arrays • The number of elements stored is returned (a) Write pseudocode for the module InitArrays(). … … … … … … … … … … [4]
Question paper, page 15
15 9608/22/O/N/20 © UCLES 2020 [Turn over (b) Write pseudocode for the module SaveArrays(). … … … … … … … … … … … … … … … … … … … … … … … … … … … … [8]
Question paper, page 16
16 9608/22/O/N/20 © UCLES 2020 (c) Write program code for the module LoadArrays(). The module description is repeated here for reference. Module Description LoadArrays() • Values from the text file Backup.txt are stored in the two arrays • The number of elements stored is returned You should assume: • each line of the file contains a string of the correct format and no validation checks are required • there are no more than 10 000 lines in the file. 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/20 © UCLES 2020 [Turn over … … … … … … … … … … … … [8]
Question paper, page 18
18 9608/22/O/N/20 © UCLES 2020 Appendix Built-in functions (pseudocode) Each function returns an error if the function call is not properly formed. LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of string 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 string "ABC" RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING returns rightmost x characters from ThisString Example: RIGHT("ABCDEFGH", 3) returns string "FGH" MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER returns the integer value representing the remainder when ThisNum is divided by ThisDiv Example: MOD(10,3) returns 1 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 string "BCD" DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER returns the integer value representing the whole number part of the result when ThisNum is divided by ThisDiv Example: DIV(10,3) returns 3 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
Question paper, page 19
19 9608/22/O/N/20 © UCLES 2020 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/20 © UCLES 2020 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 24 printed pages. © UCLES 2020 [Turn over Cambridge International AS & A Level COMPUTER SCIENCE 9608/22 Paper 2 Written Paper October/November 2020 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 2020 series for most Cambridge IGCSE™, Cambridge International A and AS Level and Cambridge Pre-U components, and some Cambridge O Level components.
Mark scheme, page 2
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 2 of 24 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.
Mark scheme, page 3
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 3 of 24 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 4
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 4 of 24 Question Answer Marks 1(a) One mark for both answers: • Process • Output Order not important. 1 1(b) One mark per bullet point (or equivalent) They all represent: • A solution to a problem / a way to perform a task • Expressed as a sequence / series of steps / stages / instructions 2 1(c) 1 mark per row to max 4 marks Example answers: Data type Example data value BOOLEAN FALSE STRING "Happy" INTEGER 18 REAL 31234.56 CHAR 'H' DATE 10/01/2019 Each row must be a different data type together with an appropriate value 4
Mark scheme, page 5
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 5 of 24 Question Answer Marks 1(d) Max 3 marks, one mark for each correct line 3
Mark scheme, page 6
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 6 of 24 Question Answer Marks 1(e) 1 mark for two rows correct, 2 marks for all rows correct. Expression Evaluates to NOT FlagB AND FlagC TRUE NOT (FlagB OR FlagC) FALSE (FlagA AND FlagB) OR FlagC TRUE NOT (FlagA AND FlagB) OR NOT FlagC TRUE 2
Mark scheme, page 7
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 7 of 24 Question Answer Marks 2(a) DECLARE A, B, C : INTEGER DECLARE Average : REAL INPUT A REPEAT INPUT B UNTIL B <> A REPEAT INPUT C UNTIL C <> A AND C <> B Average ← (A + B + C) / 3 OUTPUT Average IF A > B AND A > C THEN OUTPUT A ELSE IF B > A AND B > C THEN OUTPUT B ELSE OUTPUT C ENDIF ENDIF Mark as follows: 1 Declaration of all variables used (at least A, B and C) 2 Uniqueness test on A, B and C 3 Loop(s) to repeat until three unique values have been entered 4 Calculation of average value 5 Determine the largest value 6 Output of average value and largest value 6
Mark scheme, page 8
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 8 of 24 Question Answer Marks 2(b) One mark per correct row (Completed parts shown in bold) Expression Evaluates to "ALARM: " & RIGHT("Time: 1202",4) "ALARM: 1202" MID("Stepwise.",5, 4) "wise" 1.5 * LENGTH("OnePointFive") 18 NUM_TO_STRING(27.5) "27.5" DIV(9, 4) 2 5 2(c) One mark per point, example points: 1 Subtasks make the solution more manageable // make the algorithm easier to follow 2 A subtask makes the problem easier to solve / design / program than the whole task 3 A subtask is useful when a part of the algorithm is repeated 3
Mark scheme, page 9
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 9 of 24 Question Answer Marks 3(a) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. FUNCTION CheckSkid() RETURNS BOOLEAN DECLARE Rot : ARRAY[1:4] OF INTEGER DECLARE Average : REAL DECLARE ThisRot : INTEGER DECLARE Danger : BOOLEAN FOR Index ← 1 TO 4 REPEAT OUTPUT "Input Rotation speed for wheel ",Index INPUT ThisRot UNTIL ThisRot >= 0 AND ThisRot <= 1000 Rot[Index] ← ThisRot ENDFOR Average ← (Rot[1] + Rot[2] + Rot[3] + Rot[4]) / 4 Danger ← FALSE FOR Index ← 1 TO 4 IF Rot[Index] > (Average * 1.1) OR Rot[Index] < (Average * 0.9) THEN Danger ← TRUE ENDIF ENDFOR IF Danger = TRUE THEN OUTPUT "Skid Danger" ENDIF RETURN Danger ENDFUNCTION 8
Mark scheme, page 10
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 10 of 24 Question Answer Marks 3(a) 1 mark for each of the following: 1 Function heading and ending 2 Declare local integers for 4 rotation values and a real for the average / tolerance 3 Prompt and input four rotation values 4 Validate each input value in a loop 5 Calculate average rotation AND calculate acceptable max and min (or single tolerance, or alternative method) 6 Compare rotational value of each wheel 7 Test if rotational value of (each) wheel is within the acceptable range 8 Output a warning message and return the correct value in all cases 3(b) Example answers: Test1 – No Skid detected Value 1 Value2 Value 3 Value 4 100 100 100 100 One of: Test2 – Skid detected (one wheel too fast) Value 1 Value2 Value 3 Value 4 100 100 100 160 Test2 – Skid detected (one wheel too slow) Value 1 Value2 Value 3 Value 4 100 100 100 40 Independent marks: one mark each for Test1 and Test 2 2
Mark scheme, page 11
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 11 of 24 Question Answer Marks 4(a) Outputs from conditional diamond must have at least one label 7 Mark as follows: • One mark for START and END • One mark per area outlined
Mark scheme, page 12
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 12 of 24 Question Answer Marks 4(b)(i) One mark per region as indicated. Strin g1 String 2 Len1 RetFl ag X Len 2 NextCh ar New y "SUB" "BUS" 3 TRUE 1 3 'S' "" "B" 1 "BU" 2 3 "BU" 2 2 'U' "" 1 "B" 2 "B" 3 1 'B' "" 1 "" 5
Mark scheme, page 13
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 13 of 24 Question Answer Marks 4(b)(ii) TRUE 1 4(b)(iii) One mark for explanation of problem, one mark for test strings Problem: • The inner FOR loop removes ALL characters from String2 that match the current character from String1 and not just one instance Test Strings: • ‘SAME’ and ‘MASS’ (for example) 2 4(b)(iv) The inner FOR loop should only remove one instance of the character from String2 1 4(b)(v) • Dry run // White-box testing 1 4(b)(vi) Max 2 marks, features include: • Single stepping • Breakpoints • Variable and expressions report window • Syntax error highlighting 2
Mark scheme, page 14
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 14 of 24 Question Answer Marks 5(a) PROCEDURE InitArrays() DECLARE Index : INTEGER FOR Index ← 1 TO 10000 TagString[Index] ← "" TagCount[Index] ← 0 ENDFOR ENDPROCEDURE 1 mark for each of the following: 1 Procedure heading and ending (as shown) 2 Declaration of Index (e.g.) as integer 3 Loop for 10000 iterations 4 Initialise TagString element to "" 4
Mark scheme, page 15
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 15 of 24 Question Answer Marks 5(b) FUNCTION SaveArrays() RETURNS INTEGER DECLARE Index, NumUnused : INTEGER DECLARE FileString : STRING CONSTANT COMMA = ',' NumUnused ← 0 OPEN "Backup.txt" FOR WRITE FOR Index ← 1 to 10000 IF TagString[Index] <> "" THEN FileString ← TagString[Index] & COMMA & NUM_TO_STRING(TagCount[Index]) WRITEFILE "Backup.txt", FileString ELSE NumUnused ← NumUnused + 1 ENDIF ENDFOR CLOSEFILE "Backup.txt" RETURN NumUnused ENDFUNCTION 1 mark for each of the following: 1 Function heading and ending 2 Open the file Backup.txt in write mode and close file 3 Loop through 10000 elements 4 Test if TagString[Index] is "" in a loop 5 If not then form FileString from array elements with separator and using NUM_TO_STRING()in a loop 6 Write string to file in a loop 7 Count the number of unused elements 8 Return NumUnused not in a loop 8
Mark scheme, page 16
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 16 of 24 Question Answer Marks 5(c) ‘Pseudocode’ solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. Max 8 marks from 9 available mark points FUNCTION LoadArrrays() RETURNS INTEGER DECLARE ArrayIndex, Index, CountLen, Count : INTEGER DECLARE FileString, HashTag : STRING CONSTANT COMMA = ',' ArrayIndex ← 0 // first element OPEN "Backup.txt" FOR READ WHILE NOT EOF("Backup.txt") READFILE "Backup.txt", FileString Index ← 1 HashTag ← "" WHILE MID(FileString, Index, 1) <> COMMA // hashtag HashTag ← HashTag & MID(FileString, Index, 1) Index ← Index + 1 ENDWHILE TagString[ArrayIndex] ← HashTag CountLen ← LENGTH(FileString) - LENGTH(HashTag) - 1 Count ← STR_TO_NUM(RIGHT(FileString, CountLen)) // count TagCount[ArrayIndex] ← Count ArrayIndex ← ArrayIndex + 1 ENDWHILE CLOSE "Backup.txt" RETURN ArrayIndex ENDFUNCTION 8
Mark scheme, page 17
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 17 of 24 Question Answer Marks 5(c) 1 mark for each of the following: 1 Function heading and ending 2 Declare and initialise ArrayIndex (or equivalent name) 3 Open the file Backup.txt in read mode and close the file 4 Loop until end of the Backup.txt file // string read is null 5 Read a line from the file in a loop 6 Extract hashtag and count in a loop 7 Store hashtag in TagString array and count in TagCount array after type conversion 8 Increment ArrayIndex in a loop 9 Return number of array elements *** End of Mark Scheme – example program code solutions follow ***
Mark scheme, page 18
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 18 of 24 Appendix: Program Code Example Solutions Q3 (a): Visual Basic Function CheckSkid() As Boolean Dim Rot(3) As Integer Dim Average As Double Dim ThisRot As Integer Dim Danger As Boolean For Index = 0 To 3 Do Console.Writeline("Enter Wheel Rotation Speed: " ThisRot = Console.Readline() Loop Until ThisRot >= 0 And ThisRot <= 1000 Rot(Index) = ThisRot Next Average = (Rot(0) + Rot(1) + Rot(2) + Rot(3)) / 4 Danger = FALSE For Index = 0 TO 3 If Rot(Index) > (Average * 1.1) OR Rot(Index) < (Average * 0.9) Then Danger = TRUE End If Next If Danger = TRUE Then Console.Writeline("Skid Danger") Else Console.Writeline("No Skid Danger") End if RETURN Danger End Function
Mark scheme, page 19
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 19 of 24 Q3 (a): Pascal Function CheckSkid() : Boolean; var Rot : array [1..4] of integer; Average : Real; ThisRot : Integer; Index : Integer; Danger : Boolean; For Index := 1 to 4 do begin repeat write('Enter rotation speed : '); readln(ThisRot); until (ThisRot >= 0) And (ThisRot <= 1000); Rot[Index] := ThisRot; end; Average := (Rot[1] + Rot[2] + Rot[3] + Rot[4]) / 4; Danger := FALSE; For Index := 1 to 4 do begin If (Rot[Index] > (Average * 1.1)) OR (Rot[Index] < (Average * 0.9)) then Danger := TRUE; end; If Danger = TRUE then writeln('Skid Danger') Else writeln('No Skid Danger'); CheckSkid := Danger; end;
Mark scheme, page 20
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 20 of 24 Q3 (a): Python def CheckSkid(): # Rot[3] As Integer # Average As Real # ThisRot As Integer # Danger As Boolean Rot = [0, 0, 0, 0] for Index in range(0, 4): while True: ThisRot = float(input("Enter the rotation speed of the wheel: ")) if ThisRot >= 0 and ThisRot <= 1000: break Rot[Index] = ThisRot Next Average = (Rot[0] + Rot[1] + Rot[2] + Rot[3]) / 4 Danger = False for Index in range(0, 4): if Rot[Index] > (Average * 1.1) or Rot[Index] < (Average * 0.9): Danger = True If Danger == True: print("Skid Danger") else: print("No Skid Danger") return Danger
Mark scheme, page 21
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 21 of 24 Q5 (c): Visual Basic Function LoadArrrays () As Integer Dim ArrayIndex, Index, CountLen, Count As Integer Dim FileString, HashTag As String Dim File As New StreamReader("Backup.txt") Const COMMA = ',' ArrayIndex = 0 ' First element Do While File.Peek <> -1 FileString = File.ReadLine() Index = 1 HashTag = "" Do While Mid(FileString, Index, 1) <> COMMA ' the hashtag HashTag = HashTag & MID(FileString, Index, 1) Index = Index + 1 Loop TagString(arrayIndex) = HashTag CountLen = Len(fileString) – Len(HashTag) – 1 Count = CInt(Right(FileString, CountLen)) ' the count TagCount(ArrayIndex) = Count ArrayIndex = ArrayIndex + 1 Loop File.Close Return ArrayIndex End Function
Mark scheme, page 22
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 22 of 24 Q5 (c): Pascal Function LoadArrrays () : Integer; var ArrayIndex, Index, CountLen, Count : Integer; FileData, HashTag : String; Backup : Textfile; const COMMA = ','; begin assignfile(Backup, 'Backup.txt'); reset(File); ArrayIndex := 0; //First element while not EOF(File) do begin readln(Backup, FileData); Index := 1; HashTag := ""; while midstr(FileData, Index, 1) <> COMMA do // the hashtag begin HashTag := HashTag + midstr(FileData, Index, 1); Index := Index + 1; end; TagString[ArrayIndex] := HashTag; CountLen := length(FileData) – length(HashTag) – 1; Count := strtoint(RightStr(FileData, CountLen)); // the count TagCount[ArrayIndex] := Count; ArrayIndex := ArrayIndex + 1; end; closefile(File);
Mark scheme, page 23
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 23 of 24 LoadArrays := ArrayIndex; end;
Mark scheme, page 24
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 24 of 24 Q5 (c): Python def LoadArrays (): # ArrayIndex, Index, CountLen, Count As Integer # FileString, HashTag As String # File As StreamReader("Backup.txt") COMMA = ',' File = open("Backup.txt", "r") ArrayIndex = 0 #First element for FileString in File: Index = 0 HashTag = "" while FileString[Index] != COMMA: # the hashtag HashTag = HashTag + FileString[Index] Index = Index + 1 TagString[ArrayIndex] = HashTag Count = int(FileString[Index+1:]) # the count TagCount[ArrayIndex] = Count ArrayIndex = ArrayIndex + 1 File.close() return ArrayIndex
What you needed in this session
Cambridge’s own grade thresholds for 2020 Oct/Nov, Paper 2 · Variant 2. A higher threshold means an easier paper — the bar moves with how the cohort did.