Cambridge A Level Computer Science 9608 — 2019 May/June Paper 2 · Variant 3

9608/23/M/J/19 · 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.

← All Computer Science papersWhat was in this paper?

Question paper20 pages

Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 1 of 20
Page 1 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 2 of 20
Page 2 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 3 of 20
Page 3 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 4 of 20
Page 4 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 5 of 20
Page 5 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 6 of 20
Page 6 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 7 of 20
Page 7 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 8 of 20
Page 8 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 9 of 20
Page 9 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 10 of 20
Page 10 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 11 of 20
Page 11 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 12 of 20
Page 12 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 13 of 20
Page 13 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 14 of 20
Page 14 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 15 of 20
Page 15 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 16 of 20
Page 16 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 17 of 20
Page 17 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 18 of 20
Page 18 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 19 of 20
Page 19 of 20
Cambridge A Level Computer Science 9608 2019 May/June Paper 2 · Variant 3 question paper, page 20 of 20
Page 20 of 20

Mark scheme13 pages

Answers below. Sit the paper first if you are practising.

Mark scheme, page 1 of 13
Page 1 of 13
Mark scheme, page 2 of 13
Page 2 of 13
Mark scheme, page 3 of 13
Page 3 of 13
Mark scheme, page 4 of 13
Page 4 of 13
Mark scheme, page 5 of 13
Page 5 of 13
Mark scheme, page 6 of 13
Page 6 of 13
Mark scheme, page 7 of 13
Page 7 of 13
Mark scheme, page 8 of 13
Page 8 of 13
Mark scheme, page 9 of 13
Page 9 of 13
Mark scheme, page 10 of 13
Page 10 of 13
Mark scheme, page 11 of 13
Page 11 of 13
Mark scheme, page 12 of 13
Page 12 of 13
Mark scheme, page 13 of 13
Page 13 of 13

Paper as text

Question paper, page 1

This document consists of 18 printed pages and 2 blank pages. DC (ST) 163547/2 © UCLES 2019 [Turn over Cambridge Assessment International Education Cambridge International Advanced Subsidiary and Advanced Level * 9 9 8 3 8 0 6 9 2 4 * COMPUTER SCIENCE 9608/23 Paper 2 Fundamental Problem-solving and Programming Skills May/June 2019 2 hours Candidates answer on the Question Paper. No Additional Materials are required. No calculators allowed. READ THESE INSTRUCTIONS FIRST Write your centre number, candidate number and name in the spaces at the top of this page. Write in dark blue or black pen. You may use an HB pencil for any diagrams, graphs or rough working. Do not use staples, paper clips, glue or correction fluid. DO NOT WRITE IN ANY BARCODES. Answer all questions. No marks will be awarded for using brand names of software packages or hardware. At the end of the examination, fasten all your work securely together. The number of marks is given in brackets [ ] at the end of each question or part question. The maximum number of marks is 75.

Question paper, page 2

2 9608/23/M/J/19 © UCLES 2019 1 The following pseudocode searches for the longest run of identical characters in the array Message. DECLARE Message : ARRAY[1:100] OF CHAR PROCEDURE Search() DECLARE Index : INTEGER DECLARE ThisChar : CHAR DECLARE ThisRun : INTEGER DECLARE LongRun : INTEGER ThisChar Message[1] ThisRun 1 LongRun 1 FOR Index 2 TO 100 IF Message[Index] = ThisChar THEN ThisRun ThisRun + 1 ELSE ThisChar Message[Index] IF ThisRun > LongRun THEN LongRun ThisRun ENDIF ThisRun 1 ENDIF ENDFOR OUTPUT "The longest run was " , LongRun ENDPROCEDURE

Question paper, page 3

3 9608/23/M/J/19 © UCLES 2019 [Turn over (a) Draw a program flowchart to represent the procedure Search(). Variable and array declarations are not required in program flowcharts. [6]

Question paper, page 4

4 9608/23/M/J/19 © UCLES 2019 (b) (i) Program variables have values as follows: Variable Value MeltingPoint 180.5 Soluble FALSE Attempt 3 ProductName "Mushroom Compost" Version 'A' ProductID "BZ27-4" Evaluate each expression in the following table. If an expression is invalid, write ERROR. For the built-in functions list, refer to the Appendix on page 18. Expression Evaluates to STRING_TO_NUM(MID(ProductID, 3, 2)) + 4 INT(MeltingPoint / 2) Soluble AND Attempt > 3 LENGTH(ProductID & NUM_TO_STRING(MeltingPoint)) RIGHT(ProductName, 4) & MID(ProductName, 5, 4) [5] (ii) Programming languages support different data types. Give an appropriate data type for the following variables from part (b)(i). Variable Data type MeltingPoint Soluble Attempt Version ProductID [5]

Question paper, page 5

5 9608/23/M/J/19 © UCLES 2019 [Turn over 2 (a) A student is learning about arrays. She wants to write a program to: • search through a 1D array of 100 elements • count the number of elements that contain the string “Empty” • output the number of elements containing “Empty” together with a suitable message. Use structured English to describe the algorithm she could use. … … … … … … … … … … … [5] (b) She uses the process of stepwise refinement to develop her algorithm. Explain this process. … … … … … … [3]

Question paper, page 6

6 9608/23/M/J/19 © UCLES 2019 (c) The student is learning about file handling. She has been told that there are different file modes that can be used when opening a text file. She wants to make sure that the existing contents are not deleted when the file is opened. Identify two file modes she could use and describe their use. Mode … Description … … … Mode … Description … … … [4] (d) The student has completed the design of her program and is ready to use an Integrated Development Environment (IDE). Describe the features of an IDE that she can use to write, translate and test her program. … … … … … … [3]

Question paper, page 7

7 9608/23/M/J/19 © UCLES 2019 [Turn over Question 3 begins on the next page.

Question paper, page 8

8 9608/23/M/J/19 © UCLES 2019 3 The following pseudocode represents three separate modules from an algorithm design. The module contents are not shown. FUNCTION Search(AA : INTEGER, BB : STRING) RETURNS INTEGER ENDFUNCTION FUNCTION Allocate() RETURNS BOOLEAN ENDFUNCTION PROCEDURE Enable(CC : INTEGER, BYREF DD : INTEGER) ENDPROCEDURE A fourth module, Setup(), refers to the previous three modules as follows: PROCEDURE Setup() WHILE Authorised = TRUE ThisValue Search(27, "Thursday") Authorised Allocate() CALL Enable(ThisValue, 4) ENDWHILE ENDPROCEDURE

Question paper, page 9

9 9608/23/M/J/19 © UCLES 2019 [Turn over (a) Draw a structure chart to show the four modules and the parameters that these pass between them. [6] (b) The algorithm is implemented in a high-level language. Changes are required and the program is given to Albert, who is an experienced programmer. He is not familiar with the language that has been used. Explain why Albert would be able to understand the program. … … … … [2]

Question paper, page 10

10 9608/23/M/J/19 © UCLES 2019 4 A program is being written to process student information. One task involves inputting the names of all students in a class. A first attempt at the pseudocode for this task is as follows: DECLARE Name1 : STRING DECLARE Name2 : STRING DECLARE Name3 : STRING DECLARE Name40 : STRING OUTPUT "Input the name for student 1" INPUT Name1 OUTPUT "Input the name for student 2" INPUT Name2 OUTPUT "Input the name for student 3" INPUT Name3 OUTPUT "Input the name for student 40" INPUT Name40 (a) Re-write the pseudocode to perform this task in a more efficient way, to allow for the class of 40 students. … … … … … … … … … … [4] (b) Give one advantage of your solution. … [1]

Question paper, page 11

11 9608/23/M/J/19 © UCLES 2019 [Turn over Question 5 begins on the next page.

Question paper, page 12

12 9608/23/M/J/19 © UCLES 2019 5 Nigel is learning about string handling. He wants to write code to count the number of words in a given string. A word is defined as a sequence of alphabetic characters that is separated by one or more space characters. His first attempt at writing an algorithm in pseudocode is as follows: PROCEDURE CountWords(Message : STRING) DECLARE NumWords : INTEGER DECLARE Index : INTEGER CONSTANT Space = ' ' NumWords 0 FOR Index 1 TO LENGTH(Message) IF MID(Message, Index, 1) = Space THEN NumWords NumWords + 1 ENDIF ENDFOR OUTPUT "Number of words : " , NumWords ENDPROCEDURE For the built-in functions list, refer to the Appendix on page 18. His first attempt is incorrect. He will use white-box testing to help him to identify the problem. (a) (i) State the purpose of white-box testing. … … [1] (ii) Dry running the code is often used in white-box testing. In this method, the programmer records the values of variables as they change. Identify what the programmer would normally use to record the changes. … [1]

Question paper, page 13

13 9608/23/M/J/19 © UCLES 2019 [Turn over (b) (i) Write a test string containing two words that gives the output: Number of words : 2 Use the symbol '∇' to represent each space character in your test string. Explain why the algorithm gives the output shown above. String … Explanation … … … … … [3] (ii) Nigel tested the procedure with the strings: String 1: "Red∇and∇Yellow" String 2: "Green∇∇and∇∇Pink∇" Give the output that is produced for each of the strings. Describe the changes that would need to be made to the algorithm to give the correct output in each case. Do not write pseudocode or program code. String 1 … Description … … … … String 2 … Description … … … … [6]

Question paper, page 14

14 9608/23/M/J/19 © UCLES 2019 6 A text file, StudentContact.txt, contains a list of names and telephone numbers of students in a school. Not all students in the school have provided a contact telephone number. In this case, their name will not be in the file. Each line of the file is stored as a string that contains a name and telephone number, separated by the asterisk character ('*') as follows: <Name>'*'<TelNumber>, for example: "Bill Smith*081234567" A 1D array, ClassList, contains the names of students in a particular class. The array consists of 40 elements of string data type. You can assume that student names are unique. Unused elements contain the empty string "". A program is to be written to produce a new text file, ClassContact.txt, containing student names and numbers for all students in a particular class. For each name contained in the ClassList array, the program will: • search the StudentContact.txt file • copy the matching string into ClassContact.txt if the name is found • write the name together with “*No number” into ClassContact.txt if the name is not found. The program will be implemented as three modules. The description of these is as follows: Module Description ProcessArray() • Check each element of the array: ○ Read the student name from the array ○ Ignore unused elements ○ Call SearchFile() with the student name ○ If the student name is found, call AddToFile() to write the student details to the class file ○ If the student name is not found, call AddToFile() to write a new string to the class file, formed as follows: <Name>“*No number” • Return the number of students who have not provided a telephone number SearchFile() • Search for a given student name at the start of each line in the file StudentContact.txt: ○ If the search string is found, return the text line from StudentContact.txt ○ If the search string is not found, return an empty string AddToFile() • Append the given string to a specified file, for example, AddToFile(StringName, FileName)

Question paper, page 15

15 9608/23/M/J/19 © UCLES 2019 [Turn over (a) Write program code for the module SearchFile(). 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 … … … … … … … … … … … … … … … … … … … … … … … … … [8]

Question paper, page 16

16 9608/23/M/J/19 © UCLES 2019 (b) Write pseudocode for the module ProcessArray(). … … … … … … … … … … … … … … … … … … … … … … … … … [9]

Question paper, page 17

17 9608/23/M/J/19 © UCLES 2019 [Turn over (c) ProcessArray() is modified to make it general purpose. It will now be called with two parameters as follows: • an array • a string representing the name of a class contact file It will still return the number of students who have not provided a contact telephone number. Write program code for the header (declaration) of the modified ProcessArray(). Programming language … Program code … … … … [3]

Question paper, page 18

18 9608/23/M/J/19 © UCLES 2019 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. Example: NUM_TO_STRING(x) returns "87.5" if x has the value 87.5 Note: This function will also work if x is of type INTEGER STRING_TO_NUM(x : STRING) RETURNS REAL returns a numeric representation of a string. Example: STRING_TO_NUM(x) returns 23.45 if x has the value "23.45" Note: This function will also work if x is of type CHAR Operators (pseudocode) Operator Description & Concatenates (joins) two strings Example: "Summer" & " " & "Pudding" produces "Summer Pudding" AND Performs a logical AND on two Boolean values Example: TRUE AND FALSE produces FALSE OR Performs a logical OR on two Boolean values Example: TRUE OR FALSE produces TRUE

Question paper, page 19

19 9608/23/M/J/19 © UCLES 2019 BLANK PAGE

Question paper, page 20

20 9608/23/M/J/19 © UCLES 2019 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 13 printed pages. © UCLES 2019 [Turn over Cambridge Assessment International Education Cambridge International Advanced Subsidiary and Advanced Level COMPUTER SCIENCE 9608/23 Paper 2 Written Paper May/June 2019 MARK SCHEME Maximum Mark: 75 Published This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the details of the discussions that took place at an Examiners’ meeting before marking began, which would have considered the acceptability of alternative answers. Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for Teachers. Cambridge International will not enter into discussions about these mark schemes. Cambridge International is publishing the mark schemes for the May/June 2019 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/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 2 of 13 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/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 3 of 13 Question Answer Marks 1(a) Mark as follows: • One mark per area outlined, in correct place • Decision must be diamond symbol and have two outputs with at least one label (YES / NO) 6

Mark scheme, page 4

9608/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 4 of 13 Question Answer Marks 1(b)(i) Expression Evaluates to STRING_TO_NUM(MID(ProductID, 3, 2)) + 4 31.0 / 31 INT(MeltingPoint / 2) 90 Soluble AND Attempt > 3 FALSE LENGTH(ProductID & NUM_TO_STRING(MeltingPoint)) 11 RIGHT(ProductName, 4) & MID(ProductName, 5, 4) "postroom" Quotes for row 5 only 5 1(b)(ii) Variable Data type MeltingPoint REAL Soluble BOOLEAN Attempt INTEGER Version CHAR ProductID STRING One mark per data type 5 Question Answer Marks 2(a) One mark for each point: • Initialise a count to zero • loop 100 times // loop through all of the array • compare an element with "Empty" in a loop • increment the count if equal in a loop • Output a message together with the count not inside a loop 5 2(b) One mark for each point: • The breaking down of an algorithm / task / problem • to a level of (sufficient) detail // into smaller parts / sub-tasks • from which it can be programmed // which are easier to program 3

Mark scheme, page 5

9608/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 5 of 13 Question Answer Marks 2(c) Mode: READ Description: Used to read data from a file // input data from a file to the program // only allows you to read data from the file / can't change the data Mode: APPEND Description: Used to add data // write to the end of the text file // output data from the program to the end of a file (without changing / deleting anything) One mark for mode; one mark for corresponding description 4 2(d) Write: Use an editor to write the source code / program / high-level language code. Or by example of feature: An editor provides (features such as) context-sensitive prompts / dynamic syntax checking / PrettyPrint / auto-indentation etc. Translate: A translator (compiler) will convert the source code / program / high-level language code into object code / machine code / an executable file A translator (interpreter) is used to translate the source code / program / high-level language code line by line // Or by example: identify syntax errors Or by example of feature: A translator will identify errors Test: A debugger is used to find / (help to) correct errors. Or by example of feature: e.g. single-step, break-points, watch-window« One mark per category (Write, Translate, Test) for each reference to a specific ‘feature’. 3

Mark scheme, page 6

9608/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 6 of 13 Question Answer Marks 3(a) Mark as follows: • One mark for four boxes connected as shown (search, allocate and enable in the correct order) • One mark for each of: • Arrows labelled AA, BB and CC with correct symbols • Return parameter from Search with correct symbol • Return boolean from Allocate with correct symbol • Double-headed arrow for DD • One mark for repetition arrow (either direction) 6 3(b) • He would use his transferrable skills to understand the new program • He could recognise (or equivalent phrase) basic control structures in the language / by example of a program construct (loops, conditional, declaration...) • He could read the comments / meaningful variable names One mark for each bullet point 2

Mark scheme, page 7

9608/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 7 of 13 Question Answer Marks 4(a) DECLARE Name : ARRAY [1:40] OF STRING DECLARE Index : INTEGER FOR Index ← 1 TO 40 OUTPUT "Input the name for student ", Index INPUT Name[Index] ENDFOR One mark for each of the following: 1. Declaration of array and index 2. Loop for 40 elements 3. Prompt (as above, including student number) and input for name in a loop 4. Assign the name to an array element in a loop 4 4(b) • Program code easier to read / modify / debug • Easier to access individual elements of / search for a vaue in the ‘data set’ // single identifier used 1 Question Answer Marks 5(a)(i) To test every path through the code / algorithm Accept phrase with equivalent meaning 1 5(a)(ii) A trace table 1 5(b)(i) String: • three possible formats for string containg two words: "Cat∇∇Dog" // "Cat∇Dog∇" // "∇Cat∇Dog" Explanation: • When a space character is encountered • NumWords is incremented by 1 OR: • The algorithm counts the spaces • and not the words 1 mark for a string that would give the correct result 2 marks for explanation 3

Mark scheme, page 8

9608/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 8 of 13 Question Answer Marks 5(b)(ii) String 1: • Output: Number of words : 2 Description 1: • Check character at end of string • If not a character, increment variable NumTotal OR: • Add a space at the beginning / end of string • At the start of the algorithm OR: • Change Initialisation of NumWords • to 1 OR: • After the loop • Add 1 to NumWords String 2: • Output: Number of words : 5 Description 2: • Detect a space followed by a space • Count as a single space / only increment variable NumTotal once OR: • Replace all double spaces with a single space • Before the loop OR: • After the loop • Subtract 2 from NumWords Many possible solutions. One mark for each correct output One marks for each description bullet point 6

Mark scheme, page 9

9608/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 9 of 13 Question Answer Marks 6(a) ‘Pseudocode’ solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. FUNCTION SearchFile (SearchString : STRING) RETURNS STRING DECLARE FileData : STRING DECLARE Found : BOOLEAN DECLARE SearchLength : INTEGER Found ← FALSE SearchLength ← LENGTH(SearchString) OPENFILE "StudentContact.txt" FOR READ WHILE NOT EOF("StudentContact.txt") AND NOT Found READFILE "StudentContact.txt", FileData IF SearchString = LEFT(FileData, SearchLength) THEN Found ← TRUE ENDIF ENDWHILE CLOSEFILE "StudentContact.txt" IF NOT FOUND THEN RETURN "" ELSE RETURN FileData ENDIF ENDFUNCTION One mark for each of the following: 1. Function header and end (where appropriate). Parameter optional but if present must be of type STRING 2. Calculate length of string from parameter // extract substring from file line 3. File OPEN() in READ mode and subsequent CLOSE() 4. WHILE loop repeating until EOF() 5. read a line from the file in a loop 6. compare name from file with SearchString in a loop 7. exit loop if SearchString found 8. Return the line from the file if SearchString found or an empty string if not found 8

Mark scheme, page 10

9608/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 10 of 13 Question Answer Marks 6(b) FUNCTION ProcessArray() RETURNS INTEGER DECLARE NoTelNumber : INTEGER DECLARE Index : INTEGER DECLARE ThisName : STRING DECLARE StudentData : STRING NoTelNumber ← 0 FOR Index ← 1 to 40 ThisName ← ClassList[Index] IF ThisName <> "" //Skip blanks THEN StudentData ← SearchFile(ThisName) IF StudentData = "" //Student not found THEN StudentData ← ThisName & "*No number" NoTelNumber ← NoTelNumber + 1 ENDIF CALL AddToFile(StudentData, "ClassContact.txt") ENDIF ENDFOR RETURN NoTelNumber ENDFUNCTION One mark for each of the following: 1. Function header and end, including return parameter 2. Declaration and initialisation of local count variable (NoTelNumber) 3. FOR loop for 40 array elements « 4. skip empty elements in a loop 5. use SearchFile(ThisName) and save return value in a loop 6. if Searchfile() returns an empty string, add "*No number" to SearchString … 7. ... and increment count 8. call AddToFile with both parameters as above in a loop 9. Return count outside the loop 9 6(c) ‘Pseudocode’ solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. FUNCTION ProcessArray (ClassList : ARRAY, ClassContact : STRING) RETURNS : INTEGER One mark per underlined section. 3 *** End of Mark Scheme – example program code solutions follow ***

Mark scheme, page 11

9608/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 11 of 13 Program Code Example Solutions Q6 (a): Visual Basic Function SearchFile(SearchString As String) As String Dim FileData As String Dim Found As Boolean Dim SearchLength As Integer Dim FileName As String Found = False SearchLength = Len(SearchString) FileName = "StudentContact.txt" FileOpen(1, FileName, OpenMode.Input) While Not EOF(1) And NOT Found FileData = LineInput(1) If SearchString = Left(FileData, SearchLength) Then Found = True End If End While FileClose(1) If Not Found Then Return "" Else Return FileData End If End Function Alternative: Function SearchFile (SearchString As String) As String Dim FileData As String Dim Found As Boolean Dim SearchLength As Integer Dim MyFile As System.IO.StreamReader MyFile = My.Computer.FileSystem.OpenTextFileReader("StudentContact.txt") Found = False SearchLength = Len(SearchString) Do While MyFile.Peek <> -1 FileData = MyFile.Readline() If SearchString = LEFT(FileData, SearchLength) Then Found = True return(FileData) End If Loop MyFile.Close If NOT Found then return ("") End If End Function

Mark scheme, page 12

9608/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 12 of 13 Q6 (a): Pascal function SearchFile(var SearchString: string):string; var Found : Boolean; SearchLength : integer; FileData : string; MyFile : text; begin Found := False; SearchLength := Length(SearchString); Assign(MyFile, 'StudentContact.txt'); Reset(MyFile); While NOT EOF(MyFile) AND Found = False do Begin Readln(MyFile, FileData); If SearchString = LeftStr(FileData,SearchLength) then Found := True; End; Close(MyFile); If NOT Found then SearchFile := '' else SearchFile := FileData; End; Q6 (a): Python def searchFile(searchString): ##Declare filedata : string, found : boolean, searchLength : integer ##returns a string value found = False searchLength = len(searchString) myFile = open("StudentContact.txt", 'r') fileData = myFile.readline() while found == False: fileData = myFile.readline() if not fileData.strip(): #check if no data/end of file break else: if searchString == fileData[0:searchLength]: found = True print(searchString) myFile.close if found == False: return("") else: return(fileData)

Mark scheme, page 13

9608/23 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 13 of 13 Q6 (c): Visual Basic Function ProcessArray (ClassList() As String, ClassContact As String) As Integer OR Function ProcessArray (ClassList As String(), ClassContact As String) As Integer Q6 (c): Pascal function ProcessArray (var ClassList:CList; ClassContact:string) :integer; CList is user-defined type – could be any name that’s not a keyword Q6 (c): Python def ProcessArray (ClassList, ClassContact) :

What you needed in this session

Cambridge’s own grade thresholds for 2019 May/June, Paper 2 · Variant 3. A higher threshold means an easier paper — the bar moves with how the cohort did.

A45/75
B37/75
C31/75
D24/75
E18/75