Cambridge A Level Computer Science 9608 — 2016 Oct/Nov Paper 2 · Variant 2

9608/22/O/N/16 · 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 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 1 of 20
Page 1 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 2 of 20
Page 2 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 3 of 20
Page 3 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 4 of 20
Page 4 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 5 of 20
Page 5 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 6 of 20
Page 6 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 7 of 20
Page 7 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 8 of 20
Page 8 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 9 of 20
Page 9 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 10 of 20
Page 10 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 11 of 20
Page 11 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 12 of 20
Page 12 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 13 of 20
Page 13 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 14 of 20
Page 14 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 15 of 20
Page 15 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 16 of 20
Page 16 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 17 of 20
Page 17 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 18 of 20
Page 18 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 19 of 20
Page 19 of 20
Cambridge A Level Computer Science 9608 2016 Oct/Nov Paper 2 · Variant 2 question paper, page 20 of 20
Page 20 of 20

Mark scheme15 pages

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

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

Paper as text

Question paper, page 1

This document consists of 19 printed pages and 1 blank page. DC (NF/SG) 115874/3 © UCLES 2016 [Turn over Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level * 2 4 6 3 1 7 0 7 0 6 * COMPUTER SCIENCE 9608/22 Paper 2 Fundamental Problem-solving and Programming Skills October/November 2016 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/O/N/16 © UCLES 2016 There is an Appendix on pages 18 and 19. Some questions will refer you to this information. 1 A number of players take part in a competition. The competition consists of a number of games. Each game is between two players. The outcome of a game is that each player is awarded a grade (A, B, C or D). Each grade has an associated number of points as shown in the table below. Grade Points A 0 B 1 C 3 D 5 The points total for all players is recorded. After each game is completed, the total number of points for each player is updated. For example: • before the game between Ryan and Karina, Ryan’s total is 5 points and Karina’s total is 3 points • the result of the game between Ryan and Karina is: Ryan achieved grade B, Karina achieved grade D • the players’ points totals are updated to: Ryan has 6 and Karina has 8 When a player’s points total reaches 12 or higher, that player is removed from the competition. A programmer will write a program to update the player total after a game. The program will output: • the player’s updated points total • the message ‘ELIMINATED’ if the player is removed from the competition. The programmer designs the identifier table below: Identifier Data type Description PlayerName STRING Name of the player PlayerGameGrade CHAR Game grade for the player PointsTotal INTEGER Current player points SavePlayerTotal procedure Procedure has parameters PlayerName and PointsTotal and saves the updated player total ReadPlayerTotal function Function has a parameter PlayerName and returns the current total for that player (a) Complete the following program flowchart by: • filling in the boxes, using pseudocode where appropriate • labelling the lines of the flowchart, where necessary. [9]

Question paper, page 3

3 9608/22/O/N/16 © UCLES 2016 [Turn over Start Yes No Stop

Question paper, page 4

4 9608/22/O/N/16 © UCLES 2016 (b) Test data is to be produced to test the flowchart. Complete the table of test data below to show five tests that should be used to test different paths through the flowchart. Test data Expected results PointsTotal PlayerGameGrade Updated PointsTotal Output [5] (c) The programmer amends the design to validate the value of player game grade that the user inputs. The amended part of the flowchart is shown below. Is PlayerGameGrade = 'A' or 'B' or 'C' or 'D'? INPUT PlayerGameGrade OUPUT "Invalid – Re-enter" No Yes Loop

Question paper, page 5

5 9608/22/O/N/16 © UCLES 2016 [Turn over Write the equivalent pseudocode using a pre-condition loop, for this part of the amended flowchart. … … … … … … … … … … … [3] 2 You will need to refer to the list of pseudocode string-handling functions in the Appendix. (a) Give the value of the variables x, y and z for the following sequence of statements. (i) x ONECHAR("Barcelona", 5) x … [1] (ii) y ONECHAR("Cool", 1) & ONECHAR("Ball", 2) & "t-food" y … [1] (iii) Temp1 "13" Temp2 ONECHAR("One-2-One", 5) z TONUM(Temp2 & Temp1) z … [1] A computer program is to simulate the reading and processing of a string of characters from an input device. The character string consists of: • a number of digit characters • one or more <*> characters, each used as a separator • a final <#> character. A typical input character sequence, stored as InputString is: 13*156*9*86*1463*18*#

Question paper, page 6

6 9608/22/O/N/16 © UCLES 2016 Study this pseudocode. 01 DECLARE Numbers ARRAY [1:100] OF INTEGER 02 DECLARE InputString : STRING 03 DECLARE NextChar : CHAR 04 DECLARE NextNumberString : STRING 05 DECLARE i : INTEGER // Numbers array index 06 DECLARE j : INTEGER // InputString index 07 08 OUTPUT "String ... " 09 INPUT InputString 10 j 1 11 NextChar ONECHAR(InputString, j) 12 13 i 1 14 WHILE NextChar <> '#' 15 NextNumberString = "" 16 WHILE NextChar <> '*' 17 NextNumberString NextNumberString & NextChar 18 j j + 1 19 NextChar ONECHAR(InputString, j) 20 ENDWHILE 21 22 // store the next integer to the array 23 Numbers[i] TONUM(NextNumberString) 24 i i + 1 25 j j + 1 26 NextChar ONECHAR(InputString, j) 27 ENDWHILE 28 29 CALL DisplayArray() (b) Write the line number for: (i) A statement which declares a global variable used to store a single character. … [1] (ii) A statement which runs code written as a procedure. … [1] (iii) A statement which indicates the start of a ‘pre-condition’ loop. … [1] (iv) A statement which increments a variable. … [1] (c) Copy the condition which is used to control the inner loop. … [1]

Question paper, page 7

7 9608/22/O/N/16 © UCLES 2016 [Turn over (d) (i) Complete the trace table below for the given pseudocode as far as line 27. The input string is: 23*731*5*# i j NextChar NextNumberString Numbers 1 2 3 1 1 '2' "" "2" 2 '3' "23" 3 '*' 23 [5] (ii) Explain what this algorithm does. … … … … [2]

Question paper, page 8

8 9608/22/O/N/16 © UCLES 2016 3 Radhika mostly studied the high-level programming language XYZ at university. She has been working in her first job for two years using language XYZ. She applied for a new job which stated: “The majority of the development work is done using language ABC.” (a) Radhika was interviewed for the job. Part of the interview process was to study some program code written in language ABC. 11 settype($TimesTable, Integer); 12 settype($upTo, Integer); 13 settype($Posn, Integer); 14 settype($Product, Integer); 15 $TimesTable = 7; 16 $UpTo = 10; 17 18 $Posn = 1 19 While ($Posn < $UpTo + 1) 20 { 21 $Product = $Posn * $TimesTable; 22 Echo $Posn . ' X' . $TimesTable . ' = ' . $Product . "<br>"; 23 $Posn = $Posn + 1; 24 } Answer the following questions taken from the interview. (i) State what the settype keyword does in this language. … … [1] (ii) Name one variable that the code uses. … [1] (iii) Give a line number for an assignment statement. … [1] (iv) Line 19 is the start of a pre-condition loop. State the syntax that language ABC uses to indicate which statements must be executed inside a loop. … [1]

Question paper, page 9

9 9608/22/O/N/16 © UCLES 2016 [Turn over (b) (i) Describe what is meant by a transferable skill. … … … [2] (ii) Give two examples which suggest that programming in a high-level language is a transferrable skill. 1 … … 2 … … [2]

Question paper, page 10

10 9608/22/O/N/16 © UCLES 2016 4 A social club runs a weekly prize draw. A member can buy a ticket for $2. Each week, the club sells up to 150 tickets, with consecutive numbers starting from 1. There is a main cash prize of $120 and a further three prizes of $10. The computer program will generate the winning numbers. Throughout this question, you will need to refer to the list of pseudocode functions in the Appendix. (a) Write pseudocode to show how the RND()function can be used to generate a single integer in the range 1 to 150. … … [3] (b) Write program code to generate and output four winning numbers. Ignore the issue that duplicate numbers may be generated. Visual Basic and Pascal: You should include declaration statements for variables. Python: You should show a comment statement for each variable used with its data type. … … … … … … … [4] (c) The prize draw is a success. After six months, the club decided to sell an unlimited number of tickets each week. In any week, the total number of prizes may vary. The programmer modifies the code written in part(b). The revised program will use a function to generate a single winning number. Therefore, in a week when the club offers six prizes, the program will use the function six times to generate the six winning numbers. The function has identifier GenerateNumber and: • has a single parameter for the number of tickets sold that week • returns a single winning number. Write program code for the function header. Programming language … … … [3]

Question paper, page 11

11 9608/22/O/N/16 © UCLES 2016 [Turn over (d) The organisers do not want the same number to be drawn more than once in a week. To deal with the issue of duplicate numbers being generated, the program in part (b) will require adaptive maintenance. (i) Describe what is meant by adaptive maintenance. … … … … [2] (ii) The club does not want the program to output the same number more than once in a week. For each winning number, outline the extra steps that the program must have. Include any data structure that the program needs. Do not write pseudocode or program code. … … … … … [3]

Question paper, page 12

12 9608/22/O/N/16 © UCLES 2016 5 A team keeps a record of the scores made by each of their eight players in a number of games. The data in the two tables below shows: • the scores of the eight players after twenty games • the eight player names. 1 2 3 8 1 12 17 67 31 2 35 82 44 29 3 61 39 80 17 4 81 103 21 11 5 56 0 98 4 … 19 45 6 81 77 20 12 11 3 6 1 Vorma 2 Ravi 3 Chada 4 Nigam 5 Bahri 6 Smith 7 Goyal 8 Lata The team wants a computer program to input and record the player data. (a) A programmer designs the following pseudocode for the input of a player’s score from one game. 01 INPUT GameNumber 02 INPUT PlayerNumber 03 INPUT PlayerGameScore 04 PlayerScore[GameNumber, PlayerNumber] PlayerGameScore Describe the data structure the programmer has used for the storage of all player scores. … [2]

Question paper, page 13

13 9608/22/O/N/16 © UCLES 2016 [Turn over (b) The player names are permanently stored in a text file NAMES.TXT, with one name on each line. The player names will be read by the program and stored in a 1D array. The design given in part (a) will be expanded so that the user is prompted for the player name instead of the player number. Step 02 now becomes: 02.1 Read the player names from file NAMES.TXT into the array PlayerName 02.2 INPUT ThisPlayerName 02.3 Search the PlayerName array for ThisPlayerName to find the PlayerNumber (i) State the computing term for the expansion of one or more steps in the original design. … [1] (ii) Write the program code for step 02.1 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 … … … … … … … … … … … … … [4]

Question paper, page 14

14 9608/22/O/N/16 © UCLES 2016 (iii) Program code is to be designed and written for step 02.3 The program will use these identifiers: Identifier Data type Description PlayerName ARRAY[1 : 8] OF STRING Stores the player names (read from the file) ThisPlayerName STRING Input by the user (step 02.2) Found BOOLEAN Flags when ThisPlayerName is found when searching the PlayerName array i INTEGER Array index Write program code to carry out the linear search for step 02.3 There is no requirement to declare or comment on variables used. Programming language … … … … … … … … … … … … … [4]

Question paper, page 15

15 9608/22/O/N/16 © UCLES 2016 [Turn over (c) The team wants the program to produce a report, with the following specification. The program outputs the total number of player scores that are: • 50 and over but less than 100 • 100 or higher. You can assume that before the section runs, the program has assigned all eight player scores to the PlayerScore data structure. A first attempt at the pseudocode is shown below: 01 Total50 0 02 Total100 0 03 FOR PlayerIndex 1 TO 8 04 FOR GameIndex 1 TO 20 05 IF PlayerScore[GameIndex, PlayerIndex] > 100 06 THEN 07 Total100 Total100 + 1 08 ELSE 09 IF PlayerScore[GameIndex, PlayerIndex] > 50 10 THEN 11 Total50 Total50 + GameIndex 12 ENDIF 13 ENDIF 14 ENDFOR 15 ENDFOR 16 OUTPUT Total50 17 OUTPUT Total100 (i) Describe the control structure used in lines 03 and 04 and lines 14 and 15. … … … [2]

Question paper, page 16

16 9608/22/O/N/16 © UCLES 2016 (ii) Consider the following two statements. Write either TRUE or FALSE next to each statement. Statement TRUE or FALSE The pseudocode considers all the scores for a player, before progressing to the next player. The pseudocode considers all scores in a game, before progressing to the next game. [1] (iii) The programmer has made logic errors in the design. State a line number at which an error occurs. Explain the error or write the corrected pseudocode statement. Line number … Explanation … … [1]

Question paper, page 17

17 9608/22/O/N/16 © UCLES 2016 [Turn over 6 Study the sequence of pseudocode statements. CONST a = 3.2 : REAL DECLARE x, y, z, Answer1, Answer2, Answer3 : REAL DECLARE p, q : BOOLEAN x 3 x x + 7 y 6 Answer1 2 * (a + y) z 6 Answer2 y ^ 2 + 5 p TRUE q NOT(NOT(p)) Answer3 y + a * 2 Give the final value assigned to each variable. (i) x … [1] (ii) Answer1 … [1] (iii) Answer2 … [1] (iv) q … [1] (v) Answer3 … [1]

Question paper, page 18

18 9608/22/O/N/16 © UCLES 2016 Appendix Built-in functions (pseudocode) ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR returns the single character at position Position (counting from the start of the string with value 1) from the string ThisString. For example: ONECHAR("New York", 5) returns 'Y' CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER returns the number of characters in ThisString. For example: CHARACTERCOUNT("New York") returns 8 SUBSTR(ThisString : STRING, Value1 : INTEGER, Value2 : INTEGER) RETURNS STRING returns a sub-string from within ThisString. Value1 is the start index position (counting from the left, starting with 1). Value2 is the final index position. For example: SUBSTR("art nouveau", 5, 11) returns "nouveau" TONUM(ThisString : STRING) RETURNS INTEGER or REAL returns the integer or real equivalent of the string ThisString. For example: TONUM("502") returns the integer 502 TONUM("56.36") returns the real number 56.36 ASC(ThisCharacter : CHAR) RETURNS INTEGER returns an integer which is the ASCII character code for the character ThisCharacter. For example: ASC('A') returns integer 65

Question paper, page 19

19 9608/22/O/N/16 © UCLES 2016 CHR(Value : INTEGER) RETURNS CHAR returns the character that ASCII code number Value represents. For example: CHR(65) returns 'A' RND() RETURNS REAL returns a random number in the range 0 to 0.99999 For example: RND() returns 0.67351 INT(ThisNumber : REAL) RETURNS INTEGER returns the integer part of ThisNumber. For example: INT(12.79) returns 12 Errors For any function, if the program calls the function incorrectly, the function returns an error. Concatenation operator & operator – Concatenates two expressions of STRING or CHAR data type. For example: "South" & " " & "Pole" produces "South Pole" 'B' & "000654" produces "B000654"

Question paper, page 20

20 9608/22/O/N/16 © UCLES 2016 BLANK PAGE 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.

Mark scheme, page 1

® IGCSE is the registered trademark of Cambridge International Examinations. This document consists of 15 printed pages. © UCLES 2016 [Turn over Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level COMPUTER SCIENCE 9608/22 Paper 2 Written Paper October/November 2016 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 will not enter into discussions about these mark schemes. Cambridge is publishing the mark schemes for the October/November 2016 series for most Cambridge IGCSE®, Cambridge International A and AS Level components and some Cambridge O Level components.

Mark scheme, page 2

Page 2 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 1 (a)

Mark scheme, page 3

Page 3 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 Mark as follows: • One mark per shape, correctly labelled (except for three assignments as noted above) • One mark for three selection values ('B', 'C' and 'D') [9] (b) PointsTotal PlayerGameGrade Updated Output n A n n n B n + 1 n + 1 n C n + 3 n + 3 n D n + 5 n + 5 e.g. 10 e.g. C 13 13 ELIMINATED One mark per complete row testing different routes through the algorithm. [5] (c) INPUT PlayerGameGrade WHILE NOT(PlayerGameGrade = 'A' OR PlayerGameGrade = 'B' OR PlayerGameGrade = 'C' OR PlayerGameGrade = 'D') OUTPUT "Invalid – Re-enter" INPUT PlayerGameGrade ENDWHILE One mark for each of: • WHILE ... ENDWHILE • Correct condition in a loop • INPUT within loop plus one before loop // alternative arrangement leading to correct exit from loop [3] 2 (a) (i) 'e' [1] (ii) "Cat-food" [1] (iii) 213 [1] (b) (i) 03 // 3 [1] (ii) 29 [1] (iii) 14 // 16 [1] (iv) 18 // 24 // 25 [1]

Mark scheme, page 4

Page 4 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 (c) NextChar <> '*' [1] (d) (i) Numbers i j NextChar NextNumberString 1 2 3 1 1 '2' "" "2" 2 '3' "23" 3 '*' 23 2 4 '7' "" "7" 5 '3' "73" 6 '1' 7 '*' "731" 731 3 8 '5' "" 9 '*' "5" 5 4 10 '#' One mark for each of columns 1 to 4 One mark for numbers 2 & 3 as shown in box [5] (ii) One mark for each of: • Isolates / separates / splits up each numeric string / the numbers / data string separated by '*' • Converts each numeric string / each number into an integer and • Stores each integer in array (Numbers) [Max. 2]

Mark scheme, page 5

Page 5 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 3 (a) (i) Declaration of a variable // identifier [1] (ii) $TimesTable, // $UpTo // $Posn // $Product [1] (iii) 15 // 16 // 18 // 21 // 23 [1] (iv) Statements inside the loop are enclosed by curly brackets {} // or by example, such as {<statements>} [1] (b) (i) • a learned / existing skill… • … which can be applied to / used in a new situation / role [2] (ii) The ability to recognise: • Similar syntax – Assignment / variables / data types – Common operators / symbols for functions (+, –, /, *, OR, AND, >, <…) • Control Structures – Iteration – Selection – Sequence – Layout / format (e.g. indentation) • Modular features – Objects – Procedures / Functions Any two of the above. [Max. 2]

Mark scheme, page 6

Page 6 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 4 (a) INT(RND() * 150 ) + 1 One mark for each part as follows: • RND() * 150 • + 1 • INT() [3] (b) ‘Pseudocode’ solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. Expected Loop-based solution: DECLARE i , NextNumber : INTEGER FOR i ← 1 TO 4 NextNumber ← 1 + INT(Rnd() * 150) OUTPUT NextNumber ENDFOR Mark as follows: • Declaration of all variables used including data types • Loop • Assignment / calculation of (four) different random numbers (0 to 150) in a loop • Output of four values ALTERNATIVE Non-Loop version DECLARE Num1, Num2, Num3, Num4 : INTEGER Num1 ← INT(RND() * 150)) + 1 Num2 ← INT(RND() * 150)) + 1 Num3 ← INT(RND() * 150)) + 1 Num4 ← INT(RND() * 150)) + 1 OUTPUT Num1, Num2, Num3, Num4 Mark as follows: • Declaration of all variables used including data types • Assignment of four different random numbers (0 to 150) • Assignment to four separate variables • Output of four values [4]

Mark scheme, page 7

Page 7 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 (c) Visual Basic Function GenerateNumber(ByVal AnyName AS INTEGER) AS INTEGER Pascal FUNCTION GenerateNumber (AnyName : INTEGER) : INTEGER Python def GenerateNumber (AnyName): • Mark as follows: • Correct keyword + Function name • Single input parameter of correct type • Return parameter type [3] (d) (i) • Program code is modified • following a change to the requirements [2] (ii) • Use an array / list / file to store each number generated // a flag value • Check the array / list / file to see if the new random number has already been drawn • If YES, generate another number • If NO, output the number and update the array / list / file [Max. 3] 5 (a) • 2D array • of type integer • with identifier PlayerScore [Max. 2] (b) (i) Stepwise refinement // Top-Down Design [1] (ii) ‘Pseudocode’ solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. DECLARE ThisPlayerName : STRING DECLARE PlayerName : ARRAY[1:8) OF STRING DECLARE i : INTEGER OPENFILE "NAMES.TXT" FOR READ i ← 1 WHILE NOT EOF("NAMES.TXT") READFILE "NAMES.TXT", ThisPlayerName PlayerName[i] ← ThisPlayerName i ← i + 1 ENDWHILE CLOSEFILE "NAMES.TXT" One mark for each of: • File open in read mode • Loop until EOF() or count-controlled (8 iterations) • Read a line from the file in a loop • Assignment to PlayerName[1 to 8]from the file in a loop] Close file [Max. 4]

Mark scheme, page 8

Page 8 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 (iii) ‘Pseudocode’ solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. // search for player name … Found ← FALSE i ← 1 REPEAT IF ThisPlayerName = PlayerName[i] THEN Found ← TRUE PlayerNumber ← i ELSE i ← i + 1 ENDIF UNTIL (Found = TRUE) OR (i = 9) One mark for each of: • Initialise i to 1 and Found to FALSE • Loop through array PlayerName (including exit when found) • Comparison: ThisPlayerName = PlayerName[i] in a loop • Found set to TRUE if ThisPlayerName found [Max. 4] (c) (i) • a nested // an inner and an outer • count controlled // incremented loop(s) [2] (ii) … True … False Both answers must be correct [1] (iii) Error line number 5, 9 or 11 as follows: Line 5: The boundary value must be included // IF PlayerScore[GameIndex, PlayerIndex] >= 100 // > 99 Line 9: The boundary value must be included // IF PlayerScore[GameIndex, PlayerIndex] >= 50 // > 49 Line 11: One should be added to Total50 (not GameIndex) // Total50 ← Total50 + 1 One mark for line number + explanation [1]

Mark scheme, page 9

Page 9 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 6 (i) 10 / 10.0 [1] (ii) 18.4 [1] (iii) 41 [1] (iv) TRUE [1] (v) 12.4 [1]

Mark scheme, page 10

Page 10 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 Appendix – Program code example solutions Q4 (b): Visual Basic Randomize() Dim i As Integer Dim NextNumber As Integer For i = 1 To 4 NextNumber = 1 + Int(Rnd() * 150) Console.WriteLine(NextNumber) Next OR Randomize() Dim Num1, Num2, Num3, Num4 As Integer Num1 = 1 + Int(Rnd() * 150) Num2 = 1 + Int(Rnd() * 150) Num3 = 1 + Int(Rnd() * 150) Num4 = 1 + Int(Rnd() * 150) Console.WriteLine(Num1, Num2, Num3, Num4) Q4 (b): Pascal Var i : Integer; NextNumber : Integer; Begin Randomize; For i := 1 To 4 Do Begin NextNumber := 1 + Random(150); Writeln(NextNumber); End; Readln; End. OR Var Num1, Num2, Num3, Num4 : Integer; Begin Randomize; Num1 := 1 + Random(150); Num2 := 1 + Random(150); Num3 := 1 + Random(150); Num4 := 1 + Random(150); Writeln(Num1, Num2, Num3, Num4); Readln; End.

Mark scheme, page 11

Page 11 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 Q4 (b): Python import random # i : Integer # NextNumber : Integer for i in range(1, 5) : NextNumber = 1 + int(150 * random.random()) print(NextNumber) Alternative: import random # i Integer # NextNumber Integer for i in range(1, 5) : NextNumber = random.randint(1, 150) print(NextNumber) OR import random # i Integer # Num1, Num2, Num3, Num4 Integer Num1 = random.randint(1, 150) Num2 = random.randint(1, 150) Num3 = random.randint(1, 150) Num4 = random.randint(1, 150) print(Num1, Num2, Num3, Num4)

Mark scheme, page 12

Page 12 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 Q5 (b) (ii): Visual Basic Dim PlayerName(8) As String Dim i As Integer FileOpen(1, "Names.txt", OpenMode.Input) i = 1 Do PlayerName(i) = LineInput(1) i = i + 1 Loop Until EOF(1) FileClose(1) Alternative: Dim PlayerName(8) As String Dim i As Integer FileOpen(1, "Names.txt", OpenMode.Input) For i = 1 To 8 PlayerName(i) = LineInput(1) Next FileClose(1) Alternative: Dim sr As StreamReader = New StreamReader("Names.txt") Dim line As String line = sr.ReadLine() i = 1 Do While (line <> Nothing) PlayerName(i) = line i = i + 1 line = sr.ReadLine() Loop sr.Close()

Mark scheme, page 13

Page 13 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 Q5 (b) (ii): Pascal Var Names : TextFile; i : Integer; PlayerName : Array[1..8] Of String; Begin AssignFile(Names, 'Names.txt'); Reset(Names); i := 1; While Not Eof(Names) Do Begin Readln(Names, PlayerName[i]); Writeln(PlayerName[i]); i := i + 1; End; Close(Names); Readln; End. Alternative: Var Names : TextFile; i : Integer; PlayerName : Array[1..8] Of String; Begin AssignFile(Names, 'Names.txt'); Reset(Names); For i := 1 To 8 Do Begin Readln(Names, PlayerName[i]); Writeln(PlayerName[i]); End; Close(Names); Readln; End.

Mark scheme, page 14

Page 14 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 Q5 (b) (ii): Python # PlayerName : List # NextPlayer : String # File : File handle File = open("Names.txt", "r") PlayerName = [] while (1) : NextPlayer = File.readline() if not NextPlayer : break else : PlayerName.append(NextPlayer) File.close() Alternative: # PlayerName : List # NextPlayer : String # File : File handle # i : Integer File = open("Names.txt", "r") PlayerName = [] for i in range(1, 9) : NextPlayer = File.readline() PlayerName.append(NextPlayer) File.close() Alternative: # PlayerName : List # NextPlayer : String # File : File handle # i : Integer File = open("Names.txt", "r") PlayerName = ["" for i in range(8)] for i in range(1, 9) : PlayerName[i – 1] = File.readline() File.close()

Mark scheme, page 15

Page 15 Mark Scheme Syllabus Paper Cambridge International AS/A Level – October/November 2016 9608 22 © UCLES 2016 Q5 (b) (iii): Visual Basic Found = False i = 1 Do If ThisPlayerName = PlayerName(i) Then Found = True PlayerNumber = i Else i = i + 1 End If Loop Until Found = True Or i = 9 Q5 (b) (iii): Pascal Begin Found := False; i := 1; Repeat If (ThisPlayerName = PlayerName[i]) Then Begin Found := True; PlayerNumber := i; End Else i := i + 1; Until (Found) Or (i = 9); End. Q5 (b) (iii): Python Found = FALSE PlayerName = [j.strip() for j in PlayerName] if ThisPlayerName in PlayerName : PlayerNumber = PlayerName.index(ThisPlayerName) + 1 Found = TRUE Alternative: Found = False i = 1 while not Found and i < 9 : if ThisPlayerName == PlayerName[i].strip() : Found = True PlayerNumber = i else : i = i + 1 Alternative: Found = False for i in range(1, 9) : if ThisPlayerName == PlayerName[i].strip() : Found = True PlayerNumber = i

What you needed in this session

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

A48/75
B41/75
C33/75
D25/75
E18/75