Cambridge A Level Computer Science 9608 — 2016 May/June Paper 2 · Variant 2
9608/22/M/J/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.
Question paper20 pages




















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














Paper as text
Question paper, page 1
This document consists of 18 printed pages and 2 blank pages. DC (NF/FD) 125122 © UCLES 2016 [Turn over Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level * 1 6 2 1 1 2 6 0 3 0 * COMPUTER SCIENCE 9608/22 Paper 2 Fundamental Problem-solving and Programming Skills May/June 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/M/J/16 © UCLES 2016 There is an Appendix on page 18. Some questions will refer you to this information. 1 The items in the table below are individual statements in a generic programming language. For the built-in functions list, refer to the Appendix on page 18. (a) (i) Show what type of programming construct each statement represents. Complete the table by putting a tick (✓) in the appropriate column for each item. Item Statement Selection Iteration Assignment 1 MyScore = 65 2 FOR IndexVal = 0 TO 99 3 MyArray[3] = MID(MyString,3,2) 4 IF MyScore >= 70 THEN 5 ENDWHILE 6 ELSE Message = "Error" [6]
Question paper, page 3
3 9608/22/M/J/16 © UCLES 2016 [Turn over (ii) State the purpose of each statement in the table in part (a)(i). Do not use mathematical symbols in your descriptions. Item Purpose of statement 1 … … 2 … … 3 … … 4 … … 5 … … 6 … … [6] (iii) Evaluate the following expressions when MyString has the value "Adaptive Maintenance". Expression Result 'D' & RIGHT(MyString, 4) LEFT(RIGHT(MyString, 7), 3) [2]
Question paper, page 4
4 9608/22/M/J/16 © UCLES 2016 2 A team is designing a software system to monitor temperature in a process. To do this, the system needs to sample the temperature repeatedly. If the temperature exceeds a given threshold value, an alarm will sound. The system is to be software-based. It will include a subroutine, SampleTemp, which samples the temperature and sets the alarm state to either ON or OFF. The initial design stage will produce a prototype of SampleTemp with a user interface. The structured English for this is: 1. IF the temperature does not exceed threshold value, SET alarm state to OFF 2. INPUT threshold value (to two decimal places) 3. INPUT sensor value (a whole number in the range 0 to 100) 4. MULTIPLY sensor value by conversion factor 1.135 to give temperature 5. IF temperature exceeds threshold value SET alarm state to ON 6. IF temperature exceeds threshold value OUTPUT message “Temperature Alarm” 7. IF temperature does not exceed threshold value OUTPUT message “Temperature OK” (a) The procedure needs four variables. Complete the identifier table below for these variables. Identifier Data type Description AlarmState … … SensorValue … … ThresholdValue … … Temperature … … [4]
Question paper, page 5
5 9608/22/M/J/16 © UCLES 2016 [Turn over (b) Write the pseudocode equivalent of the structured English. Use the identifiers from the table in part (a). … … … … … … … … … … … … … …[6]
Question paper, page 6
6 9608/22/M/J/16 © UCLES 2016 Question 3 begins on page 7.
Question paper, page 7
7 9608/22/M/J/16 © UCLES 2016 [Turn over 3 A string encryption function is needed. The encryption uses a simple character-substitution method. In this method, a new character substitutes for each character in the original string. This will create the encrypted string. The substitution uses the 7-bit ASCII value for each character. This value is used as an index for a 1D array, Lookup, which contains the substitute characters. Lookup contains an entry for each of the ASCII characters. It may be assumed that the original string and the substitute characters are all printable. For example: • ‘A’ has ASCII value 65 • Array element with index 65 contains the character ‘Y’ (the substitute character) • Therefore, ‘Y’ substitutes for ‘A’ • There is a different substitute character for every ASCII value The programmer writes a function, EncryptString, to return the encrypted string. This function will receive two parameters, the original, PlainText string and the 1D array. (a) The first attempt at writing the pseudocode for this function is shown below. Complete the pseudocode. For the built-in functions list, refer to the Appendix on page 18. FUNCTION EncryptString(…) RETURNS STRING DECLARE … , … : CHAR DECLARE OldCharValue : … DECLARE n : INTEGER DECLARE OutString : STRING … //initialise the return string //loop through PlainText to produce OutString FOR n 1 TO … //from first to last character OldChar …//get next character OldCharValue …//find the ASCII value NewChar …//look up substitute character …//concatenate to OutString ENDFOR … ENDFUNCTION [10]
Question paper, page 8
8 9608/22/M/J/16 © UCLES 2016 (b) Additional code needs to be written to allow the user to change some of the characters in the array Lookup. The user will input: • the array start position • the number of elements to change • each new substitute character At the end, the program will finally output a confirmation message. The first version of the algorithm is represented by the flowchart on the following page. (i) Write program code to declare the array Lookup. Programming language … … … …[2] (ii) Write program code to implement the flowchart design. In addition to the Lookup array, assume that the following variables have been declared: StartPos, NumToChange, n, NewChar Programming language … … … … … … … … … … … … …[6]
Question paper, page 9
9 9608/22/M/J/16 © UCLES 2016 [Turn over START Input StartPos Input Loop Output prompt for new substitute character n 0 NumToChange Input NewChar Assign element No Yes STOP Output message stating number of elements changed to current array NewChar Increment n n = NumToChange – 1?
Question paper, page 10
10 9608/22/M/J/16 © UCLES 2016 4 (a) Structured programming involves the breaking down of a problem into modules. Give two reasons why this is done. 1 … … 2 … … [2] (b) A team needs to write a program to implement an online shopping system. Customers will access the program via a website. Customers can search for items before adding them to a virtual shopping basket. When they have finished shopping, they pay for the items. The program provides output for the dispatch of the items. Some of the key features of the system are as follows: • a customer can add many items to the shopping basket • payment may be either by credit or debit card, or by adding to a customer account • the shop may dispatch the items in one or more packages The structure chart below shows the program modules only. (i) Draw on the chart, the symbols that represent the key features listed in part (b) above. Online shopping Checkout Select Item Dispatch Search Add to basket Card payment Account payment Print dispatch list Print address label [3]
Question paper, page 11
11 9608/22/M/J/16 © UCLES 2016 [Turn over (ii) A section of the chart in part (b)(i) is shown below. It is to show the parameters passed between the Checkout and Card payment modules. C A B Checkout Card payment Account payment Name the three data items corresponding to the arrows. Arrow Data item A B C [3]
Question paper, page 12
12 9608/22/M/J/16 © UCLES 2016 Question 5 begins on page 13.
Question paper, page 13
13 9608/22/M/J/16 © UCLES 2016 [Turn over 5 Toni has a large collection of jazz CDs that are stored in different places. She wants to record where the CDs are stored. She decides to write a program to do this. The program must store the data in a file, MyMusic. (a) (i) Why is a file needed? … …[1] (ii) MyMusic is a text file with the data for each CD as one line of text. Data for a typical CD are: Title: Kind of Green Artist: Miles Coltrane Location: Rack1-5 The line will be formed by concatenating the three data items. For the example above, the line stored will be: Kind of GreenMiles ColtraneRack1-5 Describe a problem that might occur when organising the data in this way. … … … … Describe a possible solution. … … … … [4]
Question paper, page 14
14 9608/22/M/J/16 © UCLES 2016 (b) Toni must input the data into the file for all of her CDs. A procedure, InputData, is needed to do this. Toni designs the procedure and chooses the following identifiers: Identifier Data type CDTitle STRING CDArtist STRING CDLocation STRING The procedure repeatedly performs the following steps: • input a CD title (A rogue value of “##” is to be used to end the input) • input the artist • input the location • create the text line • write the text line to the file When the rogue value is encountered the file is closed.
Question paper, page 15
15 9608/22/M/J/16 © UCLES 2016 [Turn over Write program code for the procedure InputData. 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. Programming language … … … … … … … … … … … … … … … … … …[8]
Question paper, page 16
16 9608/22/M/J/16 © UCLES 2016 6 A string-handling function has been developed. The pseudocode for this function is shown below. For the built-in functions list, refer to the Appendix on page 18. FUNCTION SSM(String1, String2 : STRING) RETURNS INTEGER DECLARE n, f, x, y : INTEGER n 0 f 0 REPEAT n n + 1 x n y 1 WHILE MID(String1, x, 1) = MID(String2, y, 1) IF y = LENGTH(String2) THEN f n ELSE x x + 1 y y + 1 ENDIF ENDWHILE UNTIL (n = LENGTH(String1)) OR (f <> 0) RETURN f ENDFUNCTION (a) Complete the trace table below by performing a dry run of the function when it is called as follows: SSM("RETRACE", "RAC") n f x y MID(String1, x, 1) MID(String2, y, 1) 0 0 [6]
Question paper, page 17
17 9608/22/M/J/16 © UCLES 2016 [Turn over (b) (i) Describe the purpose of function SSM. … … … …[2] (ii) One of the possible return values from function SSM has a special meaning. State the value and its meaning. Value … Meaning … [2] (iii) There is a problem with the logic of the pseudocode. This could generate a run-time error. Describe the problem. … … … …[2]
Question paper, page 18
18 9608/22/M/J/16 © UCLES 2016 Appendix Built-in functions In each function below, if the function call is not properly formed, the function returns an error. MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING returns the string of length y starting at position x from ThisString Example: MID("ABCDEFGH", 2, 3) will return string "BCD" LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING returns the leftmost x characters from ThisString Example: LEFT("ABCDEFGH", 3) will return string "ABC" RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING returns the rightmost x characters from ThisString Example: RIGHT("ABCDEFGH", 3) will return string "FGH" ASC(ThisChar : CHAR) RETURNS INTEGER returns the ASCII value of character ThisChar Example: ASC('W') will return 87 LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of string ThisString Example: LENGTH("Happy Days") will return 10 String operator & operator concatenates (joins) two strings Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Question paper, page 19
19 9608/22/M/J/16 © UCLES 2016 BLANK PAGE
Question paper, page 20
20 9608/22/M/J/16 © UCLES 2016 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. BLANK PAGE
Mark scheme, page 1
® IGCSE is the registered trademark of Cambridge International Examinations. This document consists of 14 printed pages. © UCLES 2016 [Turn over Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level COMPUTER SCIENCE 9608/22 Paper 2 Written Paper May/June 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 May/June 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 – May/June 2016 9608 22 © Cambridge International Examinations 2016 Question Answer Marks 1 (a) (i) Item Statement Selection Iteration Assignment 1 MyScore = 65 2 FOR IndexVal = 0 TO 99 3 MyArray[3] = ID(MyString,3,2) 4 IF MyScore >= 70 THEN 5 ENDWHILE 6 ELSE Message = "Error" One mark per row Additional ticks in any row cancels that row 6 (ii) Item Purpose of statement 1 Assign 65 to MyScore 2 (Start of) loop with loop counter starting from zero & going to 99 / repeating 100 times 3 Assign 2 chars from position 3/4 in MyString to MyArray element 3/4 4 Test if MyScore is greater than or equal to 70 5 Marks the end of WHILE / precondition loop //Return to top of loop to check condition 6 If a condition is FALSE, variable Message is assigned the value "ERROR" Exact wording not important Explanation must refer to variables or values used in code (except for row 5) 6 (iii) Expression Result "D" & RIGHT(MyString, 4) "Dance" LEFT(RIGHT(MyString, 7), 3) "ten" Must have correct case Quotation marks optional 2
Mark scheme, page 3
Page 3 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2016 9608 22 © Cambridge International Examinations 2016 Question Answer Marks 2 (a) Identifier Data Type Description AlarmState BOOLEAN Alarm is set to ON or OFF SensorValue INTEGER Value / number from sensor / as input by user // used in calculation of Temperature ThresholdValue REAL / FLOAT / SINGLE / DOUBLE Threshold value for comparison Temperature REAL / FLOAT / SINGLE / DOUBLE Temperature value calculated from sensor value One mark per row Data types as shown Descriptions given above are examples only 4
Mark scheme, page 4
Q Qu P ues (b Pag stio ) ge on 4 M 1. 2. 3. 4. 5. 6. 7. 4 ark 4 C k p Se pre Inp Co IF cla Co Co Se giv Cam poin ettin ese put orre F.. aus orre orre ettin ven mb A I I T I E nts ng ent ttin ect .TH ses ect ect ng n brid Ala NP NP em F ND as Al t) g S t va HEN s) t TH t EL Al dg rm UT UT mpe Te TH EL IF s ci lar Sen alue N. HEN LSE lar e I mSt T S ra mp HEN LSE ircl rmS ns e a .E N E s rmS nte © at hr en tu er N E led St or ass LS sta stat St ern Ca e es so re at Al OU OU Al d, d at rVa sign SE. ate tem at nat amb ← ho rV ← ur lar UTP UTP lar des e t al ned ..E me me e t M tio brid FA ld Val ← S e rmS PUT PUT rmS scri to F an d to END ent nt to F Mar na dge ALS Va ue Sen > Sta T " T " Sta pti FA nd o T DI ts a as FA k S l A e In SE lu nso Th ate "Te "Te ate on LS Th Tem F s as s sh LS Sch AS/ nter e orV re e ← emp emp e ← s a E ( hre mpe stru sho how E w hem /A rnat Val sh ← T per per ← as (Co esh er uct ow wn wit 1 me Le tion An lue ol TRU rat rat FA be ond hol at ture wn thin 2 e eve nal nsw e * dV UE tur tur ALS low d. c ld ur e w n E 2 el – Ex we * 1 al re re SE w: che Va re ( with LS – M xam r 1.1 ue Al OK eck al (m h co SE c 7 May mina 135 lar K" k n ust orr cla 7 y/Ju atio 5 rm" ot t b rec aus un ons " es e * ct c se o 3 6 e 2 s 20 se * n on on 201 016 ntia ot dit ly 16 6 al b x) ion if m 5 but n (o ma t m or t ark S mus two po Syl 9 st b o se oin llab 960 be c ep nt 1 bu 08 cor ara 1 n s rre ate ot P ct e IF Pa 2 if F pe 22 er M M Mar Max rks x 6 s
Mark scheme, page 5
Page 5 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2016 9608 22 © Cambridge International Examinations 2016 Question Answer Marks 3 (a) FUNCTION EncryptString (LookUp : ARRAY, PlainText : STRING) RETURNS STRING DECLARE OldChar, NewChar : CHAR DECLARE OldCharValue : INTEGER DECLARE OutString: STRING //first initialise the return string OutString ← "" //initialise the return string //loop through PlainText to produce OutString FOR n ← 1 to LENGTH(PlainText) //from first to last character OldChar ← MID(PlainText, n, 1) //get next character OldCharValue ← ASC(OldChar) //find the ASCII value NewChar ← Lookup[OldCharValue] //look up substitute character OutString ← Outstring & NewChar // concatenate to OutString ENDFOR RETURN OutString // EncryptString ← OutString ENDFUNCTION One mark for each part-statement (shown underlined and bold) 10 (b) (i) VB: Dim Lookup(0 to 127 / 128) As CHAR Pascal: Var Lookup: Array[0..127 / 1..128] Of CHAR Python: Lookup = ["" for i in range(128)] OR Lookup = [] For i in range(128) : Lookup.append("") Mark as follows: VB / Pascal: one mark per part-statement as underlined and bold Python: One mark for Lookup and [] One mark for range(128) 2
Mark scheme, page 6
Q 4 Qu P ues (a) Pag stio ( ) ge on ii) 6 'P sc Pr AL M 1. 2. 3. 4. 5. 6. • • • • Pse che rog LTE ark 2 2 C ud eme gra ER k p Tw Wo OU IN As OU Nu Pro Mo sp Pro En Cam oc e. mm RNA poin wo ork UTP NPU ssig UTP umT og odu ec og nco mb od min ATIV nts IN king PUT UT gnm PUT ToC ram ule iali ram oura brid e' s ng IN IN FO EN OU VE IN IN n RE UN OU as NPU g lo T p Ne me T fi Cha m c s m ists m c age dg sol lan NPU NPU OR O I L NDF UPU E: NPU NPU ← EPE O I L n NTI UTP s ci UT oop prom ewC ent na an cod ma s cod es e I luti ngu UT UT n OUT INP Loo FOR UT UT UT 0 EAT OUT INP Loo n ← IL PUT ircl sta p (u mp Cha of al m ge de y b de the nte © ion uag St Nu ← TPU PUT oku R (N St Nu T TPU PUT oku ← n n T ( led ate usi pt ( ar Ne mes or is e be is e e r ern Ca n in ge tar umT 0 UT T N up[ Num tar umT UT T N up[ n + = Nu d, d me ing exa ewC ssa r lo eas giv eas e-u nat amb clu so rtP ToC to " New St mTo rtP ToC " New St + 1 Nu umT des ent g va act Cha age oop sie ven sie usa M tio brid ude lut Pos Cha o N In wCh tar oCh Pos Cha In wCh tar 1 umT ToC scri ts alu t te ar e af p co er to n to er to abi Mar na dge ed ion s ang Num npu har rtP han s ang npu har rtP ToC Cha pti es ext to fte oun o im o d o te lity k S l A e In he ns a ge mTo ut r Pos nge ge ut r Pos Cha ang on of no co r lo nte mp iffe est y of Sch AS/ nter re app oCh ne s + e & ne s + ang ge s a f n ot s orre oop er if plem ere t / d f pr 4 4 hem /A rnat for pea han ew + n & " ew + n ge & as fro spe ect p (e f va me nt de rog me Le tion An r de ar nge va n] e va n] " be om ecif ar exa alu ent pe bu gra 1 1 e eve nal nsw eve in t e - alu ← ent alu ← en low flo fied rray act e c / m op g / m 1 el – Ex we elo the - 1 ue Ne tri ue Ne ntr w: owc d) y e t te cor ma ple m co – M xam r opm e A fo ewC ies fo ewC rie cha elem ext rrec na to ain de May mina men App or Cha c or Cha es art) me no ct a ge de nta y/Ju atio nt a pen po ar cha po ar ch ) ent ot s at t eve in un ons and ndix osi ang osi han pe tha lop 5 5 e 2 s 20 d c x. iti ged iti nge cifi at p p // 5 201 016 clar on d") on ed" ied poin giv 16 6 rific n " n " ) d bu nt) ven 6 cat ut n to 6 tion mu o p 3 3 S n o ust pro Syl 9 f m inc gra llab 960 mar clu am bu 08 rk ude m s e Pa 2 pe 22 er M M Mar 6 Max rks x 2 s
Mark scheme, page 7
Q 5 Qu P ues (b (a) Pag stio ) ( ) ge on (i) ii) (i) 7 O Ar Di A B C Da • • • ne rrow iam (or (or ata C m ws mon r B r A a ite So co So So Cam ark s m nd B) – A) – – em o th mp o th o th mb k p may sy – C – C – (F ms f hat put he d he d brid er y be ymb Card Cos Fla for the ter dat dat dg co e d bol d d st d ag) A e d is ta / ta e I orre draw m deta eta ind an dat sw / in info nte © ect wn may ails ails dic nd B a / witc nfor orm ern Ca an n cl y be s / s / a cato B a inf che rm ma nat amb nno oc e fi Ca am or f are for ed o ati tio M tio brid otat kw lled ard mou for e in rma off on n c Mar na dge tion wise d o nu unt su ter atio ca can k S l A e In n a e o or u um t pa ucc rch on an n b Sch AS/ nter as s r a unf mbe aya ces an is s be e " hem /A rnat sho anti fille er / able ssfu ge sav ac "pe me Le tion An ow iclo ed b Ca e / ul p eab ved cce erm e eve nal nsw wn ock but ard pr pay ble d a ess man el – Ex we kwi t m d in rod yme afte sed nen – M xam r se mus nfo duc ent er t d ne ntly May mina st b ct c t // he ext y st y/Ju atio be cost / pa pr t tim tore un ons in p t / t aym rog me ed" e 2 s 20 pos tot me gram e th " 201 016 siti al nt m i he p 16 6 ion bill co is r pro n sh l nfi run ogr how rm n / w am S wn ati wh m is Syl 9 on hen s ru llab 960 n th un bu 08 he s Pa 2 pe 22 er M M Mar 3 3 Max rks x 1 s
Mark scheme, page 8
Page 8 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2016 9608 22 © Cambridge International Examinations 2016 Question Answer Marks (ii) Problem: • When retrieving / searching for / editing (text relating to a particular CD) • Can’t tell where the artist name stops and the title begins (or any similar explanation or example) Solution 1: • Use of a separator character// or by example • Where the separator character does not occur in the original strings Solution 2: • Use a fixed number of characters for each data item • Data items are padded with e.g. <Space> character where needed Solution 3: • Convert original data items to CamelCase • …and add a Space separator Mark as follows: Two marks for description of problem Two marks for description of solution 4
Mark scheme, page 9
Page 9 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2016 9608 22 © Cambridge International Examinations 2016 Question Answer Marks (b) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language solutions appear in the Appendix. PROCEDURE InputData() DECLARE CDTitle : STRING DECLARE CDArtist : STRING DECLARE CDLocation : STRING DECLARE FileData : STRING OPENFILE "MyMusic" FOR WRITE OUTPUT "Input CD Title" INPUT CDTitle WHILE CDTitle <> "##" OUPUT "Input CD Artist" INPUT CDArtist OUPUT "Input CD Location" INPUT CDLocation FileData = CDTitle & ':' & CDArtist & ':' & CDLocation WRITEFILE "MyMusic.txt", FileData OUTPUT "Input CD Title" INPUT CDTitle ENDWHILE CLOSEFILE("MyMusic.txt ") ENDPROCEDURE One mark for each of the following: • Procedure heading and ending • Declaration of CDTitle, CDArtist and CDLocation • Open file for writing (Allow MyMusic or MyMusic.txt) • Working conditional loop structure including test for rogue value (including initial input of CDTitle) • Input of three data values (CDTitle, CDArtist and CDLocation) inside a loop • String concatenation of three variables inside a loop • Write three variables in single line to file inside a loop • Close file • Use of string separator Solutions may repeatedly OPEN – WRITE – CLOSE within the loop.In this case the first OPEN could be in WRITE or APPEND mode with all others in APPEND. Max 8
Mark scheme, page 10
Q 6 Qu P ues (a) (b ag stio ) ) ( (i ge 1 on (i) ii) ii) 10 O • • • • • • Fi Va M O • • O • • O • • n 0 1 2 3 4 ne rst alu ea pti pti pti C n 0 1 2 3 4 m Mi Co Le Ign to to t m ue: nin ion It i ma MI ion If e su ion If S An Cam ark nu olum ette nor se ret ark 0 / ng: n 1 s p atch ID n 2 eith bsc n 3 Str n en mb 4 k p s o mn ers re q arc turn k p / ze St pos h (f (S her crip ing ndl brid f 0 er one n 2 mu quo ch n th poin ero tr ssib for Str r st pt o g1 f les dg co e m – ust ota for he nt: o in ble ex ri trin out fou ss l e I orre mar '4' t al atio r a po all g2 e to xam ng g i t of und oo nte © x 1 2 2 3 4 5 6 ect rk if mu l b on s str osit ow no o “fa mpl g1, s e f ra d w p w ern Ca co f a ust e i sym ring tion w lo ot f all le, x em ang with will nat amb olum nyt t no n u mb g w n o oca fou off St x, pty ge hin oc M tio brid y 1 2 1 1 1 2 3 mn thi ot p upp bol with of th ate und f” th trin 1 y th err St ccu Mar na dge n ng pre per hin he / fi d in he g1 )// hen ror ring ur k S l A e In MI 'R 'E 'E 'T 'R 'A 'C els ece r ca an sta ind n S en = de n r // g 2 Sch AS/ nter ID R' E' E' T' R' A' C' se ede ase not art d / c tr nd o "R esc de 2 hem /A rnat (S on e '4 e he of cal in of Retr crip esc me Le tion An Str n fir 4' in r s St cu ng1 St rac ptio ript e eve nal nsw rin rst n co trin tri late 1 ri ce" on o tion el – Ex we ng1 row olu ng in e p ing , S of ' n – M xam r 1, w umn / S g2 pos g1 trin 'su May mina x n 1 Str w sitio (or ng2 bs y/Ju atio x, 1 (a rin ith on r by 2 = cri un ons 1) as s ng2 in S of y e = "R pt e 2 s 20 sho 2 w St exa Rac ou 201 016 M 'R 'A 'R 'R 'R 'A 'C ow with ri amp ced t o 16 6 MID R' A' R' R' R' A' C' wn b hin ing ple d") f ra D(S by St g1 e) w ang Str arr tri // b whi ge' S rin row in by le ' Syl 9 ng w) g1 exa str llab 960 2, am ring bu 08 y mple g s y, e P 1) Pa 2 ) pe 22 er Mar 6 2 2 2 rks
Mark scheme, page 11
Page 11 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2016 9608 22 © Cambridge International Examinations 2016 Appendix - Program Code Solutions 3 (b) (ii): VB.NET Console.Write("Enter start position: ") StartPos = Console.ReadLine() Console.Write("Enter number to change: ") NumToChange = Console.ReadLine() For n = 0 To NumToChange - 1 Console.Write("Enter new value for position: ") NewChar = Console.ReadLine() Lookup(StartPos + n) = NewChar Next Console.WriteLine(NumToChange & " entries changed") ALTERNATIVE: Console.Write("Enter start position: ") StartPos = Console.ReadLine() Console.Write("Enter number to change: ") NumToChange = Console.ReadLine() n = 0 Do Console.Write("Enter new value for position: ") NewChar = Console.ReadLine() Lookup(StartPos + n) = NewChar n = n + 1 Loop Until n = NumToChange Console.WriteLine(NumToChange & " entries changed") 3 (b) (ii): Pascal write('Enter start position: '); readln(StartPos); write('Enter number to change: '); readln(NumToChange); for n := 0 to NumToChange - 1 do begin write('Input new value for position: '); readln(NewChar); LookUp[Startpos + n] := NewChar; end; writeln(IntToStr(NumToChange) + ' entries changed');
Mark scheme, page 12
Page 12 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2016 9608 22 © Cambridge International Examinations 2016 ALTERNATIVE: write('Enter start position: '); readln(StartPos); write('Enter number to change: '); readln(NumToChange); n := 0; repeat write('Input new value for position: '); readln(NewChar); LookUp[Startpos + n] := NewChar; n := n + 1; until (n = NumToChange); writeln(IntToStr(NumToChange) + ' entries changed'); 3 (b) (ii): Python StartPos = int(input("Enter start position: ")) NumToChange = int(input("Enter number to change: ")) for n in range(NumToChange) : NewChar = input("Input new value for position: ") LookUp[StartPos + n - 1] = NewChar print(str(NumToChange) + " entries changed") ALTERNATIVE: StartPos = int(input("Enter start position: ")) NumToChange = int(input("Enter number to change: ")) n = 0 while n < NumToChange : NewChar = input("Input new value for position: ") LookUp[StartPos + n] = NewChar n = n + 1 print(str(NumToChange) + " entries changed")
Mark scheme, page 13
Page 13 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2016 9608 22 © Cambridge International Examinations 2016 5 (b): VB.NET A StreamWriter() solution: Sub InputData() Dim CDTitle, CDArtist, CDLocation As String Dim FileHandle As IO.StreamWriter FileHandle = New IO.StreamWriter("MyMusic.txt") ("MyMusic.txt") Console.WriteLine("Input CD Title: ") CDTitle = Console.ReadLine() Do Until CDTitle = "##" Console.WriteLine("Input CD Artist: ") CDArtist = Console.ReadLine() Console.WriteLine("Input CD Location: ") CDLocation = Console.ReadLine() FileHandle.WriteLine(CDTitle & ":" & CDArtist & ":" & CDLocation) Console.WriteLine("Input CD Title: ") CDTitle = Console.ReadLine() Loop FileHandle.Close() End Sub A legacy FileOpen() solution: Sub InputData() Dim CDTitle, CDArtist, CDLocation As String FileOpen(1, "MyMusic", OpenMode.Output) Console.WriteLine("Input CD Title: ") CDTitle = Console.ReadLine() Do Until CDTitle = "##" Console.WriteLine("Input CD Artist: ") CDArtist = Console.ReadLine() Console.WriteLine("Input CD Location: ") CDLocation = Console.ReadLine() Print(1, CDTitle & ":" & CDArtist & ":" & CDLocation) Console.WriteLine("Input CD Title: ") CDTitle = Console.ReadLine() Loop FileClose(1) End Sub
Mark scheme, page 14
Page 14 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2016 9608 22 © Cambridge International Examinations 2016 5 (b): Pascal procedure InputData; var CDTitle, CDArtist, CDLocation : string; CDFile : Textfile; begin assign(CDFile, 'MyMusic'); rewrite(CDFile); writeln('Input CD Title: '); readln(CDTitle); while (CDTitle <> '##') do begin writeln('Input CD Artist: '); readln(CDArtist); writeln('Input CD Location: '); readln(CDLocation); writeln(CDFile, CDTitle + ':' + CDArtist + ':' + CDLocation); writeln('Input CD Title: '); readln(CDTitle); end; close(CDFile); end; 5 (b): Python def InputData() : #CDTitle String (or CDTitle = "") #CDArtist String (or CDArtist = "") #CDLocation String (or CDLocation = "") FileHandle = open("MyMusic", "w") CDTitle = input("Input CD Title: ") while CDTitle != "##" : CDArtist = input("Input CD Artist: ") CDLocation = input("Input CD location: ") FileHandle.write(CDTitle + ":" + CDArtist + ":" + CDLocation) CDTitle = input("Input CD Title: ") FileHandle.close()
What you needed in this session
Cambridge’s own grade thresholds for 2016 May/June, Paper 2 · Variant 2. A higher threshold means an easier paper — the bar moves with how the cohort did.