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

Higher Computing Science 2021 Question 9

14 marks · Software analysis

During analysis the inputs, processes and outputs were identified. Describe two processes. Details for registered restaurants are stored in four parallel 1‑D arrays. • restaurantName • foodType • city • rating Using a recognised design technique, design an algorithm that would count the number of restaurants that match the user’s food type and city. The following function is to be used to find the highest rating for a restaurant. During testing it is found that this code contains an error. … Line 26 FUNCTION findMax (ARRAY OF REAL list) RETURNS REAL Line 27 DECLARE upper INITIALLY length(list) -1 Line 28 DECLARE highest INITIALLY list[0] Line 29 FOR index FROM 1 TO upper DO Line 30 IF highest > list[index] THEN Line 31 SET highest TO list[index] Line 32 END IF Line 33 END FOR Line 34 RETURN highest Line 35 END FUNCTION … A trace table is used when the function is tested with the following values [4.51, 4.12, 4.99]. Line Number index list [index] highest highest > list [index] … 28 4.51 29 1 30 4.12 4.51 true 31 A 29 2 30 B 4.12 C 34 4.12 Identify the missing values A, B and C. A B C Describe how a breakpoint could be used to check the values in the trace table. Describe how the error in this code can be corrected. The function findMax in part (c) is used to assign the highest rating from the array rating to the variable myHighest. Using a programming language of your choice, write the line of code that assigns the highest rating to myHighest. JustDine is developing a smartphone app to allow a user to identify restaurants based on the type of food. Restaurants register with JustDine. The app will store the name, city, type of food and rating for each restaurant. Features of the app: • Users can enter the type of food and city • Displays the number of matching restaurants • Displays the name and rating of the highest rated matching restaurant. The user interface for the app is shown below. JustDine Type of Food Vegan City Aberdeen Submit There are 3 vegan restaurants in Aberdeen The highest rated vegan restaurant in Aberdeen is Leaves & Green with a rating of 4.51 out of 5

Marking scheme

• count number of matching restaurants • find highest rated restaurant 1 mark for each bullet • initialising total and incrementing total by 1 • loop that traverses array with termination IF statement with • condition for food type AND • condition for city 1 mark for each bullet Pseudocode example: (Get targetFood from user Get targetCity from user) Set count to 0 Start loop for each restaurant If restaurantType[index] = targetFood AND city[index] = targetCity Set count to count +1 End if End loop • A=4.12 • B=4.99 • C=false 1 mark for each bullet • a breakpoint will halt execution of the code at a predefined point (various line numbers are suitable) • then the values of variable can be inspected to compare with trace table values/expected values 1 mark for each bullet Award second mark if candidates refer to stepping through the code to compare with trace table values as this is another expression of second bullet point. Change > to < OR swap highest and list[index] • function called correctly with parameter • assigning result to myHighest 1 mark for each bullet SET myHighest TO findMax(rating)

Previous question: Higher Computing Science 2021 Question 8

Next question: Higher Computing Science 2021 Question 10