Cambridge A Level Computer Science 9608 — 2017 May/June Paper 2 · Variant 2
9608/22/M/J/17 · 75 marks · ≈84 min
The question paper and its mark scheme, free to read here and free to download. This is Cambridge’s own paper, exactly as it was sat.
Question paper16 pages
















Mark scheme8 pages
Answers below. Sit the paper first if you are practising.








Paper as text
Question paper, page 1
This document consists of 13 printed pages and 3 blank pages. DC (NF) 129956/4 © UCLES 2017 [Turn over Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level * 4 3 2 4 5 7 1 9 5 7 * COMPUTER SCIENCE 9608/22 Paper 2 Fundamental Problem-solving and Programming Skills May/June 2017 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/17 © UCLES 2017 1 (a) Simple algorithms usually consist of input, process and output. The statements in the following table are in a generic programming language. Complete the table by placing ticks in the relevant boxes. Item Statement Input Process Output 1 String1 = "Hello World" 2 DISPLAY RIGHT(String1, 5) 3 READFILE (MyFile, String2) 4 WRITEFILE (MyFile, "Data is " & String2) [6] (b) (i) Complete the following two sentences. A suitable operand type for an arithmetic operator is … A suitable operand type for a logical operator is … [2] (ii) The following table shows the values of three variables. Variable Value FlagA TRUE FlagB FALSE FlagC TRUE Evaluate these expressions. Expression Evaluates to (FlagA AND FlagB) OR FlagC FlagA AND (FlagB OR FlagC) (NOT FlagA) OR (NOT FlagC) [3]
Question paper, page 3
3 9608/22/M/J/17 © UCLES 2017 [Turn over (c) The loop construct (also known as repetition or iteration) appears in many algorithms. Use pseudocode to write a post-condition loop to output all the odd numbers between 100 and 200. … … … … … … … … … [4]
Question paper, page 4
4 9608/22/M/J/17 © UCLES 2017 2 A multi-user computer system maintains a text file containing the ID and preferred name for each user. User IDs are unique. Preferred names may be repeated. (a) Stepwise refinement is to be applied to the following three steps. After a user logs in, a welcome message is produced as follows: 1. Search for the user ID in the file. 2. Read the preferred name from the file. 3. Output the welcome message. Describe the goal of stepwise refinement. … … … … [2] (b) An initial identifier table is created as part of the stepwise refinement. A section of the table is shown. Complete this table. Identifier Data type Description SearchUserID Stores the user ID entered FileUserID … … FilePreferredName … … IDFoundFlag … … [5]
Question paper, page 5
5 9608/22/M/J/17 © UCLES 2017 [Turn over (c) The file may not contain an entry for every user. If the user ID is not found, then the name “Guest” should be used as the preferred name. Use structured English to write a more detailed algorithm for the welcome message process described in part (a). Use the identifiers given in the previous table. Assume that the file, UserNames.txt, is organised as a simple text file. The user ID and preferred name are held together in unencrypted form, one entry per line. … … … … … … … … … … … … … … … … [8]
Question paper, page 6
6 9608/22/M/J/17 © UCLES 2017 3 A string conversion function, ExCamel, needs to be written. This function forms a return string, OutString, from a given string, InString, by: 1 separating the original words (a word is assumed to start with a capital letter) 2 converting all characters to lower case. The following shows a pair of example values for the string values InString and OutString. InString : "MyUserInput" OutString : "my user input" You may assume that InString always starts with a capital letter. The following is a first attempt at writing the pseudocode for this function. Complete the pseudocode using appropriate built-in functions. For the built-in functions list, refer to the Appendix on page 13. FUNCTION ExCamel (…) RETURNS … DECLARE NextChar : … DECLARE … : STRING DECLARE n: INTEGER … // initialise the return string // loop through InString to produce OutString FOR n 1 TO … // from first to last NextChar … // get next character IF … // check if upper case THEN IF n > 1 // if not first character THEN … // add space to OutString ENDIF … // make NextChar lower case ENDIF … // add NextChar to OutString ENDFOR … // return value ENDFUNCTION [11]
Question paper, page 7
7 9608/22/M/J/17 © UCLES 2017 [Turn over 4 (a) High-level programming languages have many features that support the modular approach. One such feature is the use of parameters. State two other features. 1 … … 2 … … [2] (b) Consider the following pseudocode. PROCEDURE MyProc(x) x x + 1 ENDPROCEDURE Intermediate lines of pseudocode not shown x 4 CALL MyProc(x) OUTPUT(x) Parameter x is used to pass data to procedure MyProc. There are two parameter passing methods that could be used. Complete the following table for each of the two methods. Name of parameter passing method Value output Explanation … … … … … … … … … … … … [6]
Question paper, page 8
8 9608/22/M/J/17 © UCLES 2017 5 A multi-user computer system records user login data. Each time a user successfully logs into the system, it records the following data. Data item Example data User ID "Jim27" Port ID "3456" Time and date "08:30 Jun 01 2015" The data items are concatenated (joined) using a separator character to form a single string. Each string represents one log entry. (a) (i) Suggest a suitable separator character. Give the reason for your choice. Character … Reason … … [2] (ii) The concatenated strings are stored in an array, LogArray, which may contain up to 20 log entries. Use pseudocode to declare LogArray. … [2]
Question paper, page 9
9 9608/22/M/J/17 © UCLES 2017 [Turn over (b) A procedure, LogEvents, is required to add the log entry data from LogArray to the existing text file, LoginFile.txt. Unused array elements are assigned the value "****". These can occur anywhere in the array and should not be written to the file. Write program code for the procedure LogEvents. 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 10
10 9608/22/M/J/17 © UCLES 2017 6 A computerised vehicle licensing system stores details about vehicles and their registration marks (number plates or license plates). To be valid, a vehicle registration must comply with the following rules: • It must be between six and nine characters long. • Characters 1 to 3 are upper case alphabetic characters. • Characters 4 to 5 are numeric characters. • Remaining characters are upper case alphabetic. A function, ValidateRegistration is needed to check that a given registration mark follows these rules. This function takes a string, Registration as a parameter and returns a Boolean value: • TRUE if it is a valid registration • FALSE otherwise. (a) Write program code to implement the new function, ValidateRegistration. 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 11
11 9608/22/M/J/17 © UCLES 2017 [Turn over … … … … … … … … … … … … … … … … … … … … … [9]
Question paper, page 12
12 9608/22/M/J/17 © UCLES 2017 (b) The function is to be tested. Give a valid string that could be used to check that the function returns TRUE under the correct conditions. String1: … Modify your valid String1 to test each rule separately. Explain your choice in each case. String2: … Explanation: … … … String3: … Explanation: … … … String4: … Explanation: … … … String5: … Explanation: … … … [5]
Question paper, page 13
13 9608/22/M/J/17 © UCLES 2017 Appendix Built-in functions (pseudocode) In each function, if the function call is not properly formed, the function returns an error. RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING returns rightmost x characters from ThisString. Example: RIGHT("ABCDEFGH", 3) returns string "FGH" LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of string ThisString. Example: LENGTH("Happy Days") returns 10 MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING returns string of length y starting at position x from ThisString. Example: MID("ABCDEFGH", 2, 3) returns string "BCD" LCASE(ThisChar : CHAR) RETURNS CHAR returns the character value representing the lower case equivalent of ThisChar. If ThisChar is not an upper case alphabetic character then it is returned unchanged. Example: LCASE('W') returns 'w' UCASE(ThisChar : CHAR) RETURNS CHAR returns the character value representing the upper case equivalent of ThisChar. If ThisChar is not a lower case alphabetic character then it is returned unchanged. Example: UCASE('h') returns 'H' 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 DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER returns the integer value representing the whole number part of the result when ThisNum is divided by ThisDiv. Example: DIV(10,3) returns 3 Operators (pseudocode) Operator Description & Concatenates (joins) two strings Example: "Summer" & " " & "Pudding" produces "Summer Pudding" AND Performs a logical AND of two Boolean values Example: TRUE AND FALSE produces FALSE OR Performs a logical OR of two Boolean values Example: TRUE OR FALSE produces TRUE
Question paper, page 14
14 9608/22/M/J/17 © UCLES 2017 BLANK PAGE
Question paper, page 15
15 9608/22/M/J/17 © UCLES 2017 BLANK PAGE
Question paper, page 16
16 9608/22/M/J/17 © UCLES 2017 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 a registered trademark. This document consists of 8 printed pages. © UCLES 2017 [Turn over Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level COMPUTER SCIENCE 9608/22 Paper 2 Written Paper May/June 2017 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 May/June 2017 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 2017 © UCLES 2017 Page 2 of 8 Question Answer Marks 1(a) Item Statement Input Process Output 1 SomeChars = "Hello World" 9 2 OUTPUT RIGHT(String1,5) 9 9 3 READFILE (MyFile, String2) 9 4 WRITEFILE (MyFile, "Data is " & String2) 9 9 Mark as follows: Row 1 as shown Row 2 no marks if tick in Input column, otherwise 1 mark per tick Row 3 as shown Row 4 no marks if tick in Input column, otherwise 1 mark per tick 6 1(b)(i) • Integer / Real / Single / Double / Floating Point / Float • Boolean 2 1(b)(ii) Expression Evaluates to (FlagA AND FlagB) OR FlagC TRUE FlagA AND (FlagB OR FlagC) TRUE (NOT FlagA) OR (NOT FlagC) FALSE 1 mark per answer 3 1(c) MyCount ← 101 REPEAT OUTPUT MyCount MyCount ← MyCount + 2 UNTIL MyCount > 199 1 mark for each of the following: • Counter initialisation • Repeat « Until loop • Method for choosing (correct range of) odd numbers • Output all odd numbers in the range Note: Counter variable name must be consistent 4
Mark scheme, page 3
9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 3 of 8 Question Answer Marks 2(a) • to increase the level of detail of an algorithm / design... // breaking down a problem / module / task into smaller parts« • «from which the task may be programmed 1 mark per underlined phrase or equivalent 2 2(b) 1 mark for first 3 data types – String 1 mark for last data type – Boolean 1 mark for each description: FileUserID Stores (User) ID from file FilePreferredName Stores (preferred) name from file IDFoundFlag True if (User) ID found in file // False if (User) ID not found in file // If SearchUserID matches FileUserID 5 2(c) 1. LOOP through the file until EOF()« 2. OR SearchUserId is found 3. READ text line from UserNames.txt file in a loop 4. EXTRACT FileUserID in a loop 5. IF SearchUserId matches FileUserID THEN in a loop 6. SET FilePreferredName to the name from the file 7. Check if User ID found not in a loop 8. OUTPUT appropriate message for both conditions 1 mark per functional equivalent of each numbered statement. Max 8
Mark scheme, page 4
9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 4 of 8 Question Answer Marks 3 FUNCTION ExCamel (InString: STRING) RETURNS STRING DECLARE NextChar : CHAR DECLARE OutString : STRING DECLARE n : INTEGER OutString ← "" // initialise the return string // loop through InString to produce OutString FOR n ← 1 TO LENGTH(InString) // from first to last NextChar ← MID(InString, n, 1) // get next character IF NextChar >= 'A' AND NextChar <= 'Z' // check if upper case // NextChar = UCASE(NextChar) THEN IF n > 1 // if not first character THEN OutString ← OutString & " " // add space to OutString ENDIF NextChar ← LCASE(NextChar) // make NextChar lower case ENDIF OutString ← OutString & NextChar // add Nextchar to OutString ENDFOR RETURN OutString // return value ENDFUNCTION 1 mark per underlined word / expression Max 11
Mark scheme, page 5
9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 5 of 8 Question Answer Marks 4(a) • Functions • Procedures • Global / Local variables 1 mark per item Max 2 4(b) Name of parameter passing method Value output Explanation (Call) by reference 5 • The address of the variable is passed. • Original value is changed when parameter changed in called module. (Call) by value 4 • A copy of the variable itself is passed. • Original value not changed when parameter changed in called module. Mark as follows: • 1 mark for each name and value • 1 mark per bullet in explanation 6 Question Answer Marks 5(a)(i) • Any character except colon, space or any alpha-numeric • Reason: character is not in the login information strings 2 5(a)(ii) DECLARE LogArray : ARRAY[1 : 20] OF STRING 1 mark per underline 2
Mark scheme, page 6
9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 6 of 8 Question Answer Marks 5(b) Pseudocode solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. PROCEDURE LogEvents() DECLARE FileData : STRING DECLARE ArrayIndex : INTEGER OPENFILE "LoginFile.txt" FOR APPEND FOR ArrayIndex ← 1 TO 20 // IF LogArray[ArrayIndex]<> "****" THEN FileData ← LogArray[ArrayIndex] WRITEFILE ("LoginFile.txt", FileData) ENDIF ENDFOR CLOSEFILE("LoginFile.txt") ENDPROCEDURE 1 mark for each of the following: 1. Procedure heading and ending 2. Declare ArrayIndex as integer // commented in python 3. Open file 'LoginFile' for append 4. Correct loop 5. extract data from array in a loop 6. check for unused element in a loop 7. write data to file in a loop 8. Close the file outside the loop 8
Mark scheme, page 7
9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 7 of 8 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 ValidateRegistration(Registration : STRING) RETURNS BOOLEAN DECLARE UCaseChar, NumChar : INTEGER DECLARE NextChar : CHAR DECLARE ReturnFlag : BOOLEAN DECLARE n : INTEGER ReturnFlag ← TRUE ValidateRegistration ← True IF LEN(Registration) < 6 OR LEN(Registration) > 9 //check length THEN ReturnFlag ← False ELSE FOR n ← 1 TO 3 //check for 3 upper case alpha NextChar ← MID(Registration, n, 1) IF NextChar < 'A' AND NextChar > 'Z' THEN ReturnFlag ← False ENDIF ENDFOR FOR n ← 4 TO 5 //check for 2 numeric NextChar ← MID(Registration, n, 1) IF NextChar < '0' AND NextChar > '9 THEN ReturnFlag ← False ENDIF ENDFOR FOR n ← 6 TO LEN(Registration) //check remaining characters NextChar ← MID(Registration, n, 1) IF NextChar < 'A' AND NextChar > 'Z' THEN ReturnFlag ← False ENDIF ENDFOR ENDIF RETURN (ReturnFlag) ENDFUNCTION Max 9
Mark scheme, page 8
9608/22 Cambridge International AS/A Level – Mark Scheme PUBLISHED May/June 2017 © UCLES 2017 Page 8 of 8 Question Answer Marks 6(a) 1 mark for each of the following: 1. Correct Function heading and ending 2. Check for correct length 3. Extract first three characters 4. Check first three characters are capitals 5. Extract characters four and five 6. Check characters four and five are numeric 7. Extract remaining characters 8. Check remaining characters are capitals 9. Combine all four tests results into a single Boolean value 10. Return a Boolean value 6(b) String1: (for example, "ABC12XYZ") One mark for a valid string having: • Correct length (between 6 and 9 characters) • 3 capital letters followed by« • 2 numeric characters followed by« • between 1 and 4 capital letters String2 to String5: 1 mark for each string and explanation (testing different rules of the function) Test strings breaking one different rules: • Incorrect length • With incorrect number of capital letters at the start • With non-numeric characters in positions 4 and 5 • With incorrect number of capital letters at the end • Containing an invalid character (not alpha-numeric) 5
What you needed in this session
Cambridge’s own grade thresholds for 2017 May/June, Paper 2 · Variant 2. A higher threshold means an easier paper — the bar moves with how the cohort did.