Question 4

OCR Computer Science June 2017 Paper 2AS15 marks

On the specification

(a)
1.4 Data types, data structures and algorithms
(b)(i)
1.4 Data types, data structures and algorithms
(b)(ii)
1.4 Data types, data structures and algorithms
(c)
1.4 Data types, data structures and algorithms2.2 Problem solving and programming
(d)
1.4 Data types, data structures and algorithms2.2 Problem solving and programming
Question text

4 A program stores a queue of mathematical questions to be asked to a user. The questions are asked in the order they are added. Once a question has been asked it cannot be asked again. New questions are continually added to the end of the queue. The program will use a non-circular queue, questions, (implemented using an array) to store the questions. The pointer, head, stores the index of the first element in the queue. The pointer, tail, stores the index of the last element in the queue. (a) Describe why a queue is a suitable structure for this program. [3] (b) Fig. 4.1 shows an example of the data in the queue. head is currently 0, tail is currently 4. "2*3" "1+4" "3-1" "10/2" "3+6" Fig. 4.1 (i) Show the contents of the queue shown in Fig. 4.1, after the following code is run. add("6+1") [2] (ii) State the values stored in head and tail after the code in part (i) has run. head tail [2] (c) Complete the following algorithm, to remove, and output, the first element in the queue. procedure remove() endprocedure [4] (d) Complete the following algorithm, to ask the user to input a new question and then either add it to the queue, or report that the queue is full. procedure add() maxElements = 10 endprocedure [4]