ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions
15 marks · Classes and objects
A simplified version of the UML class diagram for the program is shown. Member Athlete Team -teamName: String -anthem: String -flag: String -teamList: Array of Member -event: String -personalBest: String -homeClub: String -firstName: String -lastName: String -dateOfBirth: Date -gender: String +introduce() +addMember() +deleteMember() +introduce() +introduceTeam() -email: String -twitter: String -facebook: String Official +introduce() +calculateAge() -position: String -sport: String -rating: Integer +allocateToEvent() By referring to the class diagram above, explain: • the difference between a class and an object • encapsulation • inheritance Some of the code used to define the class Team is provided below. CLASS Team IS { STRING teamName, STRING anthem, STRING flag, ARRAY OF Member teamList } METHODS CONSTRUCTOR ( STRING teamName, STRING anthem, STRING flag ) DECLARE THIS.teamName INITIALLY teamName DECLARE THIS.anthem INITIALLY anthem DECLARE THIS.flag INITIALLY flag DECLARE THIS.teamList INITIALLY [] END CONSTRUCTOR PROCEDURE addMember( Member newMember ) SET THIS.teamList TO THIS.teamList & [newMember] END PROCEDURE END CLASS An instance of the Team class is to be created using the following values. Team Name Brazil Anthem Hino Nacional Brasileiro Flag Bandeira do Brasil Using the data provided and a programming language with which you are familiar, write the code used to instantiate a Team object. Your code should make use of each of the values provided. The details of the athletes taking part in individual events will be stored in separate arrays of objects. For example, the longjumpM array will store the details of all 32 male athletes taking part in the long jump event. Using a programming language with which you are familiar, write the code used to create the array of objects used to store details of the 32 male athletes in the long jump event. Two introduce methods have been written for the Member and Athlete classes respectively. # Version in Member class PROCEDURE introduce() SEND “Hello, my name is “ & THIS.firstName TO DISPLAY END PROCEDURE # Version in Athlete class OVERRIDE PROCEDURE introduce() SEND “Hello, my name is “ & THIS.firstName TO DISPLAY SEND “I’m an athlete on the team” TO DISPLAY END PROCEDURE A new Team object called myTeam has been created. The following calls have been made to add Ali, Omar and Nour to the team. myTeam.addMember( Athlete(“Ali”, <only firstName needed here> ) ) myTeam.addMember( Member(“Omar”, <only firstName needed here> ) ) myTeam.addMember( Official(“Nour”, <only firstName needed here>) ) Write down the output displayed by the following procedure call: myTeam.introduce() Use object oriented terminology to explain the operation of the procedure call in (c) part (i) above. The names of the top 10 medal winning teams are held in a stack. Part of the stack is shown. 1 Brazil 2 United Kingdom 3 Germany 4 France 5 Australia 6 7 8 9 10 The USA wins enough medals to be fourth on the table. Write down the sequence of stack operations required to produce the new table. 1 Brazil 2 United Kingdom 3 Germany 4 USA 5 France 6 Australia 7 8 9 10 The stack storing the medal winning teams could be implemented using a linked list. The diagram below represents a linked list after the first six teams have been added to the medal table. Stack pointer 318 Australia 706 France 153 241 318 319 706 707 154 Brazil UK 208 Germany 439 439 450 242 USA 153 Null 208 209 241 Team Russia is to be added to the medal table between Germany and the USA. Describe how team Russia would be added to the correct place in the linked list. The Olympic Games generate a large amount of data. Sources of this big data will include ticket sales, competition and performance data, information gathered from retail and catering outlets and details of sponsorship deals and merchandising. Data analytics will be used to analyse the big data. Using one of the sources of big data listed above, describe one benefit to the Olympic Games Management Committee of using analytics when preparing for the 2020 Olympic Games. A program is to be written to process the results of different events in the 2016 Olympic Games.
Difference object and class Class is a template that defines the methods and attributes; object is an instance of a class. For example, teamName, anthem, flag and teamList are attributes within the class Team and an example of an object would be UK. Encapsulation Encapsulation is shown through the visibility on the (class) diagram. For example, access to the attributes, operations and class can be limited. In the diagram teamName is private and only available to the Team class; out with the Team class, it can only be accessed through use of the Team class methods. Inheritance Inheritance is demonstrated between classes Member and Athlete (or between Member and Official). The Athlete (or Official) class inherits all of the methods and attributes from the Member class. 2 marks for correct description of difference between class and object 1 mark for correct description of encapsulation 1 mark for correct description of inheritance Note that marks should only be awarded if descriptions make correct and appropriate reference to the class diagram. (a) DECLARE team1 INITIALLY Team ("Brazil","Hino Nacional Brasileiro", "Bandeira do Brasil”) 1 mark for correct use of team name, anthem and flag value Note that the variable declaration is not necessary to instantiate the object (DECLARE … INITIALLY is not necessary). Note also that answers that make use of OO languages such as Java and VB are acceptable alternatives to Haggis. DECLARE longjumpM AS ARRAY OF Athlete * 32 1 mark for declaration of array of Athlete objects 1 mark for correct dimension Hello, my name is Ali I’m an athlete on the team. Hello, my name is Omar. Hello, my name is Nour. 1 mark for correct output produced by calls The procedure call invokes the introduce method of the myTeam object. teamList is an array of Members which can store objects of type Member, Athlete or Official. Since Athlete inherits methods and properties from Member, the introduce method in the Athlete class overrides the introduce method in the super class: since the member with firstName Ali is an athlete, the output is produced by applying the overriding method. Official also inherits methods and properties from Member but since it has no overriding method of its own, the output for the member with firstName Nour is produced by applying the method in the superclass. The output for the object of class Member with the firstName Omar is straightforwardly generated by the introduce method in Member. 1 mark each for any two relevant points that make appropriate use of relevant OO terminology Examples of OO terminology that could be discussed in the answers include: • (super) class and sub-classes • inheritance • polymorphism Pop Australia, pop France, push USA, push France, push Australia 1 mark for correct pop operations 1 mark for correct push operations A new node would be added to store Russia and its pointer would be set to 241 (team Germany). The pointer of the node containing USA would be updated; instead of storing 241, it would now store the address of the new node. 1 mark for addition of new node containing Russia and correct value of its pointer 1 mark for updating pointer of node containing USA with address of the new node Analytics will provide insights and patterns that aid decision making. For example, analysis of ticketing and competition data could benefit the Management Committee by providing them with details about which events were popular with the general public from across the world and which areas of the arenas sold quickly. Analytics could show whether event popularity varied from country to country and whether it was dependent on the participation of particular athletes. This could help the Committee to determine their pricing and distribution of tickets for the Games in 2020. 1 mark for description of one benefit of analytics for the Management Committee Description must make reference to one of the sources of big data listed in the question and must illustrate how analytics could be applied to that data to benefit the Committee.
Previous question: AH Computing Science 2016 Question 2 (CfE)