Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
BEAULIEU COLLEGE INFORMATION TECHNOLOGY OOP SBA Test – 2016 GRADE 12 Time: 45 min Examiner: F. D. Khan Marks: 40 Moderator : Elaine Emmet ___________________________________________________________________________________________________ INSTRUCTIONS Answer ALL questions on the question paper. This question paper consists of 7 pages. Please check that your paper is complete ___________________________________________________________________________________________________ NAME OF LEARNER: ____________________________________________________ Question 1 1. An object definition class usually has a number of fields that describe the characteristics of the object. These fields are usually prefixed with an access Modifier 1.1 List the names of two access modifiers that you have used and explain their functionality in a program. (2) Public and private, public means the code is accessible outside of the class while private means that the code is only accessible from inside of the class. 1.2 Explain the purpose of using mutator (setters) methods in a class? (1) The purpose of mutator methods is to change the values of private fields in a class. 1.3 Differentiate between a class provider and a class user. (2) The class provider is the programmer who codes the class and the class user is a programmer who instantiates an object of the class. 1.4 What is a helper method and what is its significance? (2) Helper methods are private methods that are called by public methods. They are used to add functionality to a class. 1.5 What is encapsulation in relation to programming in either Java or Delphi? (1) Encapsulation occurs when a class combines the fields and methods into one unit of code _________________________________________________________________________________________________Total [8] Question 2 Algorithms and Pseudo Code 2.1 What is an algorithm? (1) An algorithm is a sequence of instructions, that if followed will result in a single programming problem being solved by following specific steps. 2.2 What is the purpose of writing in Pseudo Code? It allows the designer to focus on the logic of the algorithm without being distracted by details of language syntax (2) 2.3 Consider the following Java and Delphi code below. Public class HodgePodge() { getWritingStuff(); OpenStudyGuide(); OpenClassworkBook(); for ( int x= 0; x <= 9; x++) { question[x].solve(); while( !question[x].isDoneCorrectly()) { this.removeAnswer(x); question[x].solveThisProblem(); } allComplete(); submit(); } } Unit HodgePodge; Interface … implementation Function getWritingStuff; Procedure OpenStudyGuide; Procedure OpenClassworkBook; for x := 0 to 9 do begin question[x].solve; while( NOT question[x].isDoneCorrectly) do begin removeAnswer(x); question[x].solveThisProblem; end; allComplete; submit; end; end. Nathaniel, is having some difficulty understanding the code that has been created for the HodgePodge class/Unit. You have taken it upon yourself to help him understand the code by converting this code to Pseudo Code. Write a simple algorithm in Pseudo Code that you will give to Nathaniel to help him in his understanding of the abovementioned class. (4) method Hodgepodge() get Writing stuff open StudyGuide and ClassWorkbook work through ALL 10 of the questions begin solve the questions while the questions are not done correctly try again end complete everything submit your work _________________________________________________________________________________________________Total [7] Question 3 Objects, constructors and the toString method/function 3.1 Differentiate between a default constructor and a parameterised constructor? (2) The purpose of a constructor is to add values to the fields of an object, the default constructor assigns default values to the fields of an object chosen by the class provider whilst a parameterized constructor assigns values to the fields of an object as arguments inside brackets of the constructor method which are passed to the constructor from the call statement. 3.2 What is required in order for you to instantiate an object of a class? Write a line of code to show how instantiation of an object can be achieved. (2) An object gets created in Java by using the new operator and calling the constructor of a class. Gogga bug = new gogga() or similar for Delphi 3.3 What is the purpose of a toString method/function in a class? (1) The toString() method is used when we need a string representation of an object and is usually coded in a class. 3.4 What will happen if a constructor method is not coded in a class? (1) A default constructor is automatically created _________________________________________________________________________________________________Total [6] Question 4 4.1 Consider the following class diagram Member Properties/Fields: ‒ ‒ ‒ ‒ String name String Surname String Address Email emailAddr Methods: + + + + + + Constructor(String nme, String Sname, String Addr, Email emailad) getName : String getsurname : String getAddress : String; setSurname(String s) toString() : String A program can have many objects and they all need to interact with one another in different ways. This is achieved either through Inheritance or Composition. Inheritance refers to when you extend all the properties and methods of a parent class into a child class. Composition refers to when a class only uses certain objects from another class. The class above uses Composition and one of its attributes, emailAddr, is an object from the Email class. 4.1.1 Write code to create a constructor method that will initialise all the properties/fields of the Member class. (3) Java public Member(String nme, String sn, String add, Email emailad) { name = nme; surname = sn; address = add; emailAddr = emailad; } Delphi constructor TMember.Create (nme: String, sn:String, add:String, emailad:Email); begin name := nme; surname := sn; address := add; emailAddr := emailad; end; 4.1.2 The attribute emailAddr, is an object of the Email class (not shown here). Write down TWO possible attributes of the Email class. JAVA (2) private String to; private String from; DELPHI Private to:String; Private from:String; 4.1.3 Besides the constructor and toString methods, the Email class may have other methods. Write down the method headers for THREE other methods of the Email class. (3) JAVA public void setEmail() {} public String getEmail() {} public String sendEmail() {} DELPHI Procedure TMember.setEmail Function TMember.getEmail:String; Function TMember.sendEmail:String; 4.2 Arrays play a huge part in programming because they allow us to manipulate data structures in primary memory. 4.2.1 What is the purpose of an array index or subscript? A symbol or a number used to identify an element in an array. Usually, the subscript is placed in brackets following the name of the array. (1) 4.2.2 How would you use an array in programming to store an unknown number of data items? (1) Use an ArrayList or listIterator 4.2.3 An object called Patient with a name, age, gender and procedure (eg. Colonoscopy, heart bypass, appendix removal) fields, exists. (5) A Patientmanager has the following declaration: Patient [ ] Arr = new patient [50] … in Java Arr : Array [1..50] of TPatient; … in Delphi Write Pseudocode to sort the array in ascending order according to the procedure field. Use a method. Subprogram Sort Temp : Patient Begin For j = 0 to counter -2 Begin For i = j+1 to counter -1 Begin If Arr[j].getProcedure > Arr[i].getProcedure Then Begin Temp = Arr[j] Arr[j] = Arr[i] Arr[i] = Temp End; End; End; End; 4.4 Static and Non-static Methods A class called Vehicle, a method called tint and an object called window are given. 4.4.1 How would you call the static method using dot notation? (2) Vehicle.tint 4.4.2 How would you call the non-static method using dot notation? (2) Window.tint ___________________________________________________________________________________________________Total [14]