ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions

Higher Computing Science 2023 Question 9

14 marks · Constructs and reading code

During testing it is found that, due to an issue with Line 3, this code is not fit for purpose. Using the test data shown, state the output. Re-write Line 3 of the code to make this code fit for purpose. Formal and actual parameters are used in this code. Identify one formal parameter and its associated actual parameter. Formal parameter Actual parameter Describe the operation of Line 24 during the execution of this program. customerSearch(dogID, branch, noOfVisits) The program makes use of local variables. Identify a local variable in the code. Describe the scope of this local variable. Explain why using local variables increases the maintainability of program code. The area manager wants to know how many dogs have made more than five visits to a particular branch. Using a programming language of your choice, the arrays branch and noOfVisits, write the code to ask the user for the branch name and to display how many dogs have made more than five visits to this branch. A software developer is creating a program for a dog grooming company that has branches in Dundee, Edinburgh, Glasgow and Stirling. The following data is stored about each dog: • dog ID • name of the dog • branch the dog attends • number of visits to the branch. One feature of the program is to offer a discount to customers that have visited the Dundee or the Stirling branch more than four times. The data shown below is stored in four parallel 1D arrays to test this feature. dogID dogName branch noOfVisits G123 A872 D321 G876 A423 D872 Rover Roman Keeva Bailey Jack Ozzy Glasgow Stirling Dundee Edinburgh Stirling Dundee 7 2 6 6 5 2 The code below was created to display the dogID for those customers that are to be offered a discount. Line 1 PROCEDURE customerSearch (ARRAY OF STRING petNo, ARRAY OF STRING city, ARRAY OF INTEGER visits) Line 2 FOR i FROM 0 TO length(petNo)-1 DO Line 3 IF city[i]= "Stirling" OR (city[i]= "Dundee" AND visits[i] > 4) THEN Line 4 SEND petNo[i] TO DISPLAY Line 5 END IF Line 6 END FOR Line 7 END PROCEDURE … Line 20 DECLARE dogID INITIALLY ["G123", "A872","D321", "G876","A423","D872"] Line 21 DECLARE dogName INITIALLY ["Rover","Roman","Keeva", "Bailey","Jack","Ozzy"] Line 22 DECLARE branch INITIALLY ["Glasgow","Stirling", "Dundee","Edinburgh","Stirling","Dundee"] Line 23 DECLARE noOfVisits INITIALLY [7,2,6,6,5,2] Line 24 customerSearch(dogID, branch, noOfVisits)

Marking scheme

Award 2 marks for all three correct. Award 1 mark for any two correct OR three correct with a single column of additional output. A872 D321 A423 Evaluate towns then visits OR Evaluate towns and visits twice IF (city[i] = “Stirling” OR city[i] = “Dundee”) AND visits[i] > 4 THEN OR IF (city[i] = “Stirling” AND visits[i] > 4) OR (city[i] = “Dundee” AND visits[i] > 4) THEN Brackets not required for this expression. Award 2 marks for correct pair of parameters. Award 1 mark for any correct formal/actual parameter. Award 1 mark for correct pair of parameters wrong way round. Formal Actual petNo dogID city branch visits noOfVisits Award 1 mark for each bullet. • To call the procedure/subroutine • And pass the (actual) parameters into that procedure/subroutine i petNo city visits Award 1 mark for each bullet. Maximum 1 mark. • Only accessible in the (customerSearch) procedure • Accessible across lines 1 to 7 or 2 to 6 Award 1 mark for each bullet. Maximum 1 mark. • Editing one subroutine will not affect local variables with the same name in another subroutine • Relies on fewer global variables/ parameters so reduces likelihood of errors Award 1 mark for each bullet. • Initialise and increment counter • Use of fixed loop, branch input (and counter output) • IF condition matching user input to branch[] array • And condition noOfVisits[] > 5 Accept alternate array names DECLARE searchBranch INITIALLY FROM KEYBOARD DECLARE count INITIALLY 0 FOR index FROM 0 TO length(branch) If searchBranch = branch[index] and noOfVisits[index] > 5 THEN SET count TO count + 1 END IF SEND count TO DISPLAY

Previous question: Higher Computing Science 2023 Question 8

Next question: Higher Computing Science 2023 Question 10