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




















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















Paper as text
Question paper, page 1
This document has 20 pages. Blank pages are indicated. DC (RW/TP) 180777/4 © UCLES 2020 [Turn over * 4 8 6 0 2 0 4 7 9 7 * COMPUTER SCIENCE 9608/22 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. Cambridge International AS & A Level
Question paper, page 2
2 9608/22/M/J/20 © UCLES 2020 BLANK PAGE
Question paper, page 3
3 9608/22/M/J/20 © UCLES 2020 [Turn over 1 (a) Selection and repetition are basic constructs of an algorithm. Name and describe one other construct. Name … Description … … … [3] (b) Program coding is a transferable skill. Explain the term transferable skill. … … … … [2] (c) Count-controlled and post-condition are two types of loop. Describe the characteristics of each of these types of loop. Count-controlled … … … Post-condition … … … [2] (d) Name three features provided by an Integrated Development Environment (IDE) that assist in the coding and initial error detection stages of the program development cycle. 1 … 2 … 3 … [3]
Question paper, page 4
4 9608/22/M/J/20 © UCLES 2020 2 (a) A structure chart is often produced as part of a modular program design. The chart shows the hierarchy of modules and the sequence of execution. Give two other features the structure chart can show. Feature 1 … … Feature 2 … … [2] (b) Six program modules implement part of an online shopping program. The following table gives the modules and a brief description of each module: Module Description Shop() Allows the user to choose a delivery slot, select items to be added to the basket and finally check out ChooseSlot() Allows the user to select a delivery time. Returns a delivery slot number FillBasket() Allows the user to select items and add them to the basket Checkout() Completes the order by allowing the user to pay for the items. Returns a Boolean value to indicate whether or not payment was successful Search() Allows the user to search for a specific item. Returns an item reference Add() Adds an item to the basket. Takes an item reference and a quantity as parameters (i) The online shopping program has been split into sub-tasks as part of the design process. Explain the advantages of decomposing the program into modules. Your explanation should refer to the scenario and modules described in part (b). … … … … … … [3]
Question paper, page 5
5 9608/22/M/J/20 © UCLES 2020 [Turn over (ii) Complete the structure chart for the six modules described in part (b). Shop() [6]
Question paper, page 6
6 9608/22/M/J/20 © UCLES 2020 3 A navigation program includes a function, CheckCourse(). This function is called with a real value, Course, and returns an integer value. The identifier table and the program flowchart for the function are shown as follows: Identifier Type Description Course REAL The value passed to CheckCourse() Adjust INTEGER The value returned by CheckCourse() Check INTEGER A local variable Deviate() FUNCTION A function that is passed a REAL value representing the course and returns a REAL value representing the current deviation Alert() PROCEDURE A procedure that generates a warning Set Check to integer value of Deviate(Course) START OTHERWISE –20 to –1 0 1 to 20 END Set Adjust to 255 Set Adjust to 10 Set Adjust to 0 Set Adjust to –10 RETURN Adjust Alert() CASE OF Check
Question paper, page 7
7 9608/22/M/J/20 © UCLES 2020 [Turn over Write pseudocode to implement the function CheckCourse(). The pseudocode must follow the algorithm represented by the flowchart. Declare any local variables used. Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators. … … … … … … … … … … … … … … … … … … … … … … … … … … [7]
Question paper, page 8
8 9608/22/M/J/20 © UCLES 2020 4 (a) Mustafa has developed the following pseudocode to generate ten random integers in the range 1 to 100. DECLARE Random : ARRAY [1:10] OF INTEGER DECLARE Count, RNum : INTEGER FOR Count 1 TO 10 Rnum INT(RAND(100)) + 1 Random[Count] RNum ENDFOR Refer to the Appendix on page 19 for a list of built-in pseudocode functions and operators. Rewrite the pseudocode so that there are no duplicated numbers in the list of random numbers. … … … … … … … … … … … … … … … … … … … … … … [6]
Question paper, page 9
9 9608/22/M/J/20 © UCLES 2020 [Turn over (b) The changes made to the pseudocode in part (a) were as a result of changes to the program requirement. Give the term used to describe changes made for this reason. … [1]
Question paper, page 10
10 9608/22/M/J/20 © UCLES 2020 5 A global 1D array, Contact, of type STRING is used to store a list of names and email addresses. There are 1000 elements in the array. Each element stores one data item. The format of each data item is as follows: <Name>':'<EmailAddress> Name and EmailAddress are both variable-length strings. For example: "Sharma Himal:hsharma99@stlmail.com" A function, GetName(), is part of the program that processes the array. A data item string will be passed to the function as a parameter. The function will return the Name part. Validation is not necessary. (a) Use structured English to describe the algorithm for the function GetName(). … … … … … … … … … … … … … … … … … [7]
Question paper, page 11
11 9608/22/M/J/20 © UCLES 2020 [Turn over (b) (i) The array is to be sorted using an efficient bubble sort algorithm. An efficient bubble sort reduces the number of unnecessary comparisons between elements. Describe how this could be achieved. … … … … … … … … [4]
Question paper, page 12
12 9608/22/M/J/20 © UCLES 2020 (ii) A procedure, BubbleSort(), is needed to sort the 1D array Contact into ascending order of Name using an efficient bubble sort algorithm. Write program code for the procedure BubbleSort(). Visual Basic and Pascal: You should include the declaration statements for variables. Python: You should show a comment statement for each variable used with its data type. Programming language … Program code … … … … … … … … … … … … … … … … … … … … … … … [8]
Question paper, page 13
13 9608/22/M/J/20 © UCLES 2020 [Turn over Question 6 begins on the next page.
Question paper, page 14
14 9608/22/M/J/20 © UCLES 2020 6 A company hires out rowing boats on a lake. The company has 17 boats numbered from 1 to 17. Boats may be hired between 9:00 and 18:00, with a maximum hire duration of 90 minutes. The company is developing a program to help manage and record the boat hire process. The programmer has decided to store all values relating to hire time as strings. The program will use a 24-hour clock format. For example: Time (in words) String value Nine o’clock in the morning "09:00" Five minutes past ten o’clock in the morning "10:05" Ten minutes before three o’clock in the afternoon "14:50" The programmer has defined the first module as follows: Module Description AddTime() • Takes two parameters: StartTime: a STRING value representing a time as described Duration: 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 (a) (i) Write pseudocode for the module AddTime(). Assume both input parameters are valid. Refer to the Appendix on page 19 for a built-in list of pseudocode functions and operators. … … … … … … … … … … … …
Question paper, page 15
15 9608/22/M/J/20 © UCLES 2020 [Turn over … … … … … … … … … … … … … … … [8] (ii) AddTime() will be tested using white-box testing. State the reason for using white-box testing. … … [1] (iii) A run-time error is one type of error that black-box testing can reveal. Describe one other type of error that black-box testing can reveal. … … [2]
Question paper, page 16
16 9608/22/M/J/20 © UCLES 2020 (b) The user will input the desired start time of a hire. A new module will be written to validate the input string as a valid time in 24-hour clock format. The string is already confirmed as being in the format "NN:NN", where N is a numeric character. Give an example of suitable test data that is in this format but which is invalid. Explain your answer. Test data … Explanation … … … … [2] (c) Each time a boat is hired out, details of the hire are added to a text file, Hirelog.txt. Each line of the text file corresponds to information about one hire session. The format of each line is as follows: <BoatNumber><Date><AmountPaid> • BoatNumber is a two-digit numeric string • Date is a six-digit numeric string in the format DDMMYY • AmountPaid is a variable-length string representing a numeric value, for example "12.75" The total hire amount from each boat is to be stored in a global array, Total. This array is declared in pseudocode as follows: DECLARE Total : ARRAY [1:17] OF REAL The programmer has defined module GetTotals() as follows: Module Description GetTotals() • Search through the file Hirelog.txt • Extract the AmountPaid each time a boat is hired • Store the total of AmountPaid for each boat in the array
Question paper, page 17
17 9608/22/M/J/20 © UCLES 2020 Write program code for the module GetTotals(). Visual Basic and Pascal: You should include the declaration statements for variables. Python: You should show a comment statement for each variable used with its data type. Programming language … Program code … … … … … … … … … … … … … … … … … … … … … [8]
Question paper, page 18
18 9608/22/M/J/20 © UCLES 2020 BLANK PAGE
Question paper, page 19
19 9608/22/M/J/20 © UCLES 2020 Appendix Built-in functions (pseudocode) Each function returns an error if the function call is not properly formed. 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 RAND(x : INTEGER) RETURNS REAL returns a real number in the range 0 to x (not inclusive of x) Example: RAND(87) could return 35.43 MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER returns the integer value representing the remainder when ThisNum is divided by ThisDiv Example: MOD(10,3) returns 1 DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER returns the integer value representing the whole number part of the result when ThisNum is divided by ThisDiv Example: DIV(10,3) returns 3 NUM_TO_STRING(x : REAL) RETURNS STRING returns a string representation of a numeric value. Example: If x has the value 87.5 then NUM_TO_STRING(x) returns "87.5" Note: This function will also work if x is of type INTEGER STRING_TO_NUM(x : STRING) RETURNS REAL returns a numeric representation of a string. Example: If x has the value "23.45" then STRING_TO_NUM(x) returns 23.45 Note: This function will also work if x is of type CHAR 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 20
20 9608/22/M/J/20 © UCLES 2020 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. BLANK PAGE
Mark scheme, page 1
This document consists of 15 printed pages. © UCLES 2020 [Turn over Cambridge International AS & A Level COMPUTER SCIENCE 9608/22 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/22 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/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 3 of 15 Question Answer Marks 1(a) One mark for name Max two marks for description: one for each underlined word or phrase (or equivalent) Name: Sequence Description: Instructions / lines of code are executed in a fixed order OR Name: Assignment Description: A value is given to a variable 3 1(b) One mark per bullet point: • Knowledge / experience of one programming language... • ... can be applied to an unknown language // will help recognise control structures (accept by example) in an unknown language 2 1(c) One mark per bullet point: • Count controlled – the number of iterations is known / fixed • Post condition – the number of iterations depends on some condition being tested at the end / before the loop is repeated // at least one iteration is always executed For conditional: reject answer that also applies to pre-conditional 2 1(d) Examples include: • context sensitive prompts • (dynamic) syntax checking • use of colours to highlight key words / pretty printing / highlighting unused variables (etc) • Formatting (incl. collapsing and expanding blocks) • (UML) modelling • Text editor (or by reference to a function such as copy & paste) • Built-in (library) functions Do not accept answers relating to debugging features Max 3 3
Mark scheme, page 4
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 4 of 15 Question Answer Marks 2(a) One mark per bullet point: • Parameters passed between modules // the interface between modules • Module Iteration • Module selection Max 2 2 2(b)(i) Advantages include: • Easier to solve / implement / program the solution as online shopping is a complex task • Easier to debug / maintain as each module can be tested separately e.g. test FillBasket() first then test Checkout() • Tasks may be shared among a team of programmer. e.g. Checkout() and Search() modules could be developed in parallel / by teams with different expertise Note: Must include reference to given scenario to achieve all 3 marks - Max 2 if no reference. 3
Mark scheme, page 5
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 5 of 15 Question Answer Marks 2(b)(ii) One Mark for 1 Three middle row boxes correctly labelled and connected to Shop() 2 Two bottom row boxes correctly labelled and connected to FillBasket() 3 Iteration arrow on FillBasket() 4 Return parameters from ChooseSlot() and Checkout() 5 Return parameters from Search() 6 Two input parameters to Add() Notes: Parameter types must be as shown but ignore parameter names (if given) 6
Mark scheme, page 6
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 6 of 15 Question Answer Marks 3 FUNCTION CheckCourse(Course : REAL) RETURNS INTEGER DECLARE Adjust, Check : INTEGER Check ← INT(Deviate(Course)) Adjust ← 255 CASE OF Check -20 to -1: Adjust ← 10 0 : Adjust ← 0 1 to 20 : Adjust ← -10 OTHERWISE CALL Alert() ENDCASE RETURN Adjust ENDFUNCTION 1 mark for each of the following: 1 FUNCTION heading and ending including parameter as given above 2 Assign value to Check using integer conversion and intialise Adjust to 255 3 CASE ... ENDCASE 4 Conditions −20 to −1 and 1 to 20 (and corresponding assignments) 5 Condition 0 (and corresponding assignment) 6 OTHERWISE 7 Return Adjust 7
Mark scheme, page 7
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 7 of 15 Question Answer Marks 4(a) DECLARE Random : ARRAY [1:10] OF INTEGER DECLARE NextNum, Index, Rnum : INTEGER DECLARE Exists : BOOLEAN NextNum ← 1 // index position for the next random number REPEAT Rnum ← INT(RAND(100)) + 1 // from original question Exists ← FALSE FOR Index ← 1 to NextNum - 1 // search for Rnum IF Random[Index] = Rnum THEN Exists ← TRUE ENDIF ENDFOR IF Exists = FALSE THEN Random[NextNum] ← Rnum // store Rnum NextNum ← NextNum + 1 // increment index ENDIF UNTIL NextNum > 10 1 mark for each of the following: 1 Conditional (outer) loop to generate 10 values 2 Inner loop to search array for duplicate number 3 Check for duplicate by comparing number generated with array element in a loop 4 Avoid checking uninitialised elements // array initialisation to rogue value at start of algorithm 5 If Rnum is a duplicate then repeat outer loop 6 If Rnum not a duplicate then assign to array element and Increment index Notes: Max 5 if statement to generate random number (as given in Q) not present or incorrectly placed. 6 4(b) Adaptive Maintenance 1
Mark scheme, page 8
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 8 of 15 Question Answer Marks 5(a) Mark as follows: 1 SET Name to "" 2 SET Index to 1 3 SELECT the character from input parameter string at Index position 4 IF character is not colon then concatenate character with Name 5 …INCREMENT Index 6 …REPEAT from step 3 7 RETURN Name Alternative Solution: Mark as follows: 1 SET Index to 1 2 SELECT the character from input parameter string at Index position 3 IF character is colon then go to 5 4 Else INCREMENT Index and repeat from 2 5 Extract a substring from the left of the parameter string (and assign this to variable Name) 6 ...Using Index -1 for the length 7 RETURN Name Note: Mark points may be combined for equivalent marks e.g a suitable structured English description of the pseudocode statement below satisfies MP 5, 6 and 7: RETURN LEFT(ParamString, Index – 1) 7 5(b)(i) Description: • Reduce the number of items to be checked by one after each pass • Use a flag variable to stop the outer loop • ... after no more swaps made on a single pass of the inner loop • ... resetting before the inner loop starts, and setting it whenever a swap is made 4
Mark scheme, page 9
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 9 of 15 Question Answer Marks 5(b)(ii) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. PROCEDURE BubbleSort() DECLARE Temp : STRING DECLARE NoSwaps : BOOLEAN DECLARE Boundary, J : INTEGER Boundary ← 999 REPEAT NoSwaps ← TRUE FOR J ← 1 TO Boundary IF Contact[J] > Contact[J+1] THEN Temp ← Contact[J] Contact[J] ← Contact[J+1] Contact[J+1] ← Temp NoSwaps ← FALSE ENDIF ENDFOR Boundary ← Boundary - 1 UNTIL NoSwaps = TRUE ENDPROCEDURE Mark as follows: 1 Procedure heading and ending 2 Outer loop 3 Inner loop 4 Correct comparison in a loop 5 Correct swap of array elements in a loop 6 'NoSwap' mechanism: Post-conditional outer loop including flag reset 7 'NoSwap' mechanism: Set flag in inner loop to indicate swap 8 Reducing Boundary in the outer loop 8
Mark scheme, page 10
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 10 of 15 Question Answer Marks 6(a)(i) FUNCTION AddTime(StartTime : STRING, Duration : INTEGER)_ RETURNS STRING DECLARE NewTime : STRING DECLARE StartMinutes, StartHours : INTEGER DECLARE Total, NewMinutes, NewHours : INTEGER StartHours ← STRING_TO_NUM(LEFT(StartTime,2)) StartMinutes ← STRING_TO_NUM(RIGHT(StartTime, 2)) Total ← (StartHours * 60) + StartMinutes + Duration NewHours ← DIV(Total, 60) NewMinutes ← MOD(Total, 60) NewTime ← "" IF NewHours < 10 THEN NewTime ← '0' // add leading zero to hours ENDIF NewTime ← NewTime & NUM_TO_STRING(NewHours) & ':' IF NewMinutes < 10 THEN NewTime ← NewTime & '0'// add leading zero ENDIF NewTime ← NewTime & NUM_TO_STRING(NewMinutes) RETURN NewTime ENDFUNCTION 1 mark for each of the following: 1 Function heading and ending including parameters 2 Extract StartHours and convert to integer 3 Extract StartMinutes and convert to integer 4 Add Duration to StartTime in minutes 5 Use DIV() to extract NewHours 6 Use MOD() to extract NewMinutes 7 Adding leading zeros when necessary to hours and minutes eg “09:05” 8 Return concatentated string Note: Accept alternative methods for calculation of NewHours and NewMinutes 8 6(a)(ii) To test every path through the algorithm 1 6(a)(iii) • Logical error • Algorithm is incorrect // program produces unexpected result / incorrect calculation is performed 2
Mark scheme, page 11
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 11 of 15 Question Answer Marks 6(b) Test data: Any string value where hours are > “24” or minutes > “59” Explanation: Suitable explanation Note: Accept times that would also be invalid for the given scenario. 2 6(c) 'Pseudocode' solution included here for development and clarification of mark scheme. Programming language example solutions appear in the Appendix. PROCEDURE GetTotals() DECLARE BoatNum : INTEGER DECLARE Paid : REAL DECLARE FileLine : STRING FOR BoatNum ← 1 TO 17 Total[BoatNum] ← 0 ENDFOR OPENFILE "Hirelog.txt" FOR READ WHILE NOT EOF("Hirelog.txt") READFILE "Hirelog.txt", FileLine BoatNum ← STRING_TO_NUM(LEFT(FileLine, 2)) Paid ← STRING_TO_NUM (RIGHT(FileLine,__ LENGTH(Fileline) – 8)) Total[BoatNum] ← Total[BoatNum] + Paid ENDWHILE CLOSEFILE "Hirelog.txt" ENDPROCEDURE One mark for each of the following: 1 Procedure heading and ending (where appropriate) with no parameters 2 Initialisation of elements in Total array 3 OPEN "Hirelog.txt" in read mode and CLOSE after use 4 Loop until EOF() 5 Read line from file in a loop 6 Extract and convert BoatNum 7 Extract and convert Paid 8 Update appropriate array total in a loop 8
Mark scheme, page 12
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 12 of 15 Program Code Example Solutions To be reviewed at STM Q5(b)(i): Visual Basic Sub BubbleSort() Dim Temp As String Dim NoSwaps As Boolean Dim Boundary, J As Integer Boundary = 999 Do NoSwaps = TRUE For J = 1 To Boundary If Contact(J) > Contact(J+1) Then Temp = Contact(J) Contact(J) = Contact(J+1) Contact(J+1) = Temp NoSwaps = FALSE End If Next Boundary = Boundary - 1 Loop Until NoSwaps = TRUE End Sub Q5(b)(i): Pascal procuedre BubbleSort() var Temp : String; NoSwaps : Boolean; Boundary, J : Integer; Boundary := 999 repeat begin NoSwaps := TRUE for J := 1 to Boundary do begin if Contact[J] > Contact[J+1]then begin Temp := Contact[J]; Contact[J] := Contact[J+1]; Contact[J+1] := Temp; NoSwaps := FALSE; end; end; Boundary := Boundary – 1 end; until NoSwaps = TRUE; End Sub
Mark scheme, page 13
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 13 of 15 Q5(b)(i): Python def BubbleSort() # Temp : String # NoSwaps : Boolean # Boundary, J : Integer Boundary = 999 NoSwaps = TRUE while NoSwaps == TRUE: NoSwaps = TRUE For J in range(Boundary + 1) If Contact[J] > Contact[J+1]: Temp = Contact[J] Contact[J] = Contact[J+1] Contact[J+1] = Temp NoSwaps = FALSE Boundary = Boundary - 1 End Sub Q6(c): Visual Basic Sub GetTotals() Dim BoatNum As Integer Dim Paid As Real Dim File As StreamReader("Hirelog.txt") For BoatNum = 1 To 17 Total(BoatNum) = 0 Next Do While File.Peek >= 0 FileLine = File.ReadLine() BoatNum = CInt(Left(FileLine, 2)) Paid = CSng(Right(FileLine, Len(Fileline) – 8)) Total(boatnumber) = Total(boatbnumber) + Paid Loop File.Close() End Sub
Mark scheme, page 14
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 14 of 15 Q6(c): Pascal procedure GetTotals() var BoatNum : Integer; Paid : Real; MyFile : testfile; for BoatNum := 1 to 17 do Total[BoatNum] := 0; assignFile(MyFile, "Hirelog.txt"); reset(MyFile); while not eof(MyFile) do begin readln(MyFile, FileLine); BoatNum = StrToInt(copy(FileLine, 1, 2)); Paid = StrToFloat(copy(FileLine, 9, length(Fileline) – 8)); Total(boatnumber) = Total(boatbnumber) + Paid; end; close(MyFile) end; Alternative FreePascal string functions) : BoatNum := LeftStr(FileLine, 2); Paid := StrToFloat(RightStr(FileLine, length(Fileline) – 8));
Mark scheme, page 15
9608/22 Cambridge International AS & A Level – Mark Scheme PUBLISHED May/June 2020 © UCLES 2020 Page 15 of 15 Q6(c): Python def GetTotals() # BoatNum : Integer # Paid : Real # File : File Handle # FileData : String For BoatNum in range (1, 18) Total[BoatNum] = 0 Next File = open("Hirelog.txt", "r") FileData = File.readline() while FileData != "": FileLine = File.ReadLine() BoatNum = int(FileLine[1, 3]) Paid = float(FileLine[8, len(Fileline) – 7)) Total[boatnumber] = Total[boatbnumber] + Paid FileData = File.readline() File.Close()