0% found this document useful (0 votes)
63 views40 pages

Object Oriented Programing Dec 2010,2013,2016

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
63 views40 pages

Object Oriented Programing Dec 2010,2013,2016

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 40
THE MICO UNIVERSITY COLLEGE QUESTION PAPER FORM ‘Course Code and Title: OBB Date: December 2010 Tie Duration 29 Hours semeste ti Semester summerSession Cl Supplemental © a Aprijimay july Material Required: Answer Booklet: Normal i Special o Notrequied == Caleulator: (where applicable) Programmable Non-programmable C1 Multiple Choice Answer Sheets: No ofitems: 1 Numerical = Alphabetical = | Ausilary/Other material: Please specity card 4 Instructions to Students: This paperhas 1 pagesand __10__ questions. Students are reminded that the examiners will take into account the proper use of the English Language in determining the mark for each response. SECTION A INSTRUCTION: Answer ALL questions in this section 1. Use the declaration of the class Student. and its prototypes, in C++, to answer the following questions. class Student { char name (50]; int age; long int idNumber; public Student () 7 void get_data (void); void set_data (char*, int, int); fa) (b) () (d) (e) (f (eg) (a) (b) What is the access specifier for the data members of Student? (1. mark) Identify the constructor for the Student class. (1. mark) Write PIECES of C++ codes for part(c) ~ (g) that: define the function set_data outside of the class. {6 marks) create TWO Student objectsMary and John. (mark) use the Student object Mary to set the data fora student name “Mary”, age, 20 and id number 20351. (2 marks) use the Student object John to output John’s data. {1 mark) declare a friend function of Student’ name newIdNumber that returns an integer and takes a Student object argument. (2 marks) Draw an inheritance hierarchy graph representing a typical university with thousands of people who are classified as Students. These students consist of Undergraduatestudent and Graduatestudent. UndergraduateStudents are classified as Freshman, Sophomore, Junior and Senior. AGraduateStudent canbe categorized asa DoctoralStudent ora Mastersgtudent. The university has a special programme that allows some Doctoral Student andMastersStudent to be Tutors. {6 marks) Show on your graph AN INSTANCE of the following: i. a single inheritance (1 mark) ii ‘a multiple inheritance {i mark) ili a superclass only (amark) iv. asubciass only (amark) v. asuperclass and subclass (1mar ) SECTION B INSTRUCTION: Answer ALL questions in this section 3, (a) Object Oriented Programmers claim that the use of friend functions is NOT an object-oriented programming (OOP) methodology. Give ONE (1) reason for this claim and say how OOP programmers can correct this technique. (2 marks) (b) Explain briefly what is meant by encapsulation in Object Oriented Programming (oop). (3 marks) 4, The table below shows how we can summarize the different access types of members of a C++ class by according to who can access them: ee Access ublic [protected [private __yes Members of the same class Members of the derived class Not members Copy and complete the table by writing YES if access is possible and NO if not possible in the empty cells. Eg. i, Members of the same class CAN access public members, therefore yes is placed in the cell that correspond to public. (4 marks) 5. Explain, using pieces of code, what is polymorphism in OOP? (5 marks) 6. _ In JAVA, with the use of examples differentiate between: i subroutines and toolboxes (2 marks) ii, static and non-static methods (3 marks) vi. API's and packages? (2 marks) 7. ImaJava application, the main () subroutine must be declared to be both static and public. (a) Why must the main () routine be static? (Why does this requirement make sense?) (2 marks) (b) Why must the main () routine be public? (Why does this requirement make sense?) (2 marks) SECTION C INSTRUCTION: Candidates MUST Answer QUESTION 8 and ONE other question in this section, 8. Use the information given below, class Point { attributes: int x, y methods: setX (int newx) get () setY(int newY) getY() class Circle { attributes: int x, y, radius methods: setX (int newX) getx() setY¥(int newY) gety() setRadius (int newRadius) getRadius () : of the TWO classes and the INHERITANCE concept of objects to write: (2) C++ codes to define the TWO classes (b) JAVA codes to define the TWO classes. (25 marks) 9. Suppose that you want a class (name HankAccount) to represent the money in a bank account, It needs FOUR methods: one to deposit a given amount into the account (called deposit that adds the amount received by the method to the balance and stores, it in balance) one to withdraw a given amount (called withdraw that subtract the amount received by the method from the balance and stores it in balance) * one to check how much money is in the account (called checkBalance that returns the balance), "and one to set the amount in a BankAccount. (called setAccount). © It also needs a constructor that creates an account containing a specified initial amount of money which is set to $0.00. © The class should have one instance variable called balance of type double, for storing the amount of money in the account, * Amain () subroutine, that: + creates a BankAccount object called firstAccount; + allows the user to set account balance + allows the user to make a deposit in the account * allows the user to make a withdrawal from the account + checks the balance in the account to determine if there is an overdraft on the account, if there is an overdraft the program should print “Sorry there is an overdraft on your account” otherwise the program should output the balance in the account. (N.B. overdraft means balance is below $0.00) Write a complete Java class satisfying these requirements. (25 marks) oR 10. Use the requirements above in QUESTION 9 to write a C+ program. (25 marks) END OF EXAMINATION THE MICO UNIVERSITY COLLEGE QUESTION PAPER FORM : . . . ] couse coseans te: Object Oriented Programming COMP 2001 | oa: December 2013 oe uration 2% Hours ey Semestertt Summer Session [supplemental Eemination Year 2013 perasy wy | atrial Required: Answer Boot ae Special o Notreuied = Cater (where appcble) Programmable Non programmable © Multiple cole ansior sheets No oftems: 1-20 huneieat = Aphabeial = | suxitiny/Other material Please specify Students are permitted to bring the following items to thelr desks: Pens; Pencils Ruler; Geometry Set; ID Card; Examination card Instructions to Students: This paperhas _8 pagesand _ 26__ questions. Answer ALL questions in section A and B AND ONLY ONE question from section C. Students are reminded that the examiners will take into account the proper use of the English Language in determining the mark for each response. SECTION A INSTRUCTIONS: (i) Answer ALL questions in this section (i) Choose the most appropriate response by shading the corresponding circle on the computerized answer sheet provided. Which of the following is use to access a member function from outside the class? (A) The class name (B) The dot operator (C)__ The open and close braces (D) The data member Which of the following would be attributes of car object? (A) drives, stops, accelerates and crashes (B) brakes, doors, wheels and seats (©) accelerates, doors, wheels and stops (D) colour, turns, wheels and doors In OOP relationships, what is a “is-a” relationship called? (A) composition (B) inheritance (C)__ polymorphism (D) object we format, void x :: s(t) (u) can be used to define a method. Which letter represents the class name? (A) @®) © ) Which of the following statements are TRUE about structures? Eoan i, Members of the same structure must have unique names, Different structures may NOT contain members with the same name. A structure may consist of other structures. A structure cannot contain an instance of elf. (A) ionly @) (©) _ iiiandivonly (D) ivi, iv only 10. ML. Which of the following is NOT TRUE when declaring data members? (A) They can be anywhere in the class. (B) They can be constants or static. (C) They must have an access specifier. (D) They can be other objects. Use the following information to answer questions 79. i. public members ii. private members iii. protected members Which members can other members that are not of a particular class access? (A) ionly (B) _ itonly (C)__ iand iii only (D) _ iiandiii only Which members can members of the same class access? (A) ionly (B) iionly (©) iand ii only (D) i, itand iii Which members can members of a derived class access? (A) ionly (B) _ iti only (©) iand ifi only (D) i, ivandiii What is a function that is specified by placing =0 at the end of its prototype in the class definition called? (A) _ inheritance (B) pure virtual function (C) zero function (D) polymorphism Assuming that text is a variable of type st ring, what will be the contents of text after the statement cin >> text; is executed if the user types “Hello World!” then presses Enter? (Ayo (B) "Hello" (C) "Hello world" (D) "Hello world!" 12. 13, 14. 15. 16. 17, Use the inheritance graph below to answer questions 12 ~ 14, 7] In the figure above, which of the following BEST describes X? (A) superclass only (B) subclass only (©) superclass and subclass (D) — multiple inheritance In the figure above, which of the following BEST describes Y? (A) superclass only (B) subclass only (C) superclass and subclass (D) multiple inheritance Inthe figure above, which of the following BEST describes Z? (A) superclass only (B) subclass only (©) superclass and subelass (D) multiple inheritance Which of the following is TRUE about objects of the same class? (A) Gets a copy of every member function and member variable. (B) _ Gets a copy of every member variable. (©) Gets a copy of every member function. (D) Shares pointers to all member variables and member functions. Which of the following is TRUE about member function definitions? (A) Always require the binary scope operator (::). (B) Require the binary scope operator only when being defined outside of the definition of their class. (© Canuse the binary scope operator anywhere, but become public functions. (D) Must use the binary scope operator in their function prototype. Which of the following is MOST likely a base class of the other three? (A) Employee. (B) Manager. (C)__ Executive. (D) Accountant. 18. Which of the following filename extension is a typical header filename extension? (A) oh ®) .hdr (©) -header (D) «cpp Use the statement class x:y 2 {p}; to answer question 19 19. Which letier in the statement above represents the type of inheritance? (A) x @B) y¥ © z @) p 20. Which of the following would NOT be a member function that derived classes Fish, Frog and Bird should inherit from base class Animal and then provide their own definitions for, so that the funetion call can be performed polymorphically? (A) eat (8) sleep (©) move (DP) flapwings [20 marks} SECTION B INSTRUCTION: Answer ALL questions in this section (2) Draw an inheritance hierarchy graph representing a typical university with thousands of people who are classified as Student's. These students consist of UndergraduateStudent and GraduateStudent. UndergraduateStudentss are classified as Freshman, Sophomore, Junior and Senior, AGraduateStudent can be categorized as a Doctoralstudent or aMasterestudent. The university has a special programme that allows some DoctoralStudent and MastersStudent to be Tutors. [6 marks} (6) Show on your graph AN INSTANCE of the following: i, a single inheritance ii, amultiple inheritance iii a superclass only iv. asubelass only Vv, _a.superclass and subclass [5 marks} Use the declaration of the class Triangle and its prototypes, in C++, to answer the following questions. class Triangle { private: int sidel, side2, side3; public: Triangle () ; void setTriangle(int, int, int); void getTriangle(); yi Write PIECES of C+ codes for parts (a) ~ (d) that: (a) define the constructor outside the class. [5 marks} (6) createa Triangle object name trgl. [1 mark] (©) set the sides of the object tral to 10, 12, 15. [2 marks} (@ output the sides of the trg object [1 mark] The program segment below contains FIVE (5) errors. class Q{ public: int Q( ){ qData = pData = 0;} void setpData( int p ){ return pData = p;} void printa(); private: int qData = 0; int pData; } void printg(){ cout << qData << pData << endl;} Identify EACH error and write the correct code for the errors outlined. [10 marks} 4, Use the information given below about the TWO classes and the INHERITANCE concept of objects to write C++ codes to define the TWO classes. {NB YOU SHOULD ONLY DEFINE THE CLASS. DO NOT WRITE AN ENTIRE, PROGRAM] class Student { attributes: char * name int id methods: setName (char* n) getName () setId(int idno) getId() } class Freshman { attributes: char * name int id, year methods : setName (char* n) getName () setId(int idno) getid() setYr(int yr) getYr() [20 marks} SECTION C INSTRUCTIO! Answer ONLY ONE question in this section 5. Write a C++ program that creates a class name Employee to represent the employees of an organization. © The class should have five (5) instance variables called fixetName and LastName of type char *, age and yearsOfService of type integer and salary of type floating point for storing the first name, last name, age, years of service and salary of an employee. * It needs TWO methods to get and set each of the data members (the set data method should be called set EmpLoyee and get data should be called print). ‘* It also needs a constructor that initializes an employee object with name “John Brown” age 0, years of service 0 and salary $0.00. © Amain () function, that: = creates an Employee object called e1 with first name “Bob”, last name “Jones”, age 30, years of service 12 and salary $100,000.00 = prints/outputs the values of el. [30 marks] 6. Write a C++ program that creates a class name BankAccount to represent the money ina bank account. © Itneeds FOUR methods: fone to deposit a given amount into the account (called deposit that adds the amount received by the method to the balance and stores it in balance) one to withdraw a given amount (called withdraw that subtract the amount received by the method from the balance and stores it in balance) one to check how much money is in the account (called checkBalance that returns the balance). and one to set the amount in a BankAccount. (called setAccount). + Italso needs a constructor that creates an account containing a specified initial amount of money which is set to $0.00. ‘© The class should have one instance variable called balance of type double, for storing the amount of money in the account. * Amain() function, that: creates a BankAccount object called firstAccount; allows the user to set account balance allows the user to make a deposit in the account, allows the user to make a withdrawal from the account checks the balance in the account to determine if there is an overdraft on the account, if there is an overdraft the program should print “Sorry there is an overdraft on your account” otherwise the program should output the balance in the account. (N.B. overdraft means balance is below $0.00) [30 marks} [TOTAL 100 MARKS] END OF EXAMINATION seer ees rennet ne rn cen wil Meee be 5 THE MICO UNIVERSITY COLLEGE 5 DEPARTMENT OF COMPUTER STUDIES FINAL EXAM PAPER Course Code and Title: (CO0P2101/ COMP2001) OBJECT ORIENTED PROGRAMMING Date: 19" DECEMBER 2016 Time: 1:00 P.M. | Duration 2 HOURS Semester @ Semester! O Summer Session Supplemental Examinations Year: __2016 December a April/May =. juy = Material Required: Answer Booklet: Normal a Special ao Not required o Calculator: (where applicable) Programmable Non-programmable 0 Multiple Choice Answer Sheets: No of items: 1-__20 Numerical o Alphabetical o ‘Auxiliary/Other material: Please specify 1. Students should be given an additional 10 minutes for reading script 2. Allexam scripts must be collected along with answer booklet, 3, Calculators are ALLOWED but must be provided by the institution ‘Students are permitted to bring the following items to their desks: Pens; Pencils; Ruler; Geometry Set; ID Card; Examination Card Instructions to Students: This paper has _° pagesand _?5 questions. ‘Answer ALL questions in section A and section B, and ONE (1) question from section C. Each question should begin on a new page. Students are reminded that the examiners will consider the proper use of the English Language in determining the mark for each response. DO NOT TURN OVER UNTIL INSTRUCTED TO DO SO SECTION A ‘Answer ALL questions in this section. In Object Oriented Programming (OOP), which of the following is classified as data member of a class? a. Behavior b. Attribute cc. Function d. Methods access functions? Which of the following access specifiers is used a. Public b. Private ©. Protected d. Friend in 00? relationships, what is a "is-3” relationship called? h a. Composition b. Inheritance Polymorphism d. Object ‘The format, void r::s(t){u} can be used to define a method. Which letter represents the method's name? ange Objects are created from abstract data types that encapsulate and together. ‘a. Numbers, characters b. Data, functions c. Addresses, pointers d. Integers, floats ‘What OOP concept is utilize in the class definition format class x:y 2(..}? a. Composition b. Inheritance c. Polymorphism d. Modularization 7. Given that the user want to use class A’s attributes in class B. Which of the following should be placed on the line below? class At int val; public: Display(cout

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy