Question 5

OCR Computer Science November 2020 Paper 2A level32 marks

On the specification

(a)
1.4 Data types, data structures and algorithms
(b)
1.4 Data types, data structures and algorithms2.3 Algorithms
(c)(i)
2.2 Problem solving and programming2.3 Algorithms
(c)(ii)
2.2 Problem solving and programming2.3 Algorithms
(c)(iii)
2.2 Problem solving and programming
(d)
1.4 Data types, data structures and algorithms2.3 Algorithms
(e)
1.4 Data types, data structures and algorithms2.3 Algorithms
Question text

5 A printer buffer is a storage area that holds the data, known as jobs, that are to be printed by a printer. A simulation of the printer buffer uses a queue data structure to store jobs that are waiting to be printed. The queue is not circular. The printer buffer is represented as a zero-indexed 1D array with the identifier buffer. Fig. 2 shows the current contents of the queue buffer and its pointers. 6 0 queueHead 5 34 queueTail 3 job-127 2 job-126 1 job-125 0 job-124 Fig. 2 (a) State the purpose of the pointers queueHead and queueTail. queueHead queueTail [2] (b) The function dequeue outputs and removes the next data item in the queue. The procedure enqueue adds the job passed as a parameter to the queue. Show the final contents of the queue and pointer values after the following instructions have been run on the queue buffer shown in Fig. 2. dequeue() dequeue() enqueue(job-128) dequeue() enqueue(job-129) 6 queueHead 5 4 queueTail 3 2 1 0 [5] (c) The array, buffer and pointer values are declared with global scope. (i) The function dequeue returns null if the array is empty, and the contents of the next element if not empty. The queue is not circular. Write an algorithm, using pseudocode or program code, for the function dequeue(). [5] (ii) The function enqueue returns -1 if there is no space at the end of the queue to add data, and returns 1 if the parameter was added to buffer. The array buffer contains a maximum of 100 elements. Write an algorithm, using pseudocode or program code, for the function enqueue(). [6] (iii) In the main program of the simulation the user is asked whether they want to add an item to the queue or remove an item. If they choose to add an item they have to input the job name, and the function enqueue is called. If they choose to remove an item, the function dequeue is called and the job name is output. Appropriate messages are output if either action cannot be run because the queue is either empty or full. Write, using pseudocode or program code, an algorithm for the main program of the simulation. [8] (d) The queue is changed to make it a circular queue. Describe how the functions enqueue and dequeue will need to be changed to allow buffer to work as a circular queue. [3] (e) Some print jobs can have different priorities. The higher the priority the sooner the job needs to be printed. Describe how the program could be changed to deal with different priorities. [3]