ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions

AH Computing Science 2017 Question 3 (CfE)

15 marks · Inheritance and polymorphism

The application stores data from SensorValve and RemoteSensorValve objects. This is shown in the UML class diagram below. SensorValve Thread 1 0..* − name: String − valveNumber: Integer − currentState: Boolean − start[] − run[] − stop[] + SensorValve[]: Integer + getvalveNumber[]: Integer + sensorStatus[]: Boolean + activate[] + monitor[] + run[] RemoteSensorValve − currentValue: Integer − RemoteSensorValve[] − getCurrentValue[]: Integer Using the class diagram above, describe the relationship between the SensorValve class and the RemoteSensorValve class. Using an object-oriented programming language with which you are familiar, write a Class definition for a RemoteSensorValve object. Your answer should include the property and methods indicated in the UML class diagram above. Write code to show how your Class in part(ii) could be instantiated. A 1-D array of RemoteSensorValve objects is used to store the properties and methods of 10,000 RemoteSensorValve objects. Imogen writes a procedure to sort this array into ascending order based on the currentValue reading of each object. She decides to use the insertion sort algorithm. Imogen uses the procedure call below to activate the insertion sort procedure: insertionSort( remoteSensorValveArray[] ) Use pseudocode to design the insertionSort procedure used to sort the array of objects into ascending order. Once it has been completed, the application will be a large, complex piece of software that will incorporate Imogen’s procedure to sort the array of objects. Explain the relevance of component testing in this situation and describe how it could be carried out. Sensors manufactured by the engineering company are used by AirFlappe Airlines in their fleet of 700 aircraft. These sensors provide data for real-time analysis of engine performance during a flight. On a daily basis, each aircraft generates approximately 12·5 million terabytes of data. Describe one implication of this example of ‘big data’ analytics for AirFlappe Airlines. Imogen is a programmer for an engineering company that manufactures sensors. She is creating a new application that is used to ensure that the sensors are working correctly.

Marking scheme

RemoteSensorValve is a subclass of the SensorValve class. It inherits the attributes and methods from the SensorValve (super) class. The subclass can access the attributes and methods of the super class if the permissions have been granted by allowing [public/protected] access. RemoteSensorValve may call any public methods of the SensorValve class as if they were defined within itself. Award 1 mark each for any two of the following: • 1 mark for explanation of Subclass/Super class • 1 mark for explanation of inheritance • 1 mark notion of encapsulation CLASS RemoteSensorValve INHERITS SensorValve { WITH INTEGER currentValue } METHODS CONSTRUCTOR RemoteSensorValve() DECLARE THIS.currentValue INITIALLY 0 END CONSTRUCTOR FUNCTION getCurrentValue() RETURNS INTEGER RETURN THIS.currentValue END FUNCTION END CLASS 1 mark for inheritance with currentValue 1 mark for (accessor) method that returns currentValue 1 mark for the constructor method Notes • CLASS, METHODS and END CLASS are not required to gain full marks • Other languages are possible and are acceptable alternatives to the Haggis solution DECLARE rsv1 INITIALLY RemoteSensorValve() Note: class name must be correct PROCEDURE insertionSort(ARRAY OF RemoteSensorValve rsvArray) FOR index FROM 1 TO 9999 DO SET posn TO index WHILE posn > 0 AND rsvArray[posn- 1]. getCurrentValue() > rsvArray[posn].getCurrentValue() SET temp TO rsvArray[posn] SET rsvArray[posn] TO rsvArray[posn-1] SET rsvArray[posn-1] TO temp SET posn TO posn-1 END WHILE END FOR END PROCEDURE Award 1 mark each for any 5 of the following: 1 mark for use of array of objects with appropriate indexing 1 mark for appropriate use of getCurrentValue method 1 mark for use of fixed loop to process all elements of the array except the first one 1 mark for use of conditional loop with correct complex condition to control inner loop OR 1 mark for use of fixed loop with a step of -1 to control inner loop 1 mark for correct use (inc updating) of posn variable needed to control inner loop 1 mark for swapping correct array element 1 mark for correct comparison of adjacent items in the array Imogen’s procedure is created in isolation from the rest of the manufacturing application and therefore, component testing can be used to make sure that it works correctly being it is integrated within the larger application. She should write use a stub or driver to activate the subprogram and pass parameter values to it. Component testing focusses on the output of this single procedure and is a form of black box testing: we are interested in the fact that the output is correct and aren’t concerned about how the output is produced. A set of test data should be created and expected output should be calculated/computed. The results of applying the test data values to the code should be compared with the output produced to determine whether or not the subprogram is working correctly. 1 mark for explanation of use made of component testing to test Imogen’s subprogram 1 mark for description of how this component testing would be carried out. This may refer to use made of: • stubs/drivers • test data and expected output values • black box testing Many implications could be described. For example: • Fault Diagnostics • Airline safety • Passenger confidence 1 mark for suggesting an appropriate implication 1 mark for description of that implication for Airflappe Airlines

Previous question: AH Computing Science 2017 Question 2 (CfE)

Next question: AH Computing Science 2017 Question 4 (CfE)