Cambridge A Level Computer Science 9608 — 2020 Oct/Nov Paper 2 · Variant 1
9608/21/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 scheme22 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. DC (LK) 188573/3 © UCLES 2020 [Turn over COMPUTER SCIENCE 9608/21 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. * 6 3 4 1 3 6 2 7 4 2 *
Question paper, page 2
2 9608/21/O/N/20 © UCLES 2020 1 (a) Translation is one stage of the program development cycle. State three other stages. 1 … 2 … 3 … [3] (b) Define the following types of maintenance. Corrective maintenance … … … Adaptive maintenance … … … [2] (c) Experienced programmers have a transferable skill. Explain how this skill might be useful for a programmer. … … … … [2] (d) Jackie has written a program and has used the identifier names I1, I2, and I3. Explain why this is not good practice. … … … … [2]
Question paper, page 3
3 9608/21/O/N/20 © UCLES 2020 [Turn over (e) A pseudocode algorithm assigns values to three variables as follows: GateOpen FALSE Alarm TRUE PowerFail TRUE Evaluate the expressions given in the following table: Expression Evaluates to Alarm OR NOT PowerFail NOT (Alarm AND PowerFail) (GateOpen OR Alarm) AND PowerFail (GateOpen AND Alarm) OR NOT PowerFail [2]
Question paper, page 4
4 9608/21/O/N/20 © UCLES 2020 2 (a) User names are stored in a text file. Each line of the file represents one name. Before a new user name can be issued, a check has to be made to ensure that the new name is unique. Use structured English to describe an algorithm that would prompt and input a new user name and output a message to indicate whether or not it is unique. … … … … … … … … … … … … … … … [6] (b) Complete the pseudocode expressions in the following table. Use only the functions and operators described in the Appendix on pages 18–19. Expression Evaluates to … ("Stepwise" , …) & "art" "Start" … ("Concatenate" , … , …) "ten" 2 * … ("Kipper") 12 TRUE … FALSE TRUE … (9, 2) 1 [5]
Question paper, page 5
5 9608/21/O/N/20 © UCLES 2020 [Turn over (c) Study the following pseudocode. Line numbers are given for reference only. 01 PROCEDURE StringClean(InString : STRING) 02 03 DECLARE NextChar : CHAR 04 DECLARE OutString : STRING 05 DECLARE Index : INTEGER 06 07 OutString "" 08 09 FOR Index 1 TO LENGTH(InString) 10 11 NextChar MID(InString, Index, 1) 12 NextChar LCASE(NextChar) 13 14 IF NextChar >= 'a' AND NextChar <= 'z' 15 THEN 16 OutString OutString & NextChar 17 ENDIF 18 19 ENDFOR 20 21 OUTPUT OutString 22 23 ENDPROCEDURE Complete the following table by entering an appropriate answer. Answer The name for the type of loop used A line number of a selection statement The scope of OutString The name of a function that is called A line number containing a logical operator [5]
Question paper, page 6
6 9608/21/O/N/20 © UCLES 2020 3 The procedure OutputLines() outputs a number of lines from a text file. An example of the use of the procedure is given by the following pseudocode: CALL OutputLines(FileName, StartLine, NumberLines) Parameter Data type Description FileName STRING The name of the text file StartLine INTEGER The number of the first line to be output NumberLines INTEGER The number of lines to be output The procedure is tested using the file MyFile.txt that contains 100 lines of text. The procedure gives the expected result when called as follows: CALL OutputLines("MyFile.txt", 1, 10) (a) The procedure is correctly called with three parameters of the appropriate data types, but the procedure does not give the expected result. Give three different reasons why this might happen. 1 … … 2 … … 3 … … [3]
Question paper, page 7
7 9608/21/O/N/20 © UCLES 2020 [Turn over (b) Write program code for the procedure OutputLines(). Note: Parameter validation is not necessary. 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 8
8 9608/21/O/N/20 © UCLES 2020 (c) A program is compiled without producing any errors. (i) Describe one type of error that the program could still contain. … … … … [2] (ii) Give two techniques that may be used to identify an error of the type given in part (c)(i). Technique 1 … … Technique 2 … … [2] (d) State two reasons why the use of library subroutines can be a benefit in program development. 1 … … 2 … … [2]
Question paper, page 9
9 9608/21/O/N/20 © UCLES 2020 [Turn over BLANK PAGE
Question paper, page 10
10 9608/21/O/N/20 © UCLES 2020 4 A function, FormOut(), takes an integer parameter in the range 0 to 999 999 and returns a formatted string depending on two other parameter values. Formatting may incorporate the use of: • A prefix string to be added before the integer value (e.g. '$' or "Total: ") • A comma as a thousand-separator (e.g. "1,000") The function will be called as follows: MyString FormOut(Number, Prefix, AddComma) Parameter Data type Description Number INTEGER The positive integer value to be formatted. Prefix STRING A string that will appear in front of the numeric value. Set to an empty string if no prefix is required. AddComma BOOLEAN TRUE if a comma is required in the formatted string. FALSE if a comma is not required in the formatted string. (a) Fill in the tables to show two tests that could be carried out to test different aspects of the function. Give the expected result for each test. TEST 1 Parameter Value Expected return string: Number Prefix … AddComma TEST 2 Parameter Value Expected return string: Number Prefix … AddComma [4]
Question paper, page 11
11 9608/21/O/N/20 © UCLES 2020 [Turn over (b) Write pseudocode for the function FormOut(). Refer to the Appendix on pages 18–19 for the list of built-in functions and operators. … … … … … … … … … … … … … … … … … … … … … … … … … … [8]
Question paper, page 12
12 9608/21/O/N/20 © UCLES 2020 5 A message may contain several hashtags. A hashtag is a string consisting of a hash character ‘#’, followed by one or more alphanumeric characters. A hashtag may be terminated by a space character, the start of the next hashtag, any other non-alphanumeric character, or by the end of the message. For example, the following message contains three hashtags: "#Error27 is the result of #PoorPlanning by the #Designer" The hashtags in the message are "#Error27", "#PoorPlanning" and "#Designer". A program is being developed to process a message and extract each hashtag. A global 1D array of strings, TagString, will store each hashtag in a single element. Unused array elements will contain an empty string. The array will contain 10 000 elements. A developer has started to define the modules as follows: Module Description GetStart() • Called with two parameters: • a message string • an integer giving the number of the required hashtag. For example, GetStart(Message, 3) would search for the third hashtag in the string Message • Returns an integer value representing the start position of the hashtag in the message string, or value −1 if that hashtag does not exist GetTag() • Called with two parameters: • a message string • an integer giving the hashtag start position within the message • Returns the hashtag or an empty string if the character in the message at the hashtag start position is not '#' GetIndex() • Called with a hashtag as a parameter • Returns the index position of the hashtag in array TagString • Returns the value −1 if the hashtag is not present in the array
Question paper, page 13
13 9608/21/O/N/20 © UCLES 2020 [Turn over (a) Write pseudocode for the module GetIndex(). … … … … … … … … … … … … … … … … … … … … … … … … … … … [6]
Question paper, page 14
14 9608/21/O/N/20 © UCLES 2020 (b) Write pseudocode for the module GetStart(). The module description is repeated here for reference. Module Description GetStart() • Called with two parameters: • a message string • an integer giving the number of the required hashtag. For example, GetStart(Message, 3) would search for the third hashtag in the string Message • Returns an integer value representing the start position of the hashtag in the message string, or value −1 if that hashtag does not exist … … … … … … … … … … … … … … … … … … … … … … … [6]
Question paper, page 15
15 9608/21/O/N/20 © UCLES 2020 [Turn over BLANK PAGE
Question paper, page 16
16 9608/21/O/N/20 © UCLES 2020 (c) Write program code for the module GetTag(). The module description is repeated here for reference. Module Description GetTag() • Called with two parameters: • a message string • an integer giving the hashtag start position within the message • Returns the hashtag or an empty string if the character in the message at the hashtag start position is not '#' 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/21/O/N/20 © UCLES 2020 [Turn over … … … … … … … … … … … … … … [8]
Question paper, page 18
18 9608/21/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" INT(x : REAL) RETURNS INTEGER returns the integer part of x Example: INT(27.5415) returns 27 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" 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' 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"
Question paper, page 19
19 9608/21/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/21/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 22 printed pages. © UCLES 2020 [Turn over Cambridge International AS & A Level COMPUTER SCIENCE 9608/21 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/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 2 of 22 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/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 3 of 22 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/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 4 of 22 Question Answer Marks 1(a) One mark per bullet point, max 3 marks • Analysis / Problem Definition • Design • Code // Implement • Test 3 1(b) One mark per bullet point • Corrective: changes to correct a bug / problem / error in the program • Adaptive: changes due to change in specification / requirements / legislation / available technology 2 1(c) One mark per bullet point • The knowledge / experience / understanding of one programming language • Can be applied to another / unfamiliar language // will help recognise control structures in another / unfamiliar language // will help them learn a new language 2 1(d) One mark per bullet point • Names are not meaningful (or equivalent) // name does not reflect the identifier's use// easy to use the wrong name • Makes the program more difficult to understand / debug / modify / test 2
Mark scheme, page 5
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 5 of 22 Question Answer Marks 1(e) 1 mark for any two rows correct, 2 marks for all rows correct. Expression Evaluates to Alarm OR NOT PowerFail TRUE NOT (Alarm AND PowerFail) FALSE (GateOpen OR Alarm) AND PowerFail TRUE (GateOpen AND Alarm) OR NOT PowerFail FALSE 2 2(a) One mark per step (or equivalent) to max 6 marks 1 Prompt / output string and input the new user name 2 OPEN the file in read mode and close the file 3 Initialise a Boolean variable, e.g. UniqueFlag to TRUE 4 LOOP while not End of File (AND new user name not found) 5 Read a line from the file 6 If line is same as new user name (then set termination condition else repeat from step 4) 7 IF UniqueFlag is TRUE then output ‘Unique’ otherwise output ‘Not unique’ 6
Mark scheme, page 6
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 6 of 22 Question Answer Marks 2(b) One mark per row (for expression completed by addition of text shown in bold): Expression Evaluates to LEFT("Stepwise", 2) & "art" "Start" MID("Concatenate", 6, 3) "ten" 2 * LENGTH("Kipper") 12 TRUE OR FALSE TRUE MOD(9, 2) 1 5 2(c) One mark per row: Answer The name for the type of loop used Count-controlled A line number of a selection statement 14 The scope of OutString Local The name of a function that is called LENGTH // MID // LCASE A line number containing a logical operator 14 5
Mark scheme, page 7
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 7 of 22 Question Answer Marks 3(a) Reasons include: 1 FileName given does not exist / access denied / file is of wrong type 2 The StartLine line does not exist in file 3 There are less than NumLines lines after the StartLine 4 Code does not read the required number of lines (description of logical error) One mark per point to 3 max marks 3 3(b) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. PROCEDURE OutputLines(FileName: STRING, StartLine, NumLines: INTEGER) DECLARE FileData : STRING DECLARE Count : INTEGER OPENFILE FileName FOR READ FOR Count ← 1 TO StartLine + NumLines - 1 READFILE FileName, FileData IF Count >= StartLine THEN OUTPUT FileData ENDIF ENDFOR CLOSE FileName ENDPROCEDURE 7
Mark scheme, page 8
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 8 of 22 Question Answer Marks 3(b) 1 mark for each of the following: 1 Procedure heading (including parameters) and ending 2 Declare local variable for FileData and Count 3 Open FileName in READ mode and subsequent Close 4 Loop 5 Read Filedata in a loop 6 Check if current line is to be printed (i.e. if Count in range) 7 If so Output FileData in a loop Alternative 'Seek' solution PROCEDURE OutputLines(FileName: STRING, StartLine, NumLines: INTEGER) DECLARE FileData : STRING DECLARE Count : INTEGER OPENFILE FileName FOR READ FOR Count ← 1 TO StartLine - 1 // read up to StartLine READFILE FileName, FileData ENDFOR FOR Count ← 1 TO NumLines // then Output NumLines lines from here READFILE FileName, FileData OUTPUT FileData ENDFOR CLOSE FileName ENDPROCEDURE
Mark scheme, page 9
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 9 of 22 Question Answer Marks 3(b) 1 mark for each of the following: 1 Procedure heading (including parameters) and ending 2 Declare local variable for FileData and Count 3 Open FileName in READ mode and subsequent close 4 First loop to read up to StartLine 5 Read Filedata in a loop 6 Second loop for Numlines times 7 Read and Output Filedata in a loop 3(c)(i) One mark for type plus one for corresponding explanation to max 2 marks • Logic(al) Error • The program does not perform as expected (or by example) OR • Run-time error • The program executes an invalid instruction / attempts to divide by zero // the program crashes Award mark for 'description' without type 2 3(c)(ii) Max 2 marks, techniques include: • White-box testing // use of suitable test data • Dry-run / use of a trace table • IDE features such as breakpoints, stepping, watch windows 2 3(d) Max 2 marks, reasons include: • They are tried and tested / free from bugs • They are already available so their use saves development time • Perform a function which the programmer does not have the skills to write 2
Mark scheme, page 10
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 10 of 22 Question Answer Marks 4(a) There are many correct answers. There are eight relevant combinations (2 × 2 × 2 options) as follows: Parameter Option A Option B Number <= 999 >= 1000 Prefix Empty String Non-empty String AddComma TRUE FALSE Tests must be different by at least one option For each test (2 in total): • One mark for parameter values • One mark for expected return 4
Mark scheme, page 11
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 11 of 22 Question Answer Marks 4(b) FUNCTION FormOut(Num : INTEGER, Prefix : STRING, AddComma : BOOLEAN) RETURNS STRING DECLARE OutString : STRING DECLARE ThouDigits : INTEGER // just to simplify later expression CONSTANT COMMA = ',' OutString ← NUM_TO_STRING(Num) // convert integer to string IF AddComma = TRUE THEN NumLength ← LENGTH(OutString) IF NumLength > 3 THEN ThouDigits ← NumLength - 3 OutString ← LEFT(OutString, ThouDigits) & COMMA & RIGHT(OutString, 3) ENDIF ENDIF OutString ← Prefix & OutString // concatenate string with Prefix RETURN OutString ENDFUNCTION 8
Mark scheme, page 12
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 12 of 22 Question Answer Marks 4(b) 1 mark for each of the following: 1 Functon heading and ending (inc parameters) and return data type 2 Use of NUM_TO_STRING 3 Test AddComma and if TRUE … 4 Test number of digits in Num 5 Split NUM_TO_STRING(Num) and 6 Form OutString with inserted comma 7 Concatenate the Prefix with OutString 8 Return OutString MP3 and MP4 could easily appear in reverse sequence
Mark scheme, page 13
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 13 of 22 Question Answer Marks 5(a) FUNCTION GetIndex(HashTag : STRING) RETURNS INTEGER DECLARE Index : INTEGER DECLARE Found : BOOLEAN Index ← 1 Found ← FALSE WHILE Index <= 10000 AND Found = FALSE IF TagString[Index] = HashTag THEN Found ← TRUE ELSE Index ← Index + 1 ENDIF ENDWHILE IF Found = FALSE THEN Index ← -1 ENDIF RETURN Index ENDFUNCTION 1 mark for each of the following: 1 Declaration of Index as Integer and Found as Boolean // RetIndex as Integer if this used for loop termination 2 Initialisation of Index 3 Conditional loop for 10 000 elements while HashTag not found 4 Compare HashTag with element from TagString array in a loop 5 Set termination condition / store current index if match found in a loop 6 Return Integer value 6
Mark scheme, page 14
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 14 of 22 Question Answer Marks 5(b) FUNCTION GetStart(Message : STRING, TagNum : INTEGER) RETURNS INTEGER DECLARE MessLength, Index, StartPos, Count: INTEGER CONSTANT HASH = '#' Count ← 0 StartPos ← -1 Index ← 1 MessLength ← LENGTH(Message) WHILE Index <= MessLength AND Count < TagNum IF MID(Message, Index, 1) = HASH THEN Count ← Count + 1 IF Count = TagNum THEN StartPos ← Index // found the required hashtag ENDIF ENDIF Index ← Index + 1 ENDWHILE RETURN StartPos ENDFUNCTION 1 mark for each of the following: 1 Conditional loop until required hashtag found or end of message encountered 2 Extract a character and compare with hash character in a loop 3 If hash found, increment Count / decrement TagNum 4 Test if this is the required hashtag 5 Set termination condition / store current index if match found in a loop 6 Return integer value from correct function declaration 6
Mark scheme, page 15
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 15 of 22 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 mark points FUNCTION GetTag(Message : STRING, StartPos : INTEGER) RETURNS STRING DECLARE Index : INTEGER DECLARE MyString : STRING DECLARE NextChar, TestChar : CHAR DECLARE EndTag : BOOLEAN CONSTANT HASH = '#' CONSTANT SPACE = ' ' MyString ← "" EndTag ←FALSE IF MID(Message, StartPos, 1) = HASH // check first char is HASH THEN MyString ← HASH // store HASH as first char of hashtag Index ← StartPos + 1 // start loop with first char after # WHILE Index <= LENGTH(Message) AND EndTag = FALSE NextChar ← MID(Message, Index, 1) TestChar ← UCASE(NextChar) IF TestChar = SPACE OR TestChar = HASH __ OR NOT ((TestChar >= 'A' AND TestChar <= 'Z') __ OR (TestChar >= '0' AND TestChar <= '9')) THEN EndTag ← TRUE ELSE MyString ← MyString & NextChar ENDIF Index ← Index + 1 ENDWHILE 8
Mark scheme, page 16
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 16 of 22 Question Answer Marks 5(c) ENDIF IF LENGTH(MyString) = 1 THEN MyString = "" // when Hash is last char in string ENDIF RETURN MyString ENDFUNCTION 1 mark for each of the following: 1 Function heading and ending including parameters and return data type (not python) 2 Declaration and initialisation of return string (MyString) 3 Test for valid start character 4 Loop from StartPos+1 while not end of message 5 Extract NextChar 6 Test if NextChar is terminator character in a loop 7 If NextChar not a terminator then concatenate with MyString in a loop 8 Cater for MyString only containing a Hash character (return empty string) 9 Return MyString *** End of Mark Scheme – example program code solutions follow ***
Mark scheme, page 17
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 17 of 22 Program Code Example Solutions Q3 (b): Visual Basic Sub OutputLines(FileName As String, StartLine As Integer, NumLines As Integer) Dim FileData As String Dim Count As Integer Dim File As New StreamReader(FileName) For Count = 1 To StartLine + NumLines - 1 FileData = File.ReadLine() If Count >= StartLine Then Console.Writeline(FileData) Next File.Close End Sub
Mark scheme, page 18
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 18 of 22 Q3 (b): Pascal Procedure OutputLines(FileName : string; StartLine : integer; NumLines : integer); var FileData : string; Count : integer; ThisFile : textfile; begin assignfile(ThisFile, FileName); reset(ThisFile); for Count := 1 to StartLine + NumLines - 1 do begin readln(ThisFile, Filedata); if Count >= StartLine then writeln(Filedata); end; closefile(ThisFile); end; Q3 (b): Python def OutputLines(FileName, StartLine, NumLines): #Count as INTEGER #File as FILEOBJECT #FileData as STRING Count = 1 File = open(FileName, "r") for Count in range(1, StartLine + NumLines): FileData = File.readline() if Count >= StartLine: print(FileData) File.close()
Mark scheme, page 19
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 19 of 22 Q5 (c): Visual Basic Function GetTag(Message As String, StartPos As Integer) As String Dim NumChars, Index As Integer Dim MyString As String Dim NextChar, TestChar As Char Dim EndTag As Boolean Const HASH = "#" Const SPACE = " " MyString = "" EndTag = FALSE NumChars = Len(Message) If Mid(Message, StartPos, 1) = HASH Then 'Check for valid hashtag MyString = HASH Index = StartPos + 1 Do While Index <= NumChars And EndTag = FALSE NextChar = Mid(Message, Index, 1) TestChar = Ucase(NextChar) If NextChar = SPACE Or NextChar = HASH __ Or Not ((TestChar >= 'A' And TestChar <= 'Z') Or __ (TestChar >= '0' And TestChar <= '9')) Then EndTag = TRUE Else MyString = MyString & NextChar End If Index = Index + 1 Loop End If If MyString = HASH Then MyString = "" 'When Hash is last char in message Return MyString End Function
Mark scheme, page 20
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 20 of 22 Q5 (c): Pascal Function GetTag(Message : string, StartPos : integer) : String; var NumChars, Index : Integer; MyString: String; NextChar, TestChar : String; EndTag : Boolean; const HASH = '#'; SPACE = ' '; MyString = ''; EndTag = FALSE; NumChars := Length(Message); if midstr(Message, StartPos, 1) = HASH then // Check for valid hashtag begin MyString:= HASH; Index := StartPos + 1; while Index <= NumChars And EndTag = FALSE do; begin NextChar := Midstr(Message, Index, 1); TestChar := UpperCase(NextChar); If NextChar = SPACE OR NextChar = HASH Or Not ((TestChar >= 'A' And TestChar <= 'Z') Or TestChar >= '0' And TestChar <= '9')) then EndTag := TRUE; Else MyString:= MyString + NextChar; Index := Index + 1; end; end;
Mark scheme, page 21
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 21 of 22 If MyString = HASH then MyString := ""; // When Hash is last char in message GetTag := MyString; end; Q5 (c): Python def GetTag(Message, StartPostion): #EndTag as BOOLEAN #Index as INTEGER #MyString as STRING #NextChar, TestChar as CHAR HASH = '#' SPACE = ' ' MyString = "" EndTag = FALSE NumChars = len(Message) if message[Index] == "#": MyString = HASH Index = StartPos + 1 while Index <= NumChars And EndTag == FALSE: NextChar = Message[Index] TestChar = NextChar.upper() if NextChar == SPACE OR NextChar == HASH or not ((TestChar >= 'A' and TestChar <= 'Z') or TestChar >= '0' and TestChar <= '9')): EndTag = True else: MyString = MyString + NextChar Index = Index + 1
Mark scheme, page 22
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED October/November 2020 © UCLES 2020 Page 22 of 22 if MyString = HASH: MyString = "" #When Hash is last char in message return HashTag
What you needed in this session
Cambridge’s own grade thresholds for 2020 Oct/Nov, Paper 2 · Variant 1. A higher threshold means an easier paper — the bar moves with how the cohort did.