Cambridge A Level Computer Science 9608 — 2020 May/June Paper 2 · Variant 1
9608/21/M/J/20
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 paper24 pages
























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















Paper as text
Question paper, page 1
Cambridge International AS & A Level * 0 6 3 8 5 6 1 5 3 5 * This document has 24 pages. Blank pages are indicated. DC (CE/CB) 180782/4 © UCLES 2020 [Turn over COMPUTER SCIENCE 9608/21 Paper 2 Fundamental Problem-solving and Programming Skills May/June 2020 2 hours You must answer on the question paper. No additional materials are needed. INSTRUCTIONS ● Answer all questions. ● Use a black or dark blue pen. ● Write your name, centre number and candidate number in the boxes at the top of the page. ● Write your answer to each question in the space provided. ● Do not use an erasable pen or correction fluid. ● Do not write on any bar codes. ● You may use an HB pencil for any diagrams, graphs or rough working. ● Calculators must not be used in this paper. INFORMATION ● The total mark for this paper is 75. ● The number of marks for each question or part question is shown in brackets [ ]. ● No marks will be awarded for using brand names of software packages or hardware.
Question paper, page 2
2 9608/21/M/J/20 © UCLES 2020 1 (a) Complete this definition of the term algorithm. An algorithm is a solution to a problem expressed as … … … [2] (b) A program design includes the use of subroutines (functions and procedures). Give three advantages of using subroutines in a program. 1 … … 2 … … 3 … … [3] (c) Draw lines on the following diagram to connect each computing term with the appropriate description. Term Description Selection Checking that a program performs as expected Black-box testing A method for increasing the level of detail of an algorithm Stepwise refinement To test a condition to determine the path of program execution Iteration A method of executing certain lines of code more than once [3]
Question paper, page 3
3 9608/21/M/J/20 © UCLES 2020 [Turn over 2 (a) Three modules form part of a program for a car rental company. A description of the relationship between the modules is summarised as follows: Module name Description RentCar() A customer will pay for each car rental either by bank card or by using their account with the rental company. PayByCard() Called with parameter HireCost, representing the cost of the rental. Returns a BOOLEAN value to indicate whether or not the card payment was successful. PayByAccount() Called with parameters HireCost, AccountNumber, CurrentBalance and AccountLimit. • Checks whether HireCost plus the CurrentBalance would exceed the AccountLimit. If so, then the rental is not authorised. • If the rental is authorised, then the CurrentBalance is updated. • Returns a BOOLEAN value to indicate whether or not the rental was authorised. Draw a structure chart to show the relationship between the three modules and the parameters passed between them. [5]
Question paper, page 4
4 9608/21/M/J/20 © UCLES 2020 (b) The following pseudocode algorithm has been developed to check whether a string contains a valid password. To be a valid password, a string must: • be longer than 6 characters • contain at least one lower case letter • contain at least one upper case letter • contain at least one non-alphabetic character. 10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN 11 12 DECLARE Index : INTEGER 13 DECLARE StrLen : INTEGER 14 DECLARE NumUpper, NumLower : INTEGER 15 DECLARE NumNonAlpha : INTEGER 16 DECLARE NextChar : CHAR 17 18 NumUpper 0 19 NumLower 0 20 NumNonAlpha 0 21 22 StrLen LENGTH(InString) 23 IF StrLen < 7 24 THEN 25 RETURN FALSE 26 ELSE 27 FOR Index 1 TO StrLen 28 NextChar MID(InString, Index, 1) 29 IF NextChar >= 'a' AND NextChar <= 'z' 30 THEN 31 NumLower NumLower + 1 32 ELSE 33 IF NextChar > 'A' AND NextChar <= 'Z' 34 THEN 35 NumUpper NumUpper + 1 36 ELSE 37 NumNonAlpha NumNonAlpha + 1 38 ENDIF 39 ENDIF 40 ENDFOR 41 ENDIF 42 43 IF (NumUpper >= 1) AND (NumLower >= 1) AND (NumNonAlpha >= 1) 44 THEN 45 RETURN TRUE 46 ELSE 47 RETURN FALSE 48 ENDIF 49 50 ENDFUNCTION Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
Question paper, page 5
5 9608/21/M/J/20 © UCLES 2020 [Turn over The pseudocode does not work under all circumstances. A dry run performed on the function Check(), with the string "crAsh99", produced the following trace table. The string is a valid password, but the pseudocode would return the value FALSE. Trace table row StrLen Index NextChar NumUpper NumLower NumNonAlpha 1 7 0 0 0 2 1 'c' 3 1 4 2 'r' 5 2 6 3 'A' 7 1 8 4 's' 9 3 10 5 'h' 11 4 12 6 '9' 13 2 14 7 '9' 15 3 (i) Describe how the completed trace table may be used to identify the error in the pseudocode. In your answer, refer to the trace table row number(s). … … … … … [2] (ii) State the pseudocode line number that has to be changed to correct the error and write the correct pseudocode for the complete line. Line number … Correct pseudocode … … [2]
Question paper, page 6
6 9608/21/M/J/20 © UCLES 2020 (iii) Rewrite lines 29 to 39 of the original pseudocode using a CASE structure. … … … … … … … [4]
Question paper, page 7
7 9608/21/M/J/20 © UCLES 2020 [Turn over Question 3 begins on the next page.
Question paper, page 8
8 9608/21/M/J/20 © UCLES 2020 3 (a) A mobile phone provider has developed an account management program. The program includes a procedure, AddCredit(). The procedure is called with two parameters, TopUp and PhoneNum. The relevant part of the identifier table and the program flowchart for the procedure are as shown: Identifier Type Description TopUp REAL The amount of credit to be added PhoneNum STRING The unique customer phone number Balance REAL The current amount of credit Multiple REAL The amount of credit bonus GetBalance() FUNCTION Takes the phone number as a parameter and returns the current balance SetBalance() PROCEDURE Takes the phone number and the new balance as parameters and updates the account with the new balance Set Multiple to 1 Set Balance to GetBalance(PhoneNum) Is Balance > 10 ? Is Balance > 5 ? Set TopUp to TopUp * Multiple SetBalance(PhoneNum, Balance + TopUp) Set Multiple to 1.25 Set Multiple to 1.1 START YES YES END NO NO
Question paper, page 9
9 9608/21/M/J/20 © UCLES 2020 [Turn over Write pseudocode to implement the procedure AddCredit(). The pseudocode must follow the algorithm represented by the flowchart. Declare any local variables used. … … … … … … … … … … … … … … … … … … … … … … … … [7]
Question paper, page 10
10 9608/21/M/J/20 © UCLES 2020 (b) The following pseudocode searches for a string "Chris" in a 1D array and outputs the index positions where the string is found. DECLARE NameList : ARRAY [1:100] OF STRING DECLARE n : INTEGER FOR n 1 TO 100 IF NameList[n] = "Chris" THEN OUTPUT "Found at: " & NUM_TO_STRING(n) ENDIF ENDFOR The pseudocode needs to be modified as follows: • Write the search as a procedure, Search(), that takes the search string as a parameter. • Change the array to a 2D array. The first dimension contains names and the second dimension contains the corresponding status. For example: NameList[23, 1] "Chris" // name NameList[23, 2] "On Holiday" // status • Detect a match only when the name contains the search string and the status contains "Active". • If a match has been detected, the procedure will output a single message giving all of the index positions where a match occurred. For example, "Found at: 3 6 22". • If no match has been detected, the procedure will output a suitable message. Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
Question paper, page 11
11 9608/21/M/J/20 © UCLES 2020 [Turn over Write the pseudocode for the procedure Search(). Assume the array has been declared globally. … … … … … … … … … … … … … … … … … … … … … … … … [8]
Question paper, page 12
12 9608/21/M/J/20 © UCLES 2020 4 (a) An inexperienced user buys a games program. A program fault occurs while the user is playing the game. Explain what is meant by a program fault. … … … … … … … [2] (b) Give three ways to minimise the risk of faults when writing programs. 1 … … 2 … … 3 … … [3] (c) Three types of program error are syntax, logic and run-time. Define these three types. Syntax error … … … Logic error … … … Run-time error … … … [3]
Question paper, page 13
13 9608/21/M/J/20 © UCLES 2020 [Turn over Question 5 begins on the next page.
Question paper, page 14
14 9608/21/M/J/20 © UCLES 2020 5 (a) A 1D array, Directory, of type STRING is used to store a list of school internal telephone numbers. There are 1000 elements in the array. Each element stores a single data item. The format of each data item is as follows: <Number><Name> Number is a four-digit numeric string. Name is a variable-length string. For example: "1024Collins Robbie" The following pseudocode is an initial attempt at defining a procedure SortContacts() that will perform a bubble sort on Directory. The array is to be sorted in ascending order of Name. Fill in the gaps to complete the pseudocode. Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators. PROCEDURE SortContacts () DECLARE Temp : STRING DECLARE FirstName, SecondName : STRING DECLARE NoSwaps : …………………………………… DECLARE Boundary, J : INTEGER Boundary …………………… REPEAT NoSwaps TRUE FOR J 1 TO Boundary FirstName …………………………(Directory[J], LENGTH(Directory[J]) – …………… ) SecondName RIGHT(Directory[J + 1], LENGTH(Directory[J + 1]) – 4) IF FirstName ……………………………… THEN Temp Directory[J] Directory[J] Directory …………………………… Directory[J + 1] Temp NoSwaps …………………………… ENDIF ENDFOR Boundary …………………………… UNTIL NoSwaps = TRUE ENDPROCEDURE [8]
Question paper, page 15
15 9608/21/M/J/20 © UCLES 2020 [Turn over (b) The pseudocode contains a mechanism designed to make this an efficient bubble sort. Describe the mechanism and explain why it may be considered to be efficient. … … … … … … … … … … [4]
Question paper, page 16
16 9608/21/M/J/20 © UCLES 2020 6 A company hires out rowing boats on a lake. The company has ten boats, numbered from 1 to 10. The company is developing a program to help manage and record the hiring out process. Hire information is stored in three global 1D arrays when a boat is hired out. Each array contains 10 elements representing each of the ten boats. The three 1D arrays are summarised as follows: Array Data type Description Example data value HireTime STRING The time the boat was hired out "10:15" Duration INTEGER The number of minutes of the hire 30 Cost REAL The cost of the hire 5.75 If an individual boat is not currently on hire, the corresponding element of the HireTime array will be set to "Available". The programmer has started to define program modules as follows: Module Description AddTime() • Called with two parameters: o a STRING value representing a time o an INTEGER value representing a duration in minutes • Adds the duration to the time to give a new time • Returns the new time as a STRING ListAvailable() • Called with a STRING value representing the time the hire will start • Outputs the boat numbers that will be available for hire at the given start time. A boat will be available for hire if it is either: o currently not on hire, or o due back before the given hire start time • Outputs the number of each boat available • Outputs the total number of boats available or a suitable message if there are none RecordHire() • Called with four parameters: o an INTEGER value representing the boat number o a STRING value representing the hire start time o an INTEGER value representing the hire duration in minutes o a REAL value representing the cost of hire • Updates the appropriate element in each array • Adds the cost of hire to the global variable DailyTakings • Converts the four input parameters to strings, concatenated using commas as separators, and writes the resulting string to the end of the existing text file HireLog.txt
Question paper, page 17
17 9608/21/M/J/20 © UCLES 2020 [Turn over (a) Write pseudocode for the module ListAvailable(). … … … … … … … … … … … … … … … … … … … … … … … … … … …
Question paper, page 18
18 9608/21/M/J/20 © UCLES 2020 … … … … … [8]
Question paper, page 19
19 9608/21/M/J/20 © UCLES 2020 [Turn over (b) Write program code for the module RecordHire(). 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 … … … … … … … … … … … … … … … … … … … … … … … … … [7]
Question paper, page 20
20 9608/21/M/J/20 © UCLES 2020 (c) The module description of AddTime()is repeated here for reference. Module Description AddTime() • Called with two parameters: o a STRING value representing a time o an INTEGER value representing a duration in minutes • Adds the duration to the time to give a new time • Returns the new time as a STRING (i) Write program code for a statement that uses the AddTime() function to add a duration of 60 minutes to a start time contained in variable BeginTime and to assign the new time to variable EndTime. Programming language … Program code … … [2] (ii) The function AddTime() is to be tested using black-box testing. Complete the following two tests that can be performed to check the operation of the function. Note that test 1 and test 2 are different. Test 1 – Boat is returned during the same hour as rental starts Start time value … Duration value … Expected new time value … Test 2 – Boat is returned during the hour after the rental starts Start time value … Duration value … Expected new time value … [2]
Question paper, page 21
21 9608/21/M/J/20 © UCLES 2020 Appendix Built-in functions (pseudocode) MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING returns a string of length y starting at position x from ThisString Example: MID("ABCDEFGH", 2, 3) returns "BCD" LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of ThisString Example: LENGTH("Happy Days") returns 10 LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING returns leftmost x characters from ThisString Example: LEFT("ABCDEFGH", 3) returns "ABC" RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING returns rightmost x characters from ThisString Example: RIGHT("ABCDEFGH", 3) returns "FGH" INT(x : REAL) RETURNS INTEGER returns the integer part of x Example: INT(27.5415) returns 27 NUM_TO_STRING(x : REAL) RETURNS STRING returns a string representation of a numeric value Note: This function will also work if x is of type INTEGER Example: NUM_TO_STRING(87.5) returns "87.5" Operators (pseudocode) Operator Description & Concatenates (joins) two strings Example: "Summer" & " " & "Pudding" produces "Summer Pudding" AND Performs a logical AND on two Boolean values Example: TRUE AND FALSE produces FALSE OR Performs a logical OR on two Boolean values Example: TRUE OR FALSE produces TRUE
Question paper, page 22
22 9608/21/M/J/20 © UCLES 2020 BLANK PAGE
Question paper, page 23
23 9608/21/M/J/20 © UCLES 2020 BLANK PAGE
Question paper, page 24
24 9608/21/M/J/20 © UCLES 2020 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 Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cambridgeinternational.org after the live examination series. Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.
Mark scheme, page 1
This document consists of 15 printed pages. © UCLES 2020 [Turn over Cambridge International AS & A Level COMPUTER SCIENCE 9608/21 Paper 2 Written Paper May/June 2020 MARK SCHEME Maximum Mark: 75 Published Students did not sit exam papers in the June 2020 series due to the Covid-19 global pandemic. This mark scheme is published to support teachers and students and should be read together with the question paper. It shows the requirements of the exam. The answer column of the mark scheme shows the proposed basis on which Examiners would award marks for this exam. Where appropriate, this column also provides the most likely acceptable alternative responses expected from students. Examiners usually review the mark scheme after they have seen student responses and update the mark scheme if appropriate. In the June series, Examiners were unable to consider the acceptability of alternative responses, as there were no student responses to consider. Mark schemes should usually be read together with the Principal Examiner Report for Teachers. However, because students did not sit exam papers, there is no Principal Examiner Report for Teachers for the June 2020 series. Cambridge International will not enter into discussions about these mark schemes. Cambridge International is publishing the mark schemes for the June 2020 series for most Cambridge IGCSE™ and Cambridge International A & AS Level components, and some Cambridge O Level components.
Mark scheme, page 2
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 2 of 15 Generic Marking Principles These general marking principles must be applied by all examiners when marking candidate answers. They should be applied alongside the specific content of the mark scheme or generic level descriptors for a question. Each question paper and mark scheme will also comply with these marking principles. GENERIC MARKING PRINCIPLE 1: Marks must be awarded in line with: • the specific content of the mark scheme or the generic level descriptors for the question • the specific skills defined in the mark scheme or in the generic level descriptors for the question • the standard of response required by a candidate as exemplified by the standardisation scripts. GENERIC MARKING PRINCIPLE 2: Marks awarded are always whole marks (not half marks, or other fractions). GENERIC MARKING PRINCIPLE 3: Marks must be awarded positively: • marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit is given for valid answers which go beyond the scope of the syllabus and mark scheme, referring to your Team Leader as appropriate • marks are awarded when candidates clearly demonstrate what they know and can do • marks are not deducted for errors • marks are not deducted for omissions • answers should only be judged on the quality of spelling, punctuation and grammar when these features are specifically assessed by the question as indicated by the mark scheme. The meaning, however, should be unambiguous. GENERIC MARKING PRINCIPLE 4: Rules must be applied consistently e.g. in situations where candidates have not followed instructions or in the application of generic level descriptors. GENERIC MARKING PRINCIPLE 5: Marks should be awarded using the full range of marks defined in the mark scheme for the question (however; the use of the full mark range may be limited according to the quality of the candidate responses seen). GENERIC MARKING PRINCIPLE 6: Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should not be awarded with grade thresholds or grade descriptors in mind.
Mark scheme, page 3
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 3 of 15 Question Answer Marks 1(a) An algorithm is a solution to a problem expressed as: a sequence of defined steps / stages / instructions / lines of code 1 mark for each underlined term (or equivalent) 2 1(b) • Allows the subroutine code to be called from many/multiple places • Subroutine code may be (independently) tested and debugged • If the subroutine task changes the change needs to be made only once • Reduces unnecessary duplication / program lines • Enables sharing of development between programmers Or equivalent points that relate to a PROGRAM (not an algorithm) Max 3 3 1(c) One mark for each correct line to max 3 3
Mark scheme, page 4
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 4 of 15 Question Answer Marks 2(a) Mark as follows: 1 One mark for all three boxes correctly labelled 2 One mark for selection diamond 3 One mark for passing value and return Boolean from PayByCard() 4 One mark for passing Value, AccountNUmber and AccountLimit to PayByAccount() 5 One mark for passing CurrentBalance ByRef 5 2(b)(i) Trace table shows: • 'A' is not treated as an upper case character (row 7) • NumUpper not incremented as expected • Incorrect final value for NumUpper (should be 1) Max 2 2 2(b)(ii) One mark per point: • Line number: 33 • Correction: IF NextChar >= 'A' AND NextChar <= 'Z' 2
Mark scheme, page 5
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 5 of 15 Question Answer Marks 2(b)(iii) CASE OF NextChar >= 'a' AND <= 'z' : NumLower ← NumLower + 1 > 'A' AND <= 'Z' : NumUpper ← NumUpper + 1 OTHERWISE NumNonAlpha ← NumNonAlpha + 1 ENDCASE One mark for CASE OF NextChar ... ENDCASE One mark for each remaining line Accept alternative range description. E.g. 'a' to 'z' Accept corrected version for the second range. 4
Mark scheme, page 6
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 6 of 15 Question Answer Marks 3(a) PROCEDURE AddCredit(TopUp : REAL, PhoneNum : STRING) DECLARE Multiple : REAL DECLARE Balance : REAL Multiple ← 1 Balance ← GetBalance(PhoneNum) IF Balance > 10 THEN Multiple ← 1.125 ELSE IF Balance > 5 THEN Multiple ← 1.1 ENDIF ENDIF TopUp ← TopUp * Multiple SetBalance(PhoneNum, Balance + TopUp) ENDPROCEDURE 1 mark for each of the following: 1 PROCEDURE heading and ending including parameters 2 Initialise Multiple 3 Assign value to Balance using GetBalance() 4 Check for Balance > 10 and assignment: Multiple ← 1.25 5 Check for Balance > 5 and assignment: Multiple ← 1.1 6 Assignment: TopUp ← TopUp * Multiple 7 Calling SetBalance()with correct parameters Note: MP6 could be included in MP7 statement 7
Mark scheme, page 7
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 7 of 15 Question Answer Marks 3(b) PROCEDURE Search(SearchString : STRING) DECLARE Index, Msg : STRING Msg ← "Found at:" //initial value FOR Index ← 1 TO 100 IF NameList[Index, 1] = SearchString__ AND NameList[Index, 2] = "Active" THEN Msg ← Msg & " " & NUM_TO_STRING(Index) ENDIF ENDFOR IF Msg = "Found at:" // no change to initial value THEN OUTPUT "Search String not found" ELSE OUTPUT Msg ENDIF ENDPROCEDURE 1 mark for each of the following: 1 PROCEDURE heading and ending including parameter 2 Declare local variables for Index and Msg and initialise Msg to appropriate string 3 Loop structure 4 Compare SearchString to name (column 1)... 5 ... AND Compare status to "Active" (column 2) in a loop 6 Add Index to Msg when a match is encountered (using type conversion) 7 Condition to determine which string is output after loop 8 Correct output of single message Note: Credit alternative solutions for forming and checking a single output string 8 Question Answer Marks 4(a) A program fault is something that makes the program not do what it is supposed to do under certain circumstances One mark per underlined phrase or equivalent 2
Mark scheme, page 8
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 8 of 15 Question Answer Marks 4(b) Answers include the use of: • Tried and tested (library) subroutines / code • Modular programming techniques (to break the problem down and make it easier to solve) • Good programming practice (formatting, sensible variable names, comments etc) • IDE features (parameter type-checking, auto-complete) Max 3 3 4(c) Syntax error: A construct / statement in the source code that breaks the rules of the language Logic Error: An error in the algorithm that causes the program not to behave as intended Run-time: A program performs an invalid operation / tries to divide by zero // enters an infinite loop / stops unexpectedly 3
Mark scheme, page 9
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 9 of 15 Question Answer Marks 5(a)(i) PROCEDURE SortContacts() DECLARE Temp : STRING DECLARE FirstName, SecondName : STRING DECLARE NoSwaps : BOOLEAN DECLARE Boundary, J : INTEGER Boundary ← 999 REPEAT NoSwaps ← TRUE FOR J ← 1 TO Boundary FirstName ← RIGHT(Directory[J],__ LENGTH(Directory[J]) – 4) SecondName ← RIGHT(Directory[J + 1],__ LENGTH(Directory[J + 1]) – 4) IF FirstName > SecondName THEN Temp ← Directory[J] Directory[J] ← Directory[J + 1] Directory[J + 1] ← Temp NoSwaps ← FALSE ENDIF ENDFOR Boundary ← Boundary - 1 UNTIL NoSwaps = TRUE ENDPROCEDURE One mark per highlighted phrase 8 5(b) Description: • uses a flag variable to stop the outer loop • after no more swaps made during one pass of the inner loop • the flag is reset before the inner loop starts, and set whenever a swap is made • decreases the loop size at end of inner loop (Boundary decremented) Max 3 for description Effective because: • It prevents unnecessary iterations / passes through the array (i.e. when the array is already sorted) // terminates the algorithm when all elements are in order // reduces the number of unnecessary comparisons 4
Mark scheme, page 10
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 10 of 15 Question Answer Marks 6(a) PROCEDURE ListAvailable(StartTime : STRING) DECLARE NumAvailable, Index : INTEGER DECLARE TimeBack : STRING DECLARE Available : BOOLEAN NumAvailable ← 0 FOR Index ← 1 TO 10 Available ← FALSE // initialise IF HireTime[Index] = "Available" // not on hire THEN Available ← TRUE // available now ELSE TimeBack ← AddTime(HireTime[Index],__ Duration[Index]) IF TimeBack < StartTime // < or <= THEN Available ← TRUE // will be available ENDIF ENDIF IF Available = TRUE THEN OUTPUT "Boat " , Index , " is available" NumAvailable ← NumAvailable + 1 ENDIF ENDFOR IF NumAvailable > 0 THEN OUTPUT "There are " , NumAvailable ,__ " boats available." ELSE OUTPUT "Sorry, there are no boats available" ENDIF ENDPROCEDURE 1 mark for each of the following: 1 Procedure heading and ending including input parameter 2 Declare local variable for the count of available boats and initialise to 0 3 Loop through all 10 boats 4 Use of AddTime() to calculate TimeBack 5 Check for boats that are not on hire OR those due back in time in a loop 6 Increment count for number of available boats in a loop 7 Output a message for each available boat in a loop 8 Output both messages as appropriate outside a loop 8
Mark scheme, page 11
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 11 of 15 Question Answer Marks 6(b) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. PROCEDURE RecordHire(HBoatNumber, HDuration : INTEGER,__ HTime : STRING, HCost : REAL) DECLARE FileLine : STRING CONSTANT Comma = ',' HireTime[HBoatNumber] ← HTime Duration[HBoatNumber] ← HDuration Cost[HBoatNumber] ← HCost DailyTakings ← DailyTakings + HCost OPENFILE "HireLog.txt" FOR APPEND FileLine ← NUM_TO_STRING(HBoatNumber) & Comma FileLine ← FileLine & HTime & Comma FileLine ← FileLine & NUM_TO_STRING(HDuration) FileLine ← FileLine & Comma & NUM_TO_STRING(HCost) WRITEFILE "HireLog.txt", FileLine CLOSEFILE "HireLog.txt" ENDFUNCTION One mark for each of the following: 1 Procedure heading and ending (where appropriate), including input parameters (order not essential) 2 Updating the three arrays from parameter values 3 Totalling DailyTakings 4 OPEN "HireLog.txt" in append mode 5 Creating file text line including separators 6 …making use of type conversion as required 7 Writing the line to the file 8 Closing the file Solutions may combine mark points 5 and 6 (and 7) Max 7 7
Mark scheme, page 12
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 12 of 15 Question Answer Marks 6(c)(i) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. EndTime ← Addtime (BeginTime, 60) One mark per underlined section (Space before bracket for mark scheme clarification only) 2 6(c)(ii) One mark for each test: For example: Test 1 Start time value "10:00", Duration value 30 Expected new time value "10:30" Test 2 Start time value "10:45", Duration value 30 Expected new time value "11:15" String values (time) must be enclosed in quotation marks, integer values (duration) must not. Penalise once then FT. 2
Mark scheme, page 13
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 13 of 15 Program Code Example Solutions To be reviewed at STM Q6(b)(i): Visual Basic Sub RecordHire(HBoatNumber, HDuration As Integer, HTime As String, HCost As Real) Dim FileLine As String Const Comma = ',' HireTime(HBoatNumber) = HTime Duration(HBoatNumber) = HDuration Cost(HBoatNumber) = HCost DailyTakings = DailyTakings + HCost FileOpen(1, "HireLog.txt", OpenMode.Append) FileLine = CStr(HBoatNumber) & Comma FileLine = FileLine & HTime & Comma FileLine = FileLine & CStr(HDuration) & Comma FileLine = FileLine & CStr(HCost) Print(1, FileLine) PrintLine(1) Fileclose(1) End Sub
Mark scheme, page 14
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 14 of 15 Q6(b)(i): Pascal procedure RecordHire(HBoatNumber, HDuration : integer; HTime : string; HCost : Real); var Fileline : string; ThisFile: TextFile; const Comma = ','; begin HireTime[HBoatNumber] := HTime; Duration[HBoatNumber] := HDuration; Cost[HBoatNumber] := HCost; DailyTakings := DailyTakings + HCost; AssignFile(Thisfile, "HireLog.txt"); FileLine := IntToStr(HBoatNumber) + Comma; FileLine := FileLine + HTime + Comma; FileLine := FileLine + IntToStr (HDuration) + Comma; FileLine := FileLine + IntToStr (HCost); writeln(ThisFile, FileLine); CloseFile(ThisFile); end; Q6(b)(i): Python def RecordHire(HBoatNumber, HDuration, HTime, HCost) # FileLine : String # File : File handle Comma = ',' HireTime[HBoatNumber] = HTime Duration[HBoatNumber] = HDuration Cost[HBoatNumber] = HCost DailyTakings = DailyTakings + HCost File = Open("HireLog.txt", "a") FileLine = Str(HBoatNumber) + Comma FileLine = FileLine + HTime + Comma FileLine = FileLine + Str(HDuration) + Comma FileLine = FileLine + Str(HCost) File.write(FileLine) File.close
Mark scheme, page 15
9608/21 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 15 of 15 Q6(c)(i): Visual Basic EndTime = Addtime(BeginTime, 60) Q6(c)(i): Pascal EndTime := Addtime(BeginTime, 60) Q6(c)(i): Python EndTime = Addtime(BeginTime, 60)