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

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

Mark scheme13 pages

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

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

Paper as text

Question paper, page 1

This document consists of 19 printed pages and 1 blank page. DC (LK/JG) 95392/5 © UCLES 2015 [Turn over * 5 5 0 9 2 4 3 6 5 1 * COMPUTER SCIENCE 9608/21 Paper 2 Fundamental Problem-solving and Programming Skills May/June 2015 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. Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level

Question paper, page 2

2 9608/21/M/J/15 © UCLES 2015 Throughout the paper you will be asked to write either pseudocode or program code. Complete the statement to indicate which high-level programming language you will use. Programming language … 1 A marathon runner records their time for a race in hours, minutes and seconds. An algorithm is shown below in structured English. INPUT race time as hours, minutes and seconds CALCULATE race time in seconds STORE race time in seconds OUTPUT race time in seconds (a) The identifier table needs to show the variables required to write a program for this algorithm. Complete the table. Identifier Data type Description RaceHours INTEGER The hours part of the race time. [3] (b) Before the program is written, the design is amended. The new design includes input of the runner’s current personal best marathon time (in seconds). The output will now also show one of the following messages: • “Personal best time is unchanged” • “New personal best time” • “Equals personal best time” (i) Show the additional variable needed for the new design. Identifier Data type Description [1]

Question paper, page 3

3 9608/21/M/J/15 © UCLES 2015 [Turn over (ii) Write program code for the new design. 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 … … … … … … … … … … … … … … … … … … … … … … …[7]

Question paper, page 4

4 9608/21/M/J/15 © UCLES 2015 (c) The program code will be tested using white-box testing. (i) Explain what is meant by white-box testing. … … …[2] (ii) Complete the table heading. Complete Test Number 1. Add the data for Test Number 2 and Test Number 3. Input values Output Test number Race hours Race minutes Race seconds … Total time (seconds) Message 1 3 4 13 11053 11053 2 11053 3 11053 [6]

Question paper, page 5

5 9608/21/M/J/15 © UCLES 2015 [Turn over 2 A program displays a menu with choices 1 to 4. The code to display the menu is written as the procedure DisplayMenu. (a) Pseudocode which uses this procedure is: CALL DisplayMenu REPEAT OUTPUT "Enter choice (1..4)" INPUT Choice UNTIL Choice >= 1 AND Choice <= 4 (i) Describe what this pseudocode will do. … … … …[3] (ii) State why a loop is required. … …[1] (b) The following pseudocode is a revised design. CONSTANT i 3 CALL DisplayMenu NoOfAttempts 0 REPEAT OUTPUT "Enter choice (1..4)" INPUT Choice NoOfAttempts NoOfAttempts + 1 UNTIL (Choice >= 1 AND Choice <= 4) OR NoOfAttempts = i (i) Give the maximum number of inputs the user could be prompted to make. … [1] (ii) State why this algorithm is an improvement on the one given in part (a). … …[1]

Question paper, page 6

6 9608/21/M/J/15 © UCLES 2015 (c) The pseudocode is in its initial stage of development. The table below shows the action currently taken by the pseudocode following each menu choice. Menu choice Description Program response 1 Read data from the customer file Calls a procedure ReadFile which for testing purposes outputs the message “Read file code” 2 Add a customer Outputs message “Add customer code” 3 Search for a customer Outputs message “Search customer code” 4 Terminates the program Ends Complete the pseudocode for the design in part (b), shown again below, to respond to each menu choice. CONSTANT i 3 CALL DisplayMenu NoOfAttempts 0 REPEAT OUTPUT "Enter choice (1..4)" INPUT Choice NoOfAttempts NoOfAttempts + 1 UNTIL (Choice >= 1 AND Choice <= 4) OR NoOfAttempts = i … … … … … … …[3]

Question paper, page 7

7 9608/21/M/J/15 © UCLES 2015 [Turn over (d) The algorithm in part (c) is to be amended. The program will: • repeatedly display the menu and respond to the user’s choice • terminate when the user enters 4 Write program code for this final design which will be made up of: • the main program • procedure ReadFile • procedure DisplayMenu 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 … … … … … … … … … … … … … … … … … … … … … … …[8]

Question paper, page 8

8 9608/21/M/J/15 © UCLES 2015 3 When the guarantee on a computer runs out, the owner can take out insurance to cover breakdown and repairs. The price of the insurance is calculated from: • the model of the computer • the age of the computer • the current insurance rates Following an enquiry to the insurance company, the customer receives a quotation letter with the price of the insurance. A program is to be produced. The structure chart below shows the modular design for this process: … … … … … … … … … … … … … … access premium rates database Premium rates Premium rates

Question paper, page 9

9 9608/21/M/J/15 © UCLES 2015 [Turn over (a) Using the letters A to D, add the labelling to the chart boxes on the opposite page. Modules A Send quotation letter B Calculate price C Produce insurance quotation D Input computer details [2] (b) Using the letters E to J, complete the labelling on the chart opposite. Some of these letters will be used more than once. Data items E CustomerName F CustomerEmail G Model H Age I PolicyCharge J PolicyNumber [4]

Question paper, page 10

10 9608/21/M/J/15 © UCLES 2015 4 A game is played between two players: • they take turns at rolling a six-sided die (numbered 1 to 6) and record their throw • a player scores 1 point if their throw is higher than their opponent • they each roll the die 20 times • if the player’s throw is the same as their opponent, the total points is unchanged • the winner is the player with the larger number of points after 20 throws The pseudocode will use variable NoOfThrows as shown. Identifier Data type Description NoOfThrows INTEGER Loop control variable (i) Complete the pseudocode for the given algorithm. FOR … INPUT Player1Throw … IF Player1Throw > Player2Throw THEN … ENDIF IF Player2Throw > Player1Throw THEN Player2Total Player2Total + 1 ENDIF … IF Player1Total > Player2Total THEN OUTPUT "Player1 is the winner" ELSE OUTPUT "Player2 is the winner" ENDIF [5] (ii) Identify the game result which will produce incorrect output. … …[1]

Question paper, page 11

11 9608/21/M/J/15 © UCLES 2015 [Turn over Question 5 begins on page 12.

Question paper, page 12

12 9608/21/M/J/15 © UCLES 2015 5 A company creates two new websites, Site X and Site Y, for selling bicycles. Various programs are to be written to process the sales data. These programs will use data about daily sales made from Site X (using variable SalesX) and Site Y (using variable SalesY). Data for the first 28 days is shown below. SalesDate SalesX SalesY 1 03/06/2015 0 1 2 04/06/2015 1 2 3 05/06/2015 3 8 4 06/06/2015 0 0 5 07/06/2015 4 6 6 08/06/2015 4 4 7 09/06/2015 5 9 8 10/06/2015 11 9 9 11/06/2015 4 1 … 28 01/07/2015 14 8 (a) Name the data structure to be used in a program for SalesX. …[2]

Question paper, page 13

13 9608/21/M/J/15 © UCLES 2015 [Turn over (b) The programmer writes a program from the following pseudocode design. x 0 FOR DayNumber 1 TO 7 IF SalesX[DayNumber] + SalesY[DayNumber] >= 10 THEN x x + 1 OUTPUT SalesDate[DayNumber] ENDIF ENDFOR OUTPUT x (i) Trace the execution of this pseudocode by completing the trace table below. x DayNumber OUTPUT 0 [4] (ii) Describe, in detail, what this algorithm does. … … … …[3]

Question paper, page 14

14 9608/21/M/J/15 © UCLES 2015 (c) The company wants a program to output the total monthly sales for one of the selected websites. The programmer codes a function with the following function header: FUNCTION MonthlyWebSiteSales(ThisMonth : INTEGER, ThisSite : CHAR) RETURNS INTEGER The function returns the total number of bicycles sold for the given month and website. The function will use the following: Identifier Data type Description ThisMonth INTEGER Represents the month number e.g. 4 represents April ThisSite CHAR Coded as: • X for website X • Y for Website Y (i) Give the number of parameters of this function . …[1] (ii) Some of the following function calls may be invalid. Mark each call with: • a tick (✓), for a valid call • a cross (✗), for an invalid call For any function calls which are invalid, explain why. Function call Tick (✓) / cross (✗) Explanation (if invalid) MonthlyWebSiteSales(1, "Y") MonthlyWebSiteSales(11, 'X', 'Y') MonthlyWebSiteSales(12, 'X') [3]

Question paper, page 15

15 9608/21/M/J/15 © UCLES 2015 [Turn over (d) The company decides to offer a discount on selected dates. A program is written to indicate the dates on which a discount is offered. The program creates a text file, DISCOUNT_DATES (with data as shown), for a number of consecutive dates. 03/06/2015 TRUE 04/06/2015 FALSE 05/06/2015 FALSE 06/06/2015 FALSE 07/06/2015 FALSE 08/06/2015 FALSE 09/06/2015 FALSE 10/06/2015 TRUE 11/06/2015 FALSE 01/07/2015 FALSE Each date and discount indicator is separated by a single <Space> character. The discount indicators are: • FALSE – indicates a date on which no discount is offered • TRUE – indicates a date on which a discount is offered A programming language has the built-in function CONCAT defined as follows: CONCAT(String1 : STRING, String2 : STRING [, String3 : STRING] ) RETURNS STRING For example: CONCAT("San", "Francisco") returns "SanFrancisco" CONCAT("New", "York", "City") returns "NewYorkCity" The use of the square brackets indicates that the parameter is optional.

Question paper, page 16

16 9608/21/M/J/15 © UCLES 2015 The following incomplete pseudocode creates the text file DISCOUNT_DATES. Complete the pseudocode. OPENFILE "DISCOUNT_DATES" FOR … INPUT … WHILE NextDate <>"XXX" INPUT Discount …………..…………………… = CONCAT(NextDate, " ", Discount) WRITEFILE "DISCOUNT_DATES", NextLine INPUT NextDate … OUTPUT "File now created" CLOSEFILE [4]

Question paper, page 17

17 9608/21/M/J/15 © UCLES 2015 [Turn over Question 5(e) continues on page 18.

Question paper, page 18

18 9608/21/M/J/15 © UCLES 2015 (e) The DISCOUNT_DATES text file is successfully created. The company now wants a program to: • key in a date entered by the user • search the text file for this date • if found, output one of the following messages: o “No discount on this date” o “This is a discount date” • if not found, output “Date not found” (i) Add to the identifier table to show the variables you need for this new program. Identifier Data type Description DISCOUNT_DATES FILE Text file to be used [3]

Question paper, page 19

19 9608/21/M/J/15 © UCLES 2015 (ii) Write the program code. Do not include any declaration or comment statements for the variables used. Programming language … … … … … … … … … … … … … … … … … … … … … … … … …[7]

Question paper, page 20

20 9608/21/M/J/15 © UCLES 2015 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. CAMBRIDGE INTERNATIONAL EXAMINATIONS Cambridge International Advanced Subsidiary and Advanced Level MARK SCHEME for the May/June 2015 series 9608 COMPUTER SCIENCE 9608/21 Paper 2 (Written Paper), maximum raw mark 75 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 2015 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 2015 9608 21 © Cambridge International Examinations 2015 1 (a) Identifier Data Type Description RaceHours INTEGER The hours part of the race time RaceMinutes INTEGER the minute part of the race time RaceSeconds INTEGER // REAL the seconds part of the race time RaceTime INTEGER // REAL the race time in seconds 3 × (meaningful name + data type) [3] (b) (i) Identifier Data Type Description PersonalBestTime INTEGER/REAL Personal best time in seconds meaningful name + data type [1] (ii) Mark as follows: • Declarations/comments for variables – at least 2 • Input (+ prompts) for hours, minutes, seconds • Input (+ prompt) of personal best time • Correct calculation of RaceTimeInSeconds (don’t allow use of ‘x’ for ‘*’) • Output RaceTimeInSeconds • Correct logic and output message for < personal best • Correct logic and output message for > personal best • Correct logic and output message for = personal best [max 7] (c) (i) • Choosing data/values… • Test every possible ‘logic path’ through the code // with knowledge of the structure/code Ignore any reference to normal/boundary/extreme … [2] (ii) • PersonalBest column labelled • Test number 1 message: “Equals personal best time”/or similar • Test 2/Test 3 – data for better performance … • Described with suitable message • Test 2/Test 3 – data for worse performance … • Described with suitable message [6] 2 (a) (i) Displays the menu (choices) Repeats the prompt and input … …the input is a number between 1 and 4 // Checks number is between 1 and 4 "within range" is not enough [3] (ii) …the input number is validated [1]

Mark scheme, page 3

Page 3 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 (b) (i) 3 [1] (ii) Previous design repeated indefinitely // (new design) limits number of attempts Penalise "Program terminates/closes” [1] (c) IF Choice = 1 THEN (CALL) ReadFile (1) IF Choice = 2 THEN OUTPUT "Add Customer code" (1) IF Choice = 3 THEN OUTPUT "Search Customer code" (1) IF Choice = 4 THEN END (1) alternative answer: mark as follows: CASE OF Choice // Select CASE Choice 1 mark 1: (CALL) ReadFile 1 mark (allow CASE = 1) 2: OUTPUT "Add Customer code" 1 mark 3: OUTPUT "Search Customer code" 1 mark 4: END ENDCASE Output strings must match [max 3] (d) Mark as follows: • Choice / NoOfAttempts declared/commented as integer Must appear within the 'main' program Allow: different identifier names • Constant i assigned a value 3 • There is an ‘outer’ loop to repeatedly display the menu • Input ‘choice’ variable • Three IF statements (or equivalent) for processing menu choices 1, 2 and 3 Note: they must be correctly formed as ‘nested’ or ‘independent’ • Choice 1 calls procedure ReadFile • Choice 2 outputs “Add Customer Code” + Choice 3 outputs “Search Customer Code” • Outer loop terminates correctly with ‘Choice = 4’ //or equivalent • Procedure DisplayMenu shows the four menu options • Procedure ReadFile is present … and contains a single output message ‘Read file code’ [max 8]

Mark scheme, page 4

Page 4 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 3 (a) Control box – C // Produce insurance quotation [1] D // Input customer details + A // Send quotation letter is correct positions [1] (b) Data items E CustomerName F CustomerEmail G Model H Age I PolicyCharge J PolicyNumber [4] Any 2 correct Any 3 correct

Mark scheme, page 5

Page 5 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 4 (i) FOR NoOfThrows ← 1 TO 20 / 0 TO 19 1 1 (2) INPUT Player1Throw INPUT Player2Throw (1) IF Player1Throw > Player2Throw THEN Player1Total ← Player1Total + 1 (1) ENDIF IF Player2Throw > Player1Throw THEN Player2Total ← Player2Total + 1 ENDIF ENDFOR (1) IF Player1Total > Player2Total THEN OUTPUT "Player1 is the winner" ELSE OUTPUT "Player2 is the winner" END [5] (ii) Player scores equal // if Player1Total = Player2Total // there is no winner // a draw [1] 5 (a) • 1D Array // List [1] • INTEGER [1] (b) (i) x DayNumber OUTPUT 0 1 2 1 3 5/6/2015 4 2 5 7/6/2015 6 3 7 9/6/2015 3 Note: ‘x’ and ’output’ entries must be on or below the relevant ‘DayNumber’ entry Mark as above [4]

Mark scheme, page 6

Page 6 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 (ii) • … Sales for the first seven days (1) • … the number of days on which the total sales were 10 or over (1) • Outputs the corresponding dates (1) • Output the final value/total (of x) (1) [max 3] (c) (i) 2 [1] (ii) Tick Cross Explanation (if invalid) X //  2nd parameter should be CHAR // accept just tick X Three parameters/should be 2 parameters  [3] (d) OPENFILE "DISCOUNT_DATES" FOR WRITE / WRITING (1) INPUT NextDate (1) WHILE NextDate <> "XXX" INPUT Discount NextLine = CONCAT(NextDate, " ", Discount) (1) WRITEFILE "DISCOUNT_DATES", NextLine ENDWHILE (1) OUTPUT "File now created" CLOSEFILE [4] (e) (i) Sensible Identifier + Data Type + Description (1 + 1 + 1) For example: ThisDate STRING/DATE date ‘entered by user’ Found BOOLEAN flag to indicate ThisDate is ‘present in the file’ NextLine STRING a single line ‘from the text file’ NextDate STRING/DATE date ‘from next line in the file’ NextDiscount STRING the discount value from NextLine ThisMonth INTEGER the month part of the date (input or from file) MyStreamReader STREAMREADER references DISCOUNT_DATES file Reject ‘generic’ reserved words Allow one instance variable to store output string(s) Allow one instance of month/day/year number e.g. ThisMonth shown above [3]

Mark scheme, page 7

Page 7 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 (ii) Mark as follows: Open file statement (1) File read statement for line text – NextLine (1) File close statement (1) Input of the required date – ThisDate (1) Isolate NextDate from NextLine (1) Isolate NextDiscount from NextLine (1) IF statement comparing the two dates (1) Uses Boolean variable Found to flag when found (1) Post/pre condition loop iterate through the file (1) Test for EOF or ‘found’ (1) Note: These must follow some correct logic to score … Output ‘No discount on this date’ and Output ’This is a discount date’) (1) Output (when date not found) ‘Date not found’ (1) Accept ‘any’ identifier names [max 7]

Mark scheme, page 8

Page 8 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 APPENDIX Programming Solutions Question 1 (b) (ii) Visual Basic … Dim RaceHours As Integer Dim RaceMinutes As Integer Dim RaceSeconds As Integer Dim RaceTimeInSeconds As Integer Dim PersonalBest As Integer Console.Write("Time in hours ... ") : RaceHours = Console.ReadLine Console.Write("Time in minutes... ") : RaceMinutes = Console.ReadLine Console.Write("Time in seconds ... ") RaceSeconds = Console.ReadLine Console.Write("Personal best in seconds ... ") PersonalBest = Console.ReadLine RaceTimeInSeconds = RaceHours*60*60 + RaceMinutes*60 + RaceSeconds Console.Write(RaceTimeInSeconds) If RaceTimeInSeconds < PersonalBest Then Console.WriteLine("New personal best time") Else If RaceTimeInSeconds = PersonalBest Then Console.WriteLine("Equals personal best time") Else Console.WriteLine("Below personal best") End If End If Python … # RaceHours - Integer # RaceMinutes - Integer # RaceSeconds - Integer # RaceTimeInSeconds - Integer # PersonalBest - Integer RaceHours = int(input("Time in hours ... ")) RaceMinutes = int(input("Time in minutes... ")) RaceSeconds = int(input("Time in seconds ... ")) PersonalBest = int(input("Personal best in seconds ... ")) RaceTimeInSeconds = RaceHours*60*60 + RaceMinutes*60 + RaceSeconds if RaceTimeInSeconds < PersonalBest: print("New personal best time") elif RaceTimeInSeconds == PersonalBest: print("Equals personal best time") else: print("Below personal best")

Mark scheme, page 9

Page 9 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 Programming Solutions Question 1 (b) (ii) – contd. Pascal … var RaceHours : Integer ; var RaceMinutes : Integer ; var RaceSeconds : Integer ; var RaceTimeInSeconds : Integer ; var PersonalBestTime : Integer ; begin Writeln('Time in hours ... ') ; readln(RaceHours) ; Writeln('Time in minutes... ') ; readln(RaceMinutes) ; Writeln('Time in seconds ... ') ; readln(RaceSeconds) ; Writeln('Personal best in seconds ... ') ; Readln(PersonalBest) ; RaceTimeInSeconds := RaceHours*60*60 + RaceMinutes*60 + RaceSeconds ; Writeln(RaceTimeInSeconds) ; If RaceTimeInSeconds < PersonalBestTime Then WriteLn('New personal best time') Else If RaceTimeInSeconds = PersonalBest Then WriteLn('Equals personal best time') Else WriteLn('Personal best time is unchanged) ; Readln; End

Mark scheme, page 10

Page 10 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 Programming Solutions Question 2 (d) Visual Basic … Dim Choice As Integer Dim NoOfAttempts As Integer CONST i = 3 Do Call DisplayMenu() NoOfAttempts = 0 Do Console.Write("Enter choice (1..4)" Choice = Console.ReadLine NoOfAttempts = NoOfAttempts + 1 Loop Until (Choice >= 1 And Choice <= 4) Or NoOfAttempts = i If Choice = 1 Then Call ReadFile() If Choice = 2 Then Console.WriteLine("Add customer code") If Choice = 3 Then Console.WriteLine("Search customer code") Loop Until Choice = 4 Sub DisplayMenu() Console.WriteLine() Console.WriteLine("1. Read customer file") Console.WriteLine("2. Add customer") Console.WriteLine("3. Search for a customer") Console.WriteLine("4. End") Console.WriteLine() End Sub Sub ReadFile() Console.WriteLine("Read file code") End Sub Python … def DisplayMenu(): print() print("1. Read customer file") print("2. Add customer") print("3. Search for a customer") print("4. End") print() def ReadFile(): print("Read file code”) if __name__ ==”__main__” : # Choice - Integer # NoOfAttempts - Integer Choice = 0 while Choice !=4: DisplayMenu()

Mark scheme, page 11

Page 11 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 Choice = int(input”Enter choice (1..4) :”) NoOfAttempts = 1 while (Choice < 1 or Choice >4) and NoOfAttempts < 3: Choice = int(input”Enter choice (1..4) :”) NoOfAttempts = 1 if Choice == 1: ReadFile() elif Choice == 2: print("Add customer code") elif Choice == 3: print("Print customer code") Programming Solutions Question 2 (d) – contd. Pascal … var Choice : Integer ; var NoOfAttempts : Integer ; const i = 3 ; procedure DisplayMenu ; begin WriteLn(); WriteLn('1. Read customer file') ; WriteLn('2. Add customer') ; WriteLn('3. Search for a customer'); WriteLn('4. End') ; WriteLn() ; End ; Procedure ReadFile ; begin WriteLn('Read file code'); End ; begin repeat DisplayMenu() ; NoOfAttempts := 0 ; repeat Writeln('Enter choice (1..4)') ; ReadLn(Choice) ; NoOfAttempts := NoOfAttempts + 1 ; Until ((Choice >= 1) And (Choice <= 4)) Or (NoOfAttempts = i); If Choice = 1 Then ReadFile() ; If Choice = 2 Then writeLn('Add customer code'); If Choice = 3 Then WriteLn('Search customer code') ; Until Choice = 4 ; end.

Mark scheme, page 12

Page 12 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 Programming Solutions Question 5 (ii) Visual Basic … Dim ThisDate As String : Dim NextDate As String Dim FileString As String Dim Found As Boolean FileOpen(1, "D:DISCOUNT_DATES.txt", OpenMode.Input) or equivalent for a ‘StreamReader’ solutions Console.Write("Date to find (DD/MM/YYYY)..") ThisDate = Console.ReadLine Found = False Do FileString = LineInput(1) NextDate = Left(FileString, 10) If NextDate = ThisDate Then Found = True ' length is 15 when shows TRUE If Len(FileString) = 15 Then Console.WriteLine("This is a discount date") Else Console.WriteLine("No discount on this date") End If End If Loop Until Found = True Or EOF(1) FileClose(1) If Found = False Then Console.WriteLine("Date not found") End If Python … MyFile = open("c:\DISCOUNT_DATES.txt", "r") ThisDate = input("Next date ...(XXX to end)") Found = 0 while Found == 0: NextLine = MyFile.readline() if not NextLine: break FileDate = NextLine[0:10] DiscountIndicator = NextLine[11:] if FileDate == ThisDate: Found = 1 print (ThisDate, DiscountIndicator) MyFile.close() if Found == 0:

Mark scheme, page 13

Page 13 Mark Scheme Syllabus Paper Cambridge International AS/A Level – May/June 2015 9608 21 © Cambridge International Examinations 2015 print ("This date was not found") Note: Found could be Boolean to give: Found = False while not Found: Programming Solutions Question 5 (ii) – contd. Pascal … var ThisDate : String ; var NextDate : String ; var TheFile : Text ; var FileString : String ; var Found : Boolean ; begin assign(TheFile, 'k:\DISCOUNT_DATES.txt') ; reset(TheFile) ; writeln('Date to find (DD/MM/YYYY)..') ; readln(ThisDate) ; Found := False ; repeat readln(TheFile, FileString) ; NextDate := copy(FileString,1, 10) ; If NextDate = ThisDate then begin Found := True ; { length is 15 when shows TRUE } if length(FileString) = 15 then writeLn('This is a discount date') else writeLn('No discount on this date') end ; until Found = True or EOF(TheFile) ; close(TheFile) ; if Found = False then writeLn('Date not found') ;

What you needed in this session

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

A52/75
B45/75
C38/75
D31/75
E24/75