Anda di halaman 1dari 2

University of Aden Faculty of Engineering Even Semester Examination (2012-2013) Subject: Object Oriented Programming Date: / /2013 Class:

B2CS/B2CSE Time: 2 hours -------------------------------------------------------------------------------------------------------ANSWER ANY FOUR QUESTIONS 1# (a) Give the code for an example when you use a friend function. Using the Phone class which containing a name of a person, and a phone number. Include a default constructor. Use the UML to draw its class diagram. (b) Fill up the blanks: (i) . is a process of creating different implementations of a method which have a same name as base class, in a derived class. (ii) .. is a process of acquiring attributes and behaviors from another class. (iii)A .. member ensures that there will be exactly one copy of the member, shared by all objects of the class. (iv) A class is like an ordinary class, except that its definition is based on one or more existing classes, called base classes. 2# (a) Give the code for an example when you use a static method. Using the Person class which containing the Name of the person, his Address, and his ID number. Include a constructor and appropriate methods. Use the UML to draw its class diagram.

(b) Name the type of the relationships in these class diagrams?

(i)

(ii)

(iii)

3# (a) Describe, with an example, a case where Virtual Inheritance is necessary (b) TRUE or FALSE: (i) Can we have a virtual inheritance? (ii) Constructors and destructors can be overloaded? (iii) If you dont write a friend method, the compiler supplies one for you (iv) If you dont write a copy constructor, the compiler supplies one for you. 4# (a) Give the code for an example when you use a friend class. Using the BOOK class which containing the books title, authors name, and number of the copies of the book. Include a copy constructor and appropriate methods. Use the UML to draw its class diagram.

(b) What are the differences?


(i) (a) BOX c1,c2; c1=c2; (b) BOX c3=c2; (b) main() { CAR MyCar = MyCar (4,120); } (ii) (a) main() { CAR MyCar (10,20); . }

5# (a) Give the code for an example when you use a class template. Using the Box class which containing the length, width and the height of the box. Include a constructor overloading and appropriate methods.

(b) Select the correct answer: (i) UML stands for


1) Unique modeling language. 3) Unified modern language 2) Unified modeling language . 4) Unified master language.

(ii) Can two classes contain member functions with the same name?
1) No. 3) Yes, this is always allowed. 2) Yes, but only if the two classes have the same name. 4) Yes, but only if one of them is a derived class.

(iii) A C++ class destructor is automatically invoked


1) When the template of the class is called. 3) When the class instance goes out of scope. 2) When one of the data members is a pointer. 4) A class destructor is not called automatically

6# (a) How do I initialize a Pointer to a function? (b) How to declare a Reference in a class? (c) How do I avoid Memory leaks?

Anda mungkin juga menyukai