Question 15

AQA Computer Science June 2018 Paper 2A level5 marks

On the specification

15.1
4.12 Fundamentals of functional programming
15.2
4.12 Fundamentals of functional programming
15.3
4.12 Fundamentals of functional programming
Question text

15 In a functional programming language, four functions named fw, fx, fy and fz and box a list named sales are defined as shown in Figure 15. Figure 15 fw [a,b] = a * b fx c = map fw c fy d = fold (+) 0 d fz e = fy (fx e) sales = [[10,2], [2,25], [4,8]] The sales list represents all of the sales made in a shop in 1 day. It is composed of sublists. The values in each sublist indicate the price of a product and the quantity of the product that was sold. For example, [10,2] indicates that 10 units of a product priced at £2 were sold. 15.1 Shade one lozenge to indicate how many of the four functions (fw, fx, fy, fz) in Figure 15 use a higher-order function. [1 mark] 12 3 4 15.2 Calculate the results of making the function calls listed in Table 5, using the functions and lists in Figure 15 as appropriate. [3 marks] Table 5 Function call Result fw [4,3] fx sales fz sales 15.3 In the context of the shop, explain what the result of the function call fz sales box represents. [1 mark]