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

Higher Computing Science 2015 Question 17 (CfE)

14 marks · Data types and structures

Explain the purpose of line 2. State the output from line 4. Chris wants to calculate the average for the first pupil. Using pseudocode, or a language with which you are familiar, write the line to calculate this average. Chris calculates the average mark for each pupil and stores the average marks in an array. He writes the following pseudocode to count the number of grade A passes of 70 or more: Line 1 SET list TO [74.33, 57.67, 73.33, 82.33] Line 2 SET amount TO 0 Line 3 FOR counter FROM 0 TO 2 DO Line 4 IF list[counter] >= 70 THEN Line 5 SET amount TO amount + 1 Line 6 END IF Line 7 END FOR Line 8 SEND amount TO DISPLAY When Chris tests the program, it outputs the wrong number of A passes. State the output from the code above. State the name of this type of error. Identify and correct the line of the algorithm which contains the error. Chris creates an algorithm that will search the array of average marks and return the smallest value present. Line 1 SET list to [74.33, 57.67, 73.33, 87.33] Line 2 SET minimum TO list [0] Line 3 FOR counter FROM 1 TO 3 DO Line 4 IF minimum > list[counter] THEN Line 5 SET minimum TO list[counter] Line 6 END IF Line 7 END FOR A trace table is used to record the change to a variable at the corresponding line number. Part of the trace table is shown below. State the values missing from the trace table below at A, B and C. Line list minimum counter 1 74.33, 57.67, 73.33, 87.33 2 3 B 5 C 3 ......... ............. ........... A A B C Explain how breakpoints could be used in conjunction with a trace table to locate errors in code. Chris wants a program to process information about each of the pupils in his class. Line 1 RECORD Test_marks IS {STRING surname, INTEGER mark_1, INTEGER mark_2, INTEGER mark_3, STRING email} Line 2 SET pupil[1] TO (“Smith”, 67, 89, 91, “john@doodle.co.uk”) Line 3 SET pupil[2] TO (“Latif”, 42, 91, 84, “fatima@doodle.co.uk”) Line 4 SEND pupil[1].mark_2 TO DISPLAY

Marking scheme

• Assigns values to (element one of) an array • Assigns values to the Test_mark record 1 mark each, maximum of 2 marks Must reference both array and record for two marks. 89 SET average TO (pupil[1].mark_1+ pupil[1].mark_2+ pupil[1].mark_3)/3 1 mark for logical average with assignment. 1 mark for reference to the variable pupil at least once. Do not penalise BODMAS errors. 2 Logic error • Line 3 needs changed • FOR counter FROM 0 TO 3 DO Award 1 mark for line 3 attempt even if incorrect. Candidate does not need to state ‘line 3’. Allow: For counter FROM 1 TO 4 DO As this will still traverse four items of the array. This corrects the error of traversing three items instead of four. A – 74.33 B – 1 C – 57.67 • Stop/pause program at a defined point • to check the values of the variables (match the expected value)

Previous question: Higher Computing Science 2015 Question 16 (CfE)

Next question: Higher Computing Science 2016 Question 1 (CfE)