Code: C-11 / T-22                                        Subject: OBJECT ORIENTED PROGRAMMING

Time: 3 Hours                                                      June 2006                                                Max. Marks: 100

 

NOTE: There are 9 Questions in all.

·      Question 1 is compulsory and carries 20 marks. Answer to Q. 1. must be written in the space provided for it in the answer book supplied and nowhere else.

·      Out of the remaining EIGHT Questions answer any FIVE Questions. Each question carries 16 marks.

·      Any required data not explicitly given, may be suitably assumed and stated.

Q.1       Choose the correct or best alternative in the following:                                         (2x10)

       

a.       How many constructors can a class have?

 

                   (A)  0                                                  (B)  1

(C)    2                                                 (D)  any number                                                   

 

b.      The new operator

                                                                         

(A)    returns a pointer to the variable    

(B)    creates a variable called new

(C)  obtains memory for a new variable                                                                            

(D)  tells how much memory is available

                                                               

             c.   Consider the following statements:

                   int x = 22,y=15;

                   x = (x>y) ? (x+y) : (x-y);

                   What will be the value of x after executing these statements?

 

(A)    22                                                (B)  37

(C)  7                                                  (D)  Error. Cannot be executed

 

             d.   An exception is caused by

 

(A)    a hardware problem                    (B) a problem in the operating system

(C)  a syntax error                              (D)  a run-time error

                                                         

             e.   A template class                                 

 

(A)     is designed to be stored in different containers            

(B)     works with different data types

(C)     generates objects which must be identical                  

(D)    generates classes with different numbers of member functions.

 

             f.    Which of the following is the valid class declaration header for the derived class d with base classes b1 and b2?

 

(A)     class d : public b1, public b2         (B)  class d : class b1, class b2

(C)  class d : public b1, b2                   (D)  class d : b1, b2

 

 

             g.   A library function exit() causes an exit from

 

(A)     the loop in which it occurs            (B)  the block in which it occurs

(C)  the function in which it occurs        (D)  the program in which it occurs

 

             h.   RunTime polymorphism is achieved by ___________

 

(A)    friend function                               (B) virtual function

(C) operator overloading                     (D) function overloading

 

             i.    The process of building new classes from the existing one is called _________

 

(A)   Polymorphism                               (B)  Structure

(C) Cascading                                     (D) Inheritance

       

             j.    An array element is accessed using

 

(A)  a FIFO approach                         (B)  an index number

(C)  the operator                                 (D)  a member name

 

 

Answer any FIVE Questions out of EIGHT Questions.

Each question carries 16 marks.

 

  Q.2     a.   Discuss the role of inheritance in object-oriented programming.  What is public, private and protected derivation?                                           (8)

       

             b.   Explain the meaning of polymorphism.  Describe how polymorphism is accomplished in C++ taking a suitable example?                                 (8)

 

  Q.3           Define a class Fraction whose objects represent rational numbers (i.e. fractions).  Include integer data members num and den for storing the numerator and denominator respectively. 

                  

             a.   Write the following functions for traction:

(i)                  parameterised constructors with one and two arguments.

(ii)                copy constructors.

(iii)               a function, eval-fract() for evaluating the value of the rational number.

(iv)              a function, invert() for inverting the given rational number.               

 

             b.   Overload >> and << operators for reading and printing the fraction object from the keyboard.                                                                   (2+8+6)

 

  Q.4     a.   What do you mean by static variable and static function?  Give an example?                       (5)

 

             b.   Write a template function to find the maximum number from a template array of size N.                   (8)

 

             c.   Describe the basic characteristics object-oriented programming.                         (3)          

 

  Q.5     a.   What is meant by exceptions?  How an exception is handled in C++?  Explain with the help of an example.                                                            (4)

            

             b.   What do you mean by operator overloading?  How unary and binary operators are implemented using the member and friend functions?               (8)

 

             c.   Explain the importance of using friend function in operator overloading with the help of an example.                                                            (4)                                                             

 

  Q.6           Define a class Date with three variables for day, month and year

       

             a.   Write the default and parameterised constructors,

             b.   Overload the operators <<,>> to read and print Date object,

c.       Overload > to compare two dates.

d.      Write the destructor that sets values to zero for all three variables.  Define object of the class in main and call the above defined functions.                 (2+2+3+3+4+2)

 

  Q.7     a.   Define the class Student which has name (char name[20]) and age(int).  Define the default constructor, member functions get_data() for taking the name and age of the Student, print() for displaying the data of Student.                                               (5)

            

             b.   For the above defined class create an array of students of size N and write the friend function sort(Student arr[N]) which sorts the array of Students according to their age.                                         (6)

 

             c.   Create a file namely “STUDENT.DAT” for storing the above objects in sorted order.                     (5)

 

Q.8             Consider a publishing company that markets both book and audio cassette version to its works.  Create a class Publication that stores the title (a string) and price(type float) of a publication.  Derive the following two classes from the above Publication class: Book which adds a page count (int) and Tape which adds a playing time in minutes(float).  Each class should have get_data() function to get its data from the user at the keyboard.

                   Write the main() function to test the Book and Tape classes by creating instances of them asking the user to fill in data with get_data() and then displaying it using put_data().                                        (16)

 

  Q.9           Write short notes on the following:

 

(v)                Nested class.

(vi)              Scope resolution operator.

(vii)             this pointer.

(viii)           Early binding and Late binding.                                         (4*4=16)