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

9608/22/M/J/18 · 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 2018 May/June Paper 2 · Variant 2 question paper, page 1 of 16
Page 1 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 2 of 16
Page 2 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 3 of 16
Page 3 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 4 of 16
Page 4 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 5 of 16
Page 5 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 6 of 16
Page 6 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 7 of 16
Page 7 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 8 of 16
Page 8 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 9 of 16
Page 9 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 10 of 16
Page 10 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 11 of 16
Page 11 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 12 of 16
Page 12 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 13 of 16
Page 13 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 14 of 16
Page 14 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 15 of 16
Page 15 of 16
Cambridge A Level Computer Science 9608 2018 May/June Paper 2 · Variant 2 question paper, page 16 of 16
Page 16 of 16

Mark scheme16 pages

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

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

Paper as text

Question paper, page 1

* 0 9 6 9 3 8 9 3 9 9 * This document consists of 16 printed pages. DC (NF/JG) 146141/3 © UCLES 2018 [Turn over Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level COMPUTER SCIENCE 9608/22 Paper 2 Fundamental Problem-solving and Programming Skills May/June 2018 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/22/M/J/18 © UCLES 2018 1 (a) A farm has a number of greenhouses used to grow vegetables. Each greenhouse has a different identification number. A program is needed to store temperature information for each greenhouse throughout the day. Give a suitable identifier name for each of the data items. Description of data item Suitable identifier name The temperature inside the greenhouse The temperature outside the greenhouse The greenhouse identification number The time of the temperature measurements [4] (b) (i) Program variables have values as follows: Variable Value Mark 60 Subject "Computer Science" Grade 'B' CourseCompleted TRUE AverageMark 49.5 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 "Fas" & MID(Subject, 6, 3) LEFT(Mark, 1) 10 + ASC(Grade) MOD(AverageMark * 2, 3) CourseCompleted AND (Mark >= 60) [5]

Question paper, page 3

3 9608/22/M/J/18 © UCLES 2018 [Turn over (ii) Programming languages support different data types. Give an appropriate data type for each of these variables from part (b)(i). Variable Data type Mark Subject Grade CourseCompleted AverageMark [5]

Question paper, page 4

4 9608/22/M/J/18 © UCLES 2018 2 The following is a function design in pseudocode. Line numbers are given for reference only. 01 FUNCTION CountDigits(InString : STRING) RETURNS CHAR 02 03 DECLARE nc : CHAR 04 DECLARE c : INTEGER 05 DECLARE n : INTEGER 06 07 08 c 0 09 n LENGTH(InString) // get number of characters for loop 10 11 WHILE n > 0 // repeat until no more characters left 12 13 nc LEFT(InString,1) 14 n n - 1 15 InString RIGHT(InString,n) // remove first character 16 17 IF (nc < '0') OR (nc > '9') 18 THEN 19 // do nothing 20 ELSE 21 c c + 1 22 ENDIF 23 24 ENDWHILE 25 26 RETURN c 27 28 ENDFUNCTION (a) (i) This pseudocode includes features that make it easier to read and understand. State two such features. Feature 1 … Feature 2 … [2] (ii) State two additional features that should be used to make this pseudocode easier to read and understand. Feature 1 … Feature 2 … [2]

Question paper, page 5

5 9608/22/M/J/18 © UCLES 2018 [Turn over (b) Study the function CountDigits(). Identify the features of the function in the following table. Feature Answer A line number containing an example of an assignment statement A line number containing the start of a ‘pre-condition’ loop A line number containing the end of a ‘pre-condition’ loop A line number containing the start of a selection statement The number of parameters passed to the LEFT() function The Boolean operator used The number of times the function LEFT() is called from within CountDigits() resulting from the call: Result CountDigits("AB27C4") The number of local variables [8] (c) (i) There is a mistake in the pseudocode that would produce a data type mismatch error if a programmer were to write similar program code. Describe this mistake and how it may be corrected. … … … … [2] (ii) Lines 17 to 22 of the pseudocode could be written in a simplified form. Re-write the lines in a simplified form. … … … … … … … … [4]

Question paper, page 6

6 9608/22/M/J/18 © UCLES 2018 3 A chocolate factory produces bars of chocolate. A computer program controls the process. The weight of each bar is stored in an array, BarWeight. The array contains 100 elements, representing the weights of 100 bars that make up one shipping box. A procedure, CheckWeight(), is required to: 1. examine each array element and count how many times the weight has exceeded MaxWeight 2. compare the count obtained with a limit value, Threshold. Call procedure ServiceCheck() if the count exceeds the Threshold 3. output a message if the count does not exceed the Threshold. For example: "ShippingBox OK – maximum weight exceeded 3 times." Draw a program flowchart on the next page to represent the algorithm for the CheckWeight() procedure. Assume that: • the array contains 100 valid weight values and the first element is BarWeight[1] • MaxWeight, Threshold and BarWeight are global variables. Variable declarations are not required in program flowcharts.

Question paper, page 7

7 9608/22/M/J/18 © UCLES 2018 [Turn over [10]

Question paper, page 8

8 9608/22/M/J/18 © UCLES 2018 Question 4 begins on the next page.

Question paper, page 9

9 9608/22/M/J/18 © UCLES 2018 [Turn over 4 The structure chart shows part of the design of a program for an online shopping system. Process basket Change item quantity Checkout (pay and despatch) Discard basket (remove all items) A B C D E F G (a) (i) Draw on the chart to show the following facts. • Each of the modules at the lower level returns a Boolean parameter, X. • Process basket will call only one of the modules shown at the lower level. [2] (ii) The parameters A to G shown on the chart will be used to pass the following information. PaymentDetails Quantity BasketID DeliveryAddress ItemID Complete the following table to show the parameter and the information it represents. Parameter Information A B C D E F G [3]

Question paper, page 10

10 9608/22/M/J/18 © UCLES 2018 5 A golf club holds information about its members. When a member completes a round of golf, their score is stored along with their membership number and the date of the round. A program is to be written to store and process the score information. The information to be stored is formed into a string as follows: <MembershipNumber><Date><Score> (a) The program designer considers storing the strings in either a 1D array, RoundScore or as a separate variable for each round, for example, RoundScore01, RoundScore02, RoundScore03 and so on. Describe two advantages of storing the strings in a 1D array rather than as separate variables. Advantage 1 … … Advantage 2 … … [2] (b) A procedure, AddNewScores() is being developed. The procedure will be coded using an Integrated Development Environment (IDE). Name two features provided by an IDE that assist in the initial detection of errors in the procedure. Feature 1 … … Feature 2 … … [2]

Question paper, page 11

11 9608/22/M/J/18 © UCLES 2018 [Turn over (c) The program needs a function, GetNumber(), to return a valid membership number. A valid membership number is a four-digit numeric string between “1111” and “9999”. The structured English representing the algorithm for this function is as follows: 1. Prompt and input a membership number. 2. Validate the membership number. 3. Repeat from step 1 if the membership number is invalid. 4. Return the valid membership number as a string. An example of the function call in pseudocode is: MembershipNumber GetNumber() Write program code for the GetNumber() function. 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 … … … … … … … … … … … … … … … … … [4]

Question paper, page 12

12 9608/22/M/J/18 © UCLES 2018 (d) The program designer decides to store the strings from part (a) in a text file, ScoreDetails.txt Each string is formatted as follows: <MembershipNumber><Date><Score> • MembershipNumber is a four-digit numeric string between "1111" and "9999". • Date is a six-digit numeric string in the format DDMMYY, for example "040716". • Score is a two-digit numeric string in the range "50" to "99". A procedure OutputLowestScore() is required to output the lowest score for an individual member. Assume that there is at least one string stored for each member. The program needs a procedure, OutputLowestScore(), to process the ScoreDetails.txt file and output the lowest score for an individual member. 1. Use the GetNumber() function to obtain a valid membership number. 2. Search the ScoreDetails.txt file for the lowest score for that member. 3. Output a message giving the lowest score for that member and the date of the round. For example: "The lowest score was 66 on 300917" Write program code for the OutputLowestScore() procedure. 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 13

13 9608/22/M/J/18 © UCLES 2018 [Turn over … … … … … … … … … … … … … … … … … … … … [10]

Question paper, page 14

14 9608/22/M/J/18 © UCLES 2018 6 (a) Individual elements in a 1D array are referenced using an integer value that is used as the subscript to the array. Give the technical terms for the minimum and maximum values the subscript may take. Minimum value … Maximum value … [2] (b) A 2D array, Picture, contains data representing a bitmap image. Each element of the array represents one pixel of the image. The image is grey-scale encoded where the value of each pixel ranges from 0 (representing black) to 255 (representing white) with intermediate values representing different levels of grey. A graphics program needs a procedure, Flip(), to flip (reflect) the image. An example of an image before and after the function is: Before flip After flip The values contained in the 2D array before the flip are as follows: Data values 80 80 255 80 80 255 80 80 80 80 255 80 80 255 80 80 255 80 120 120 120 120 255 80 255 80 255 255 255 255 80 80 255 80 120 120 120 120 80 80 In pseudocode, the array is declared as follows: DECLARE Picture : ARRAY[1:5, 1:8] OF INTEGER

Question paper, page 15

15 9608/22/M/J/18 © UCLES 2018 [Turn over Write pseudocode to implement the Flip() procedure. Assume that Picture is a global variable. … … … … … … … … … … … … … … … … … … … … … … … [8]

Question paper, page 16

16 9608/22/M/J/18 © UCLES 2018 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 International Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after the live examination series. Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge. 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 string "BCD" 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" ASC(ThisChar : CHAR) RETURNS INTEGER returns the ASCII value of character ThisChar Example: ASC('A') returns 65 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 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

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

Mark scheme, page 3

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 3 of 16 Question Answer Marks 1(a) Description of data item Suitable identifier name The temperature inside the greenhouse GreenhouseTemperature The temperature outside the greenhouse OutsideTemperature The greenhouse identification number GreenhouseID The time the temperature was measured SampleTime The above are examples only. Names must be meaningful and unambiguous 4 1(b)(i) Expression Evaluates to "Fas" & MID(Subject, 6, 3) "Faster" LEFT(Mark, 1) ERROR 10 + ASC(Grade) 76 MOD(AverageMark * 2, 3) 0 CourseCompleted AND (Mark >= 60) TRUE 5 1(b)(ii) Variable Data type Mark INTEGER Subject STRING Grade CHAR CourseCompleted BOOLEAN AverageMark REAL One mark per answer 5

Mark scheme, page 4

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 4 of 16 Question Answer Marks 2(a)(i) • Keywords in capitals • White Space / blank lines / grouping • Comments • Sensible function names Max 2 2(a)(ii) • Indentation • Meaningful identifier names 2 2(b) Feature Answer A line number containing an example of an assignment statement 08 / 09 / 13 / 14 / 15 / 21 A line number containing the start of a ‘pre- condition’ loop 11 A line number containing the end of a ‘pre- condition’ loop 24 A line number containing the start of a selection statement 17 The number of parameters of the LEFT() function 2 The Boolean operator used OR The number of times the function LEFT() is called from within CountDigits() resulting from the call: Result ← CountDigits("AB27C4") 6 The number of local variables 3 8 2(c)(i) • Mistake: function header returns a CHAR but last line of code returns an INTEGER • Correction: Function should return an INTEGER // Change line 26 to return c as CHAR 2

Mark scheme, page 5

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 5 of 16 Question Answer Marks 2(c)(ii) IF (nc >= '0') AND (nc <= '9') THEN c ← c + 1 ENDIF One mark for each of: • Single IF THEN ENDIF statement (no ELSE) • Switching OR to AND • Lower value comparison • Upper value comparison ALTERNATIVE: IF NOT ((nc < '0') OR (nc > '9')) THEN c ← c + 1 ENDIF One mark for each of: • Single IF THEN ENDIF statement (no ELSE) • Inverting test using NOT« • ... correct use of brackets • « both comparisons unchanged 4

Mark scheme, page 6

9 © Q 9608/22 © UCLES 2018 Question 3 Example P Cambridg Program Flo ge Internatio P owchart onal AS/A L PUBLISHED Page 6 of 16 Answer Level – Mar D k Scheme Ma ay/June 201 Marks 10 18

Mark scheme, page 7

9 © Q Q 9608/22 © UCLES 2018 Question 3 Question 4(a)(i) One mark 1 STAR 2 Initial 3 Initial 4 Decis 5 Decis 6 Decis 7 Corre 8 Corre 9 Outpu excee 10 Callin mess Mark as fo • One m • One m Cambridg k for each of RT and END ising Count ising Index sion box com sion box com sion box com ect incremen ect incremen ut message eded ng Servic age) ollows: mark for thr mark for dia ge Internatio P f: D / STOP t to 0 x to 1 or 0 mparing Ba mparing In mparing Co nt of Index nt of Count e (concatena eCheck() ree arrows a amond symb onal AS/A L PUBLISHED Page 7 of 16 Answer rWeight[ dex to 100 unt > Thre x t ation of text if Thresho Answer all labelled X bol Level – Mar D Index] > M eshold t and value) old exceed X (with filled k Scheme MaxWeight ) if threshold ed (without d circles) Ma t d not t text ay/June 201 Marks 10 Marks 2 18

Mark scheme, page 8

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 8 of 16 Question Answer Marks 4(a)(ii) Parameter Information A BasketID B BasketID, ItemID, Quantity (In any order) C D E BasketID, DeliveryAddress, PaymentDetails (In any order) F G Mark as follows: • One mark for parameter A • One mark for parameters B, C & D • One mark for parameters E, F & G 3 Question Answer Marks 5(a) One mark for each of: • Same data type using a single identifier / more efficient coding / less declaration statements needed • Access of individual elements (using subscript / index) • Ability to iterate through the data // easier to search / sort the data • Code easier to understand / maintain / modify Max 2 5(b) One mark for each of: • (Dynamic) syntax checking / Errors are highlighted / underlined • Type checking • Parameter checking • Identification of unused variables Max 2

Mark scheme, page 9

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 9 of 16 Question Answer Marks 5(c) Example ‘Pseudocode’ solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. FUNCTION GetNumber() AS STRING DECLARE Valid : BOOLEAN DECLARE MemberNumber : INTEGER REPEAT Valid ← TRUE OUTPUT "Please input a valid member number" INPUT MemberNumber IF (MemberNumber > 9999) OR (MemberNumber < 1111) THEN Valid ← FALSE ENDIF UNTIL Valid = TRUE RETURN STR(MemberNumber) ENDFUNCTION 1 mark for each of the following: 1 Function heading (as above) and ending 2 Conditional loop structure 3 Condition to check valid membership number 4 Returning string value 4

Mark scheme, page 10

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 10 of 16 Question Answer Marks 5(d) ‘Pseudocode’ solution included here for development and clarification of mark scheme. Programming language solutions appear in the Appendix. PROCEDURE OutputLowestScore() DECLARE FileData, FileMembershipNumber : STRING DECLARE FileScore, LowestScore : INTEGER DECLARE LowestScoreDate, MembershipNumber : STRING MembershipNumber ← GetNumber() OPENFILE "ScoreDetails.txt" FOR READ LowestScore ← 100 WHILE NOT EOF("ScoreDetails.txt") READFILE "ScoreDetails.txt", FileData FileMembershipNumber ← LEFT(FileData, 4) IF FileMembershipNumber = MembershipNumber THEN FileScore ← INT(RIGHT(FileData,2)) IF FileScore < LowestScore THEN LowestScore ← FileScore LowestScoreDate ← MID(FileData(5,6)) ENDIF ENDIF ENDWHILE OUTPUT ("The lowest score was " & LowestScore & " on " & _ LowestScoreDate) CLOSEFILE("ScoreDetails.txt ") ENDPROCEDURE 1 mark for each of the following: 1 Declare variables to store LowestScore as INTEGER and FileData as STRING (commented in Python) (variable names may be different) 2 Function call GetNumber() for membership number 3 Initialisation of LowestScore to 99 or above 4 Open file in READ mode 5 Loop until EOF() 6 Read a line from the file in a loop 7 Use of substring operations to extract at least one data item 8 Compare the membership numbers 9 Convert score to INTEGER 10 Compare and assign (if appropriate) new value to LowestScore 11 Output the lowest score message including lowest score and date (outside the loop) 12 Close the file Max 10

Mark scheme, page 11

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 11 of 16 Question Answer Marks 6(a) • lower bound • upper bound 2 6(b) Example using single temp variable: PROCEDURE Flip() //Use of Single temp value DECLARE temp : INTEGER DECLARE i : INTEGER //i is the row DECLARE j : INTEGER //j is the column FOR i ← 1 TO 5 FOR j ← 1 to 4 //swap element 1&8, 2&7, 3&6, 4&5 temp ← Picture[i,j] Picture[i,j] ← Picture[i, 9 - j] Picture[i, 9 - j] ← temp ENDFOR ENDFOR ENDPROCEDURE Alternative Solution – Use of temp array row: PROCEDURE Flip() //Use of temproary row (8 elements) DECLARE temp : ARRAY[1:8] OF INTEGER DECLARE i : INTEGER //i is the row DECLARE j : INTEGER //j is the column FOR i ← 1 to 5 FOR j ← 1 to 8 temp[j] ← Picture[i, 9 – j] //temp is row i reversed ENDFOR FOR j ← 1 to 8 Picture[i,j] ← temp[j] //copy temp back to row i ENDFOR ENDFOR ENDPROCEDURE 8

Mark scheme, page 12

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 12 of 16 Question Answer Marks 6(b) Alternative Solution – Use of new array: PROCEDURE Flip() //Flip to New array DECLARE NewPic : ARRAY[1:5, 1:8] OF INTEGER DECLARE i : INTEGER //i is the row DECLARE j : INTEGER //j is the column FOR i ← 1 to 5 FOR j ← 1 to 8 NewPic[i, 9 - j] ← Picture[i, j] //NewPic row is Pic row flipped ENDFOR ENDFOR END PROCEDURE 1 mark for each of the following (all methods): 1 Correct procedure heading and ending 2 Declaring local variables for loop counter(s) 3 Declaring a temporary storage variable for swap or new duplicate 2D array 4 A nested loop including attempt at flip operation « 5 « Correct number of iterations 6 Assign element to temp (single var or temp array) or to new array 7 Selection of correct source element (row, column) 8 Selection of correct destination element (row, column) 8 *** End of Mark Scheme – program code solutions follow ***

Mark scheme, page 13

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 13 of 16 Appendix Program Code Example Solutions Q5 (c): Visual Basic Function GetNumber() As String Dim Valid As Boolean Dim MemberNumber As Integer Do Valid = True Console.Write("Please enter a valid member number: ") MemberNumber = Console.ReadLine() If MemberNumber > 9999 Or MemberNumber < 1111 Then Valid = False End If Loop Until Valid = True Return MemberNumber.ToString() End Function Q5 (c): Pascal function GetNumber() : string; var Valid : boolean; MemberNumber : integer; begin repeat Valid := true; write('Please enter a valid member number: '); readln(MemberNumber); if (MemberNumber > 9999) or (MemberNumber < 1111) then Valid := false; until Valid = true; GetNumber := IntToStr(MemberNumber); end; Q5 (c): Python def GetNumber() : # Valid : boolean # MemberNumber : integer Valid = False while not Valid : Valid = True MemberNumber = int(input("Please enter a valid member number: ")) if MemberNumber > 9999 or MemberNumber < 1111 : Valid = False return str(MemberNumber)

Mark scheme, page 14

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 14 of 16 Q5 (d): Visual Basic Sub OutputLowestScore() Dim FileData As String Dim FileMembershipNumber As String Dim FileScore As Integer Dim LowestScore As Integer Dim LowestScoreDate As String Dim MembershipNumber As String MembershipNumber = GetNumber() FileOpen(1, "ScoreDetails.txt", OpenMode.Input) LowestScore = 100 While Not EOF(1) FileData = LineInput(1) FileMembershipNumber = Left(FileData, 4) If FileMembershipNumber = MembershipNumber Then FileScore = Integer.Parse(Right(FileData, 2)) If FileScore < LowestScore Then LowestScore = FileScore LowestScoreDate = Mid(FileData, 5, 6) End If End If End While Console.WriteLine("The lowest score was " & LowestScore & " on " & LowestScoreDate) FileClose(1) End Sub

Mark scheme, page 15

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 15 of 16 Q5 (d): Pascal procedure OutputLowestScore(); var FileData : string; FileMembershipNumber : string; FileScore : integer; LowestScore : integer; LowestScoreDate : string; MembershipNumber : string; Scores : textFile; begin MembershipNumber := GetNumber(); assignFile(Scores, 'ScoreDetails.txt'); reset(Scores); LowestScore := 100; while not eof(Scores) do begin readln(Scores, FileData); FileMembershipNumber := copy(FileData, 1, 4); if FileMembershipNumber = MembershipNumber then begin FileScore:= StrToInt(copy(FileData, 11, 2)); if FileScore < LowestScore then begin LowestScore := FileScore; LowestScoreDate := copy(FileData, 5, 6) end; end; end; writeln('The lowest score was ', LowestScore, ' on ', LowestScoreDate); close(Scores); end;

Mark scheme, page 16

9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2018 © UCLES 2018 Page 16 of 16 Q5 (d): Python def OutputLowestScore() : # FileData : string # FileMembershipNumber : string # FileScore : integer # LowestScore : integer # LowestScoreDate : string # MembershipNumber : string # File : file handle MembershipNumber = GetNumber() File = open("ScoreDetails.txt", "r") LowestScore = 100 FileData = File.readline() while FileData != "": FileMembershipNumber = FileData[:4] if FileMembershipNumber == MembershipNumber : FileScore = int(FileData[10:12]) if FileScore < LowestScore : LowestScore = FileScore LowestScoreDate = FileData[4:10 FileData = File.readline() print("The lowest score was ", LowestScore, " on ", LowestScoreDate) File.close()

What you needed in this session

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

A51/75
B43/75
C37/75
D31/75
E24/75