Question 6
OCR Computer Science June 2018 Paper 2A level50 marks
On the specification
- (a)(i)
- 1.2 Software and software development1.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 algorithms
- (b)(i)
- 1.4 Data types, data structures and algorithms
- (b)(ii)
- 2.2 Problem solving and programming
- (b)(iii)
- 2.2 Problem solving and programming1.4 Data types, data structures and algorithms
- (b)(iv)
- 1.4 Data types, data structures and algorithms2.2 Problem solving and programming
- (b)(v)
- 2.2 Problem solving and programming
- (b)(vi)
- 2.2 Problem solving and programming1.4 Data types, data structures and algorithms
Question text
6 Kamran is writing a program to manipulate the data for a set of items. For each item, the program needs to store: • Item name (e.g. Box) • Cost (e.g. 22.58) • Date of arrival (e.g. 1/5/2018) • Transferred (e.g. true) The items are added to a queue for processing. The queue is defined as a class, itemQueue. itemQueue theItems[10] : Items head : Integer tail : Integer numItems : Integer constructor enqueuer() dequeuer() setnumItems() getnumItems() The head attribute points to the first element in the queue. The tail attribute points to the next available space in the queue. The numItems attribute states how many items are currently in the queue. (a) The data about the items can be stored using either a record structure, or as objects of a class. (i) Explain the similarities and differences between a record and a class. [3] (ii) Kamran chooses to use a record structure to store the data about the items. Record structures may be declared using the following syntax: recordStructure recordstructurename fieldname : datatype endRecordStructure Complete the pseudocode to declare a record called items. recordStructure itemName : : Currency : Date transferred : endRecordStructure [5] (iii) New records may be created using the following syntax: recordidentifier : recordstructurename recordidentifier.fieldname = data Write a programming statement to create a new item, using the identifier ‘box1’, with the item name “Box”, the cost 22.58, date of arrival 1/5/2018 and transferred true. [3] (b) The array, theItems, stores the items in the queue. When the tail of the queue exceeds the last element in the array, it adds a new item to the first element if it is vacant. For example, in the following queue, the next item to be added would be placed at index 0. Index 0 1 2 3 4 5 6 7 8 9 Element Data Data Data Data Data Data Data (i) Define the term ‘queue’. [2] (ii) The attributes in itemQueue are all declared as private. Explain how a private attribute improves the integrity of the data. [2] (iii) The constructor method creates a new instance of itemQueue and sets the head, tail and numItems attributes to 0. Write an algorithm, using pseudocode or program code, for the constructor including the initialisation for all attributes. [2] (iv) The enqueue method: • takes as a parameter the item to insert in the queue • checks if the queue is full • reports an error and returns false if the queue is full • does the following if the queue is not full: o adds the item to the array at the tail position and adjusts the pointer(s) o returns true The attribute numItems stores the number of items currently in the queue. Write an algorithm, using pseudocode or program code, for the enqueue method. [6] (v) Write a programming statement to declare an instance of itemQueue called myItems. [1] (vi) Write a procedure, insertItems(), to ask the user to input the data for an item. The item is then added to the queue myItems. The user is continually asked to input data items until the queue is full. [5] (vii) When the main program ends, the items and the queue no longer exist. Describe how Kamran could amend the program to make sure the items and queue still exist and are used the next time the program is run. [2] (c)* Kamran wants to expand the program to allow it to handle up to 100,000,000 items and to allow him to search for data about items. Kamran is worried that the increase in the number of items will cause a decrease in the performance of the program. He decides to investigate the benefits of caching and concurrent processing. Evaluate the use of caching and concurrent processing in this scenario and make a recommendation to Kamran. [9]