Question 6

OCR Computer Science November 2020 Paper 2A level40 marks

On the specification

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

6 Barney is writing a program to store data in a linked list. He is writing the initial program for a maximum of 10 data items. Each node in the linked list has a data value and a pointer (to the next item). A null pointer is stored with the value –1. (a) Fig. 3 shows the current contents of the linked list including the head and free list pointer values. index data pointer headPointer 0 0 2.6 3 13.5 –1 freeListPointer 4 2 1.8 1 36.9 2 45 56 67 78 89 9 –1 Fig. 3 (i) Describe the purpose of freeListPointer. [2] (ii) State the purpose of headPointer. [1] (iii) Show the contents of the linked list from Fig. 3 and the pointer values when the node with data 6.9 is deleted. index data pointer headPointer 0 1 freeListPointer 2 3 4 5 6 7 8 9 [4] (b) Barney wants the nodes to be stored as objects using object-oriented programming. He designs the following class. class: node attributes: private data : Real private pointer : Integer methods: new (newData, newPointer) getData() getPointer() setData(newData) setPointer(newPointer) The constructor assigns the parameters to the attributes to create an object. (i) Write an algorithm, using pseudocode or program code, to create the class node, its attributes and constructor. You do not need to write the get and set methods. [4] (ii) The class node, uses get methods and set methods. Describe one difference between get methods and set methods. [2] (c) The function findNodePath() takes the data item to find in the linked list as a parameter and follows the pointers to find the required node. The function returns the array indexes of all the nodes it visits and joins this to a suitable message stating whether the data was found or not found and then returns this as one string. Describe how the function findNodePath() will search for the data item and return the required message. [6] (d) The procedure printLinkedList() follows the pointers to print all of the elements in the linked list. 1 procedure printLinkedList(headPointer) 2 tempPointer = headPointer - 1 3 dataToPrint = ″″ 4 if tempPointer == -1 then 5 print(″List is full″) 6 else 7 while linkedList[pointer].getPointer() != -1 8 dataToPrint = dataToPrint + ″ ″ + linkedList[tempPointer,0] 9 linkedList[tempPointer].getPointer() = tempPointer 10 endwhile 11 print(dataToPrint + ″ ″ + linkedList[tempPointer].getData() 12 endif 13 endprocedure The procedure has a number of errors. (i) Identify the line of each error and write the corrected line. Error 1 line number Error 1 correction Error 2 line number Error 2 correction Error 3 line number Error 3 correction [3] (ii) Barney will use an Integrated Development Environment (IDE) to debug his program code. Describe three features commonly found in IDEs that Barney could use to debug his program code. 1 2 3 [6] (e)* Barney would like his linked list to be part of a base program that is saved in a library. This means that it can be reused and changed by other programs. Discuss the benefits of using different object-oriented techniques that Barney could use to achieve this. [12]