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

AH Computing Science 2019 Question 1 (CfE)

15 marks · Inheritance and polymorphism

Using a programming language of your choice, write the code equivalent to Line 1 of the Event class, for the declaration for the WorkMeeting class. Describe the use of the Constructor method in the Event class. Using appropriate object-oriented terminology, explain the operation and effect of executing the following code. DECLARE sales INITIALLY WorkMeeting ( "22/6/19", "14:00", "Head Office", false, "June sales meeting", 12.0, 0.0 ) Explain the effect of executing the following code. sales.addParticipant("Chao Li") The venue for the event called sales has been changed. By referring to the UML class diagram and using appropriate object-oriented terminology, explain why it is not possible to edit the value already assigned to the venue property. A user of the app can claim £0·50 from their employer for every mile travelled for work meetings. The calculateTravelExpenses() method will multiply the mileage by £0·50 to calculate the travelling expenses for one meeting. The calculateTravelExpenses() method makes use of a procedure. Line 21 PROCEDURE calculateTravelExpenses() Line 22 Line 23 END PROCEDURE Using a programming language of your choice, write the code for Line 22 of the calculateTravelExpenses() method. The following line of code creates an array of 100 meetings. DECLARE myMeetings2019 AS ARRAY OF WorkMeeting INITIALLY <array of 100 WorkMeeting objects> Travel expenses can be claimed at the end of every month. Using a programming language of your choice, write the code used to calculate the total travel expenses for all meetings stored in the myMeetings2019 array that took place in April 2019. Increased popularity of the MyBusyLife app means more servers are needed to store and process users’ data. Describe two environmental implications of this increased popularity. A new time management and planning app called MyBusyLife has been developed using an object-oriented programming language. A simplified version of the UML class diagram and the code for the Event class is shown below. - date: String - startTime: String - venue: String - eventType: String - alert: Boolean - description: String - participants[]: String - index: Integer + Event() + setEventType() + setDescription() + updateDate() + getDate() + addParticipant() Event WorkMeeting Personal - meetingTitle: String - mileage: Real - travelExpenses: Real + WorkingMeeting() + calculateTravelExpenses() + getTravelExpenses() Line 1 CLASS Event IS { STRING date, STRING startTime, STRING venue, BOOLEAN alert, ARRAY OF STRING participants, INTEGER index } Line 2 METHODS Line 3 CONSTRUCTOR ( STRING date, STRING startTime, STRING venue, BOOLEAN alert ) Line 4 DECLARE THIS.date INITIALLY date Line 5 DECLARE THIS.startTime INITIALLY startTime Line 6 DECLARE THIS.venue INITIALLY venue Line 7 DECLARE THIS.alert INITIALLY alert Line 8 DECLARE THIS.participants INITIALLY [NULL] * 20 Line 9 DECLARE THIS.index INITIALLY 0 Line 10 END CONSTRUCTOR Line 11 PROCEDURE updateDate(STRING eventDate) Line 12 SET THIS.date TO eventDate Line 13 END PROCEDURE Line 14 FUNCTION getDate() RETURNS STRING Line 15 RETURN THIS.date Line 16 END FUNCTION Line 17 PROCEDURE addParticipant(STRING name) Line 18 SET THIS.participants[index] TO name Line 19 SET index TO index + 1 Line 20 END PROCEDURE Line 21 END CLASS

Marking scheme

CLASS WorkMeeting INHERITS Event WITH { STRING meetingTitle, REAL mileage, REAL travelExpenses } 1 mark for class declaration indicating use of inheritance 1 mark for additional attributes; only award mark for nine attributes if no inheritance indicated The constructor assigns initial values upon instantiation of an object. Description must mention creation/instantiation of an object. A new object of the WorkMeeting subclass has been instantiated (1 mark) The values are assigned to the relevant instance variables with the constructor initialising an empty array to store the list of participants and initialising the array index as zero (1 mark) Award 1 mark each for 2 of the following: • instantiation/creation of object or invoke constructor method for WorkMeeting class • assignment using the 7 values provided and additional two attributes of Event class Award 1 mark each for any two of the following: • A new participant called Chao Li has been added to the array of meeting participants • and the array index is incremented • Invoke addParticipants() method Encapsulation means that a property cannot be edited directly. (1 mark) A method needs to exist in order to update the venue property. (1 mark) 1 mark for encapsulation/private variable 1 mark for need for method SET THIS.travelExpenses TO THIS.mileage * 0.5 1 mark for correct calculation Note: use of THIS is not mandatory FOR i FROM 0 TO 99 DO IF (myMeetings2019[i].getDate( ) >= "01/04/2019") AND (myMeetings2019[i].getDate( ) <= "30/04/2019") THEN SET THIS.expenses TO THIS.expenses + myMeetings2019[i].getTravel Expenses() END IF END FOR 1 mark for correct use of getDate() and getTravelExpenses() methods of the array of objects 1 mark for correct condition 1 mark for updating running total using myMeetings2019 array Note: accept calculateTravelExpenses() method rather than getTravelExpenses() method Note: alternative methods for finding dates in April are acceptable eg use of substring Increase in energy used to process users’ data in the company data centre leading to increased carbon emissions. Need to use low carbon or energy efficient equipment in the company data centre to reduce carbon emissions needed to run the devices. 1 mark each Note: answers must refer to environmental impact.

Previous question: AH Computing Science 2018 Question 4 (CfE)

Next question: AH Computing Science 2019 Question 2 (CfE)