ExamBank Scot · N5 Computing Science question bank · All N5 Computing Science questions
10 marks · Data types and structures
Describe the data structure that has been used to store the individual costs. Gillian writes and tests her program. It works perfectly calculating a correct total of 188.50. With reference to line numbers, explain how the program calculates the final total. Describe how the contents of the variable total would be stored in the computer’s memory. Gillian edits the program with the following data: [35.00, 36.00, 40.00, 35.00, 42.50, 45.00] The output is still 188.50. Explain why the output is still 188.50. State how this error could be corrected. Concatenation has been used in line 6. State the purpose of concatenation. Gillian designs a program to calculate how much it costs to get her dog Penny groomed. The design is shown below. Line 1 SET total = 0 Line 2 DECLARE all costs INITIALLY [35.00, 36.00, 40.00, 35.00, 42.50] Line 3 FOR EACH cost FROM all costs DUE Line 4 SET total=total+cost Line 5 END FOR EACH Line 6 SEND “The total cost = £“&total TO DISPLAY
Array – 1 mark Of Real - 1 mark Description includes reference to: • line 1 – total set to 0 • line 3 - loop • line 4 – each cost is added to previous total Mantissa – 1 mark Exponent – 1 mark 1 mark for ‘floating point representation’. A Accept any answer that would have explained the total being incorrect: • logic error • syntax error (DUE) • not recompiled code • program not saved before being re- run • program only calculates 5 costs • program has not been run • has not added on the 45.00 • line 3 has not been implemented correctly 1 mark for stating how error could be corrected. Additional - Error in question code There were errors in the code of this question and the Expected Answer(s) above are appropriate for the code as it was produced in the question paper. However, to help prepare for future examinations, the code should have read: Line 1 SET total = 0 Line 2 SET counter = 0 Line 3 DECLARE cost INITIALLY[35.00, 36.00, 40.00, 35.00, 42.50] Line 4 REPEAT Line 5 SET total = total + cost(counter) Line 6 SET counter = counter + 1 Line 7 UNTIL counter = 4 Line 8 SEND “The total cost = £”&total TO DISPLAY This would result in these Expected Answer(s): 19(b)(iii)(A) logic error counter only set to 4 program only calculates 5 costs 19(b)(iii)(B) candidate answer links to response to part (A): logic error – change the counter value counter only set to 4 – change to 5 allow for 6 values to be added With SQA reference language, indexing for both Array and String starts from zero. This is not the case in some other languages. Used to join text and variables together OR Output includes both text and variables together OR Used to join strings Also accept joining variables to other variables. Also accept an example of concatenation.