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

9608/21/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 paper16 pages

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

Mark scheme11 pages

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

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

Paper as text

Question paper, page 1

This document consists of 16 printed pages. DC (ST) 163545/2 © UCLES 2019 [Turn over Cambridge Assessment International Education Cambridge International Advanced Subsidiary and Advanced Level * 3 0 2 5 5 8 8 3 4 7 * COMPUTER SCIENCE 9608/21 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/21/M/J/19 © UCLES 2019 1 (a) (i) Algorithms may be expressed using four basic constructs. One construct is sequence. Complete the following table for two other constructs. Construct Pseudocode example … … … … … … … … … … [4] (ii) Simple algorithms usually consist of input, process and output. Complete the table by placing ticks (‘3’) in the relevant boxes. Pseudocode statement Input Process Output Temp SensorValue * Factor WRITEFILE "LogFile.txt", TextLine WRITEFILE "LogFile.txt", MyName & MyIDNumber READFILE "AddressBook.txt", NextLine [4]

Question paper, page 3

3 9608/21/M/J/19 © UCLES 2019 [Turn over (b) Program variables have values as follows: Variable Value Title "101 tricks with spaghetti" Version 'C' Author "Eric Peapod" PackSize 4 WeightEach 6.2 Paperback TRUE (i) 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 16. Expression Evaluates to MID(Title, 5, 3) & RIGHT(Author, 3) INT(WeightEach * PackSize) PackSize >= 4 AND WeightEach < 6.2 LEFT(Author, ASC(Version) - 65) RIGHT(Title, (LENGTH(Author) – 6)) [5] (ii) Programming languages support different data types. Give an appropriate data type for the following variables from part (b). Variable Data type Title Version PackSize WeightEach Paperback [5] (c) White-box and black-box are two types of testing. In white-box testing, data are chosen to test every possible path through the program. Explain how data are chosen in black-box testing. … … [2]

Question paper, page 4

4 9608/21/M/J/19 © UCLES 2019 2 (a) One type of loop that may be found in an algorithm is a count-controlled loop. State one other type and explain when it should be used. Type … Explanation … … … [2] (b) Chris is asked to work on a program that has been coded in a language he is not familiar with. He has identified that the program contains the constructs: sequence, iteration and selection. Identify three other features of the program that he should expect to recognise. Feature 1 … Feature 2 … Feature 3 … [3] (c) The following lines of code are taken from a program in a high-level language. ON x { 15: Call ProcA 20: y := 0 25: y := 99 NONE: Call ProcError } Identify the type of control structure and describe the function of the code. Control structure … Description … … … … [3]

Question paper, page 5

5 9608/21/M/J/19 © UCLES 2019 [Turn over 3 (a) A student is developing an algorithm to search through a 1D array of 100 elements. Each element of the array, Result, contains a REAL value. The algorithm will output: • the average value of all the elements • the number of elements with a value of zero. The structured English description of the algorithm is: 1. SET Total value to 0 2. SET Zero count to 0 3. SELECT the first element 4. ADD value of element to Total value 5. IF element value is 0 then INCREMENT Zero count 6. REPEAT from step 4 for next element, until element is last element 7. SET Average to Total / 100 8. OUTPUT a suitable message and Average 9. OUTPUT a suitable message and Zero count Write pseudocode for this algorithm. … … … … … … … … … … … … … … … … [7]

Question paper, page 6

6 9608/21/M/J/19 © UCLES 2019 (b) The student decides to change the algorithm and implement it as a procedure, ScanArray(), which will be called with three parameters. ScanArray(AverageValue, ZeroCount, ArrayName) ScanArray() will modify the first two parameters so that the new values are available to the calling program or module. Write the pseudocode procedure header for ScanArray(). … … … … [4]

Question paper, page 7

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

Question paper, page 8

8 9608/21/M/J/19 © UCLES 2019 4 The following pseudocode is a string handling function. For the built-in functions list, refer to the Appendix on page 16. FUNCTION Clean(InString : STRING) RETURNS STRING DECLARE NewString : STRING DECLARE Index : INTEGER DECLARE AfterSpace : BOOLEAN DECLARE NextChar : CHAR CONSTANT Space = ' ' AfterSpace FALSE NewString "" FOR Index 1 TO LENGTH(InString) NextChar MID(InString, Index, 1) IF AfterSpace = TRUE THEN IF NextChar <> Space THEN NewString NewString & NextChar AfterSpace FALSE ENDIF ELSE NewString NewString & NextChar IF NextChar = Space THEN AfterSpace TRUE ENDIF ENDIF ENDFOR RETURN NewString ENDFUNCTION

Question paper, page 9

9 9608/21/M/J/19 © UCLES 2019 [Turn over (a) (i) Complete the trace table by performing a dry run of the function when it is called as follows: Result Clean("X∇∇∇Y∇and∇∇Z") The symbol '∇' represents a space character. Use this symbol to represent a space character in the trace table. Index AfterSpace NextChar NewString [6] (ii) State the effect of the function Clean(). … … [1]

Question paper, page 10

10 9608/21/M/J/19 © UCLES 2019 (iii) The pseudocode is changed so that the variable AfterSpace is initialised to TRUE. Explain what will happen if the function is called as follows: Result Clean("∇∇X∇∇∇Y∇and∇∇Z") … … … … [2] (b) The following pseudocode declares and initialises an array. DECLARE Code : ARRAY[1:100] OF STRING DECLARE Index : INTEGER FOR Index 1 TO 100 Code[Index] "" ENDFOR The design of the program is changed as follows: • the array needs to be two dimensional, with 500 rows and 4 columns • the elements of the array need to be initialised to the string "Empty" Re-write the pseudocode to implement the new design. … … … … … … … … … … [4] (c) State the term used for changes that are made to a program in response to a specification change. … [1]

Question paper, page 11

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

Question paper, page 12

12 9608/21/M/J/19 © UCLES 2019 5 (a) Programming languages usually contain a range of built-in functions, such as a random number generator. State three advantages of using built-in functions. 1 … 2 … 3 … [3] (b) A student is learning about random number generation. She is investigating how many times the random function needs to be called before every number in a given series is generated. She is using pseudocode to develop a procedure, TestRand(), which will: • use the random number function to generate an integer value in the range 1 to 50 inclusive • count how many times the random function needs to be called before all 50 values have been generated • output a message giving the number of times the random function was called.

Question paper, page 13

13 9608/21/M/J/19 © UCLES 2019 [Turn over Write pseudocode for the procedure TestRand(). For the built-in functions list, refer to the Appendix on page 16. … … … … … … … … … … … … … … … … … … … … … … … … … … [8]

Question paper, page 14

14 9608/21/M/J/19 © UCLES 2019 6 A text file, MyCDs.txt, stores information relating to a Compact Disc (CD) collection. Information about each CD is stored on three separate lines in the file as follows: Line 1: <Artist Name> Line 2: <CD Title> Line 3: <Storage Location> Information is stored as data strings. A section of the file is shown: File line Data 100 "Green Floyd" 101 "Bowlful of Cereal" 102 "Shelf 4" 103 "Strolling Bones" 104 "Exile on Station Road" 105 "Box 12" (a) A program, CDOrganiser, will be written to manage the stored information. The program will consist of three modules: AddCD, FindCD and RemoveCD. Give three reasons why it is good practice to construct the program using modules. 1 … 2 … 3 … [3] (b) The module, FindCD(), will check whether a given CD exists in the collection. The module will be implemented as a function. The function will: • be called with two strings as parameters, representing the artist name and CD title • return a string that gives the storage location, or an empty string if the given CD has not been found. 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.

Question paper, page 15

15 9608/21/M/J/19 © UCLES 2019 [Turn over Write program code for the function FindCD(). 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/21/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 ASC(ThisChar : CHAR) RETURNS INTEGER returns the ASCII value of character ThisChar Example: ASC('A') returns 65 RAND(x : INTEGER) RETURNS REAL returns a real number in the range 0 to x (x not inclusive). Example: RAND(87) could return 35.43 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

Mark scheme, page 1

This document consists of 11 printed pages. © UCLES 2019 [Turn over Cambridge Assessment International Education Cambridge International Advanced Subsidiary and Advanced Level COMPUTER SCIENCE 9608/21 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/21 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 2 of 11 Generic Marking Principles These general marking principles must be applied by all examiners when marking candidate answers. They should be applied alongside the specific content of the mark scheme or generic level descriptors for a question. Each question paper and mark scheme will also comply with these marking principles. GENERIC MARKING PRINCIPLE 1: Marks must be awarded in line with: • the specific content of the mark scheme or the generic level descriptors for the question • the specific skills defined in the mark scheme or in the generic level descriptors for the question • the standard of response required by a candidate as exemplified by the standardisation scripts. GENERIC MARKING PRINCIPLE 2: Marks awarded are always whole marks (not half marks, or other fractions). GENERIC MARKING PRINCIPLE 3: Marks must be awarded positively: • marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit is given for valid answers which go beyond the scope of the syllabus and mark scheme, referring to your Team Leader as appropriate • marks are awarded when candidates clearly demonstrate what they know and can do • marks are not deducted for errors • marks are not deducted for omissions • answers should only be judged on the quality of spelling, punctuation and grammar when these features are specifically assessed by the question as indicated by the mark scheme. The meaning, however, should be unambiguous. GENERIC MARKING PRINCIPLE 4: Rules must be applied consistently e.g. in situations where candidates have not followed instructions or in the application of generic level descriptors. GENERIC MARKING PRINCIPLE 5: Marks should be awarded using the full range of marks defined in the mark scheme for the question (however; the use of the full mark range may be limited according to the quality of the candidate responses seen). GENERIC MARKING PRINCIPLE 6: Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should not be awarded with grade thresholds or grade descriptors in mind.

Mark scheme, page 3

9608/21 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 3 of 11 Question Answer Marks 1(a)(i) Construct: Assignment Pseudocode example: Answer ← "YES" Construct: Selection Pseudocode example: IF X = 3 THEN OUTPUT "HELLO" Construct: Repetition / Iteration Pseudocode example: FOR N ← 1 to 100 One mark for construct One mark for pseudocode example Maximum 4 marks 4 1(a)(ii) Pseudocode statement Input Process Output Temp ← SensorValue * Factor 3 WRITEFILE "LogFile.txt", TextLine 3 WRITEFILE "LogFile.txt", MyName & MyIDNumber 3 3 READFILE "AddressBook.txt", NextLine 3 (3) One mark per correct row 4 1(b)(i) Expression Evaluates to MID(Title, 5, 3) & RIGHT(Author, 3) "tripod" INT(WeightEach * PackSize) 24 PackSize >= 4 AND WeightEach < 6.2 FALSE LEFT(Author, ASC(Version) - 65) "Er" RIGHT(Title, (LEN(Author) – 6)) "hetti" Quotes must be present Must be capital E in row 4 5

Mark scheme, page 4

9608/21 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 4 of 11 Question Answer Marks 1(b)(ii) Variable Data type Tile STRING Version CHAR PackSize INTEGER WeightEach REAL Paperback BOOLEAN One mark per data type 5 1(c) Data is chosen: • to test that the program does what it is supposed to do / to check that the results are as expected • to use known valid, boundary and erroneous values 2 Question Answer Marks 2(a) Type: Conditional Explanation: The number of iterations is not known / dependent on a condition 2 2(b) One mark per bullet point to max 3 • Functions / Procedures / Modules / subtasks • Parameters • Variable / constant declaration / assignment / Data types • Input / Output • Arithmetic / logic operations • Classes / Objects 3 2(c) One mark for: • A CASE structure Max 2 for remaining points: • Selecting on / using variable X • Calling ProcA if X = 15 • Assigning a value of 0 to Y if X = 20 and assign 99 to Y if X = 25 • Calling ProcError if no match (previous conditions not satisfied) // Call ProcError if x = NONE 3

Mark scheme, page 5

9608/21 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 5 of 11 Question Answer Marks 3(a) TotalValue ← 0 ZeroCount ← 0 FOR Index ← 1 TO 100 TotalValue ← TotalValue + Result[Index] IF Result[Index] = 0.0 THEN ZeroCount ← ZeroCount + 1 ENDIF ENDFOR OUTPUT "The average is ", (TotalValue / 100) OUTPUT "The number of elements with a zero value is ", ZeroCount One mark for each of the following: 1 Both initialisations 2 Loop 100 times 3 Adding individual element to TotalValue in a loop 4 Check if element value is zero in a loop 5 If so increment ZeroCount in a loop 6 Average is calculated after the loop 7 Both OUTPUT statements, including message and variables 7 3(b) PROCEDURE ScanArray (BYREF AverageValue: REAL, _ BYREF ZeroCount: INTEGER, ArrayName : ARRAY) One mark for each underlined part Names unimportant but first two parameters must be BYREF 4

Mark scheme, page 6

9608/21 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 6 of 11 Question Answer Marks 4(a)(i) Index AfterSpace NextChar NewString FALSE "" 1 'X' "X" 2 TRUE '∇' "X∇" 3 '∇' 4 '∇' 5 FALSE 'Y' "X∇Y" 6 TRUE '∇' "X∇Y∇" 7 FALSE ‘a’ "X∇Y∇a" 8 'n' "X∇Y∇an" 9 'd' "X∇Y∇and" 10 TRUE '∇' "X∇Y∇and∇" 11 '∇' 12 FALSE 'Z' "X∇Y∇and∇Z" One mark for each area as outlined. If no row marks then mark by column for columns 2, 3 and 4 6 4(a)(ii) To remove repeated space characters 1 4(a)(iii) • All leading spaces / spaces at the beginning • will be removed (from the input string) 2

Mark scheme, page 7

9608/21 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 7 of 11 Question Answer Marks 4(b) DECLARE Code : ARRAY[1:500, 1:4] OF STRING DECLARE RowIndex : INTEGER DECLARE ColIndex : INTEGER FOR RowIndex ← 1 TO 500 FOR ColIndex ← 1 TO 4 Code[RowIndex, ColIndex] ← "Empty" ENDFOR ENDFOR One mark for each of the following: 1 Array declaration 2 Additional local variable 3 Nested loops 4 Array element assignment within the inner loop RowIndex and ColIndex can be interchangeable 4 4(c) Adaptive Maintenance 1

Mark scheme, page 8

9608/21 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 8 of 11 Question Answer Marks 5(a) • Saves development time / no need to write it / can’t write it« • Pre-compiled and tested / Increased reliability / reduces chance of error • Is available to all programs 3 5(b) PROCEDURE TestRand() DECLARE MyArray : ARRAY [1:50] OF BOOLEAN DECLARE Attempts : INTEGER DECLARE NumFound : INTEGER DECLARE ThisRndNumber : INTEGER DECLARE Index : INTEGER FOR Index ← 1 TO 50 Myarray[Index] ← FALSE ENDFOR NumFound ← 0 Attempts ← 0 WHILE NumFound < 50 ThisRndNumber ← 1 + INT(RAND(50)) Attempts ← Attempts + 1 IF MyArray[ThisRndNumber] = FALSE THEN MyArray[ThisRndNumber] ← TRUE NumFound ← NumFound + 1 ENDIF ENDWHILE OUTPUT "Number of calls to RAND() was ", Attempts ENDPROCEDURE 1 mark for each of the following: 1 Declaration of array of 50 elements 2 Loop to initialise array 3 Conditional loop stopping when all numbers generated 4 Generate a random integer in the range 1 to 50 in a loop 5 Count each call to RND() in a loop 6 check if the number has already been generated in a loop 7 if true, record as generated in a loop 8 Output a message plus the Attempts outside a loop 8

Mark scheme, page 9

9608/21 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 9 of 11 Question Answer Marks 6(a) One mark for each of: 1 To make a more manageable / understandable solution 2 Subroutine may be (independently) tested and debugged 3 Program is easier to maintain 3 6(b) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. FUNCTION FindCD(SearchCDArtist : STRING, SearchCDTitle : STRING) RETURNS STRING DECLARE CDTitle : STRING DECLARE CDArtist : STRING DECLARE CDLocation : STRING DECLARE Location : STRING Location ← "" OPENFILE "MyCDs.txt" FOR READ WHILE NOT EOF ("MyCDs.txt") AND Location = "" READFILE "MyCDs.txt", CDArtist READFILE "MyCDs.txt", CDTitle READFILE "MyCDs.txt", CDLocation IF SearchCDArtist = CDArtist AND SearchCDTitle = CDTitle THEN Location ← CDLocation ENDIF ENDWHILE CLOSEFILE("MyCDs.txt") RETURN Location ENDFUNCTION One mark for each of the following: 1 Function header and close (where appropriate), including parameters 2 Declaration of local STRING variables for CDArtist and CDTitle 3 OPEN and CLOSE file for reading (Allow MyCDs or MyCDs.txt) 4 (WHILE) loop checking for EOF 5 read three lines from file in a loop 6 compare search values with file values in a loop« 7 «If true, set Location and exit loop in a loop 8 Return Location 8

Mark scheme, page 10

9608/21 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 10 of 11 Program Code Example Solutions Q6 (b) (i): Visual Basic Function FindCD(SearchCDArtist As String, SearchCDTitle As String) As String Dim CDTitle As String Dim CDArtist As String Dim CDLocation As String Dim Location As String Location = "" FileOpen(1,"MyCDs.txt", OpenMode.Input) Do While Not EOF(1) And Location = "" CDArtist = LineInput(1) CDTitle = LineInput(1) CDLocation = LineInput(1) If SearchCDArtist = CDArtist And SearchCDTitle = CDTitle Then Location = CDLocation End If Loop FileClose(1) EndFunction Q6 (b) (i): Python def FindCD(SearchCDArtist, SearchCDTitle): # CDTitle, CDArtist, CDLocation, Location : string Location = "" myFile = open("MyCDs.txt", 'r') while True: # or Location == "": CDArtist = myFile.readline() if CDArtist == "": break else: CDTitle = myFile.readline() CDLocation = myFile.readline() if SearchCDArtist == CDArtist.strip()and SearchCDTitle == CDTitle.strip(): Location = CDLocation myFile.close return (Location)

Mark scheme, page 11

9608/21 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2019 © UCLES 2019 Page 11 of 11 Q6 (b) (i): Pascal function FindCD(SearchCDArtist, SearchCDTitle:string): string; var CDTitle, CDArtist, CDLocation, Location : string; FileHandle : TextFile; begin Location := ''; AssignFile(FileHandle,'MyCDs.txt'); Reset (FileHandle); while not eof(FileHandle) and (Location = '') do begin readln(FileHandle, CDArtist); readln(FileHandle, CDTitle); readln(FileHandle, CDLocation); if (SearchCDArtist = CDArtist) and (SearchCDTitle = CDTitle) then Location := CDLocation; end; Close (FileHandle); FindCD := Location; end;

What you needed in this session

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

A44/75
B37/75
C31/75
D25/75
E19/75