DECEMBER 2006

 

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

Time: 3 Hours                                                                                                     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.       If there is a pointer p to object of a base class and it contains the address of an object of a derived class and both classes contain a virtual member function abc(), then the statement p->abc(); will cause the version of abc() in the __________class to be executed.

 

                   (A)  Base Class                                   (B)  Derived class

(C)    Produces compile time error        (D)  produces runtime error                                  

 

b.      A pure virtual function is a virtual function that

                                                                   

                   (A)  has no body                                 (B)  returns nothing

(C)  is used in base class                      (D)  both (A) and (C)                                           

 

             c.   A static function

                  

(A)    should be called when an object is destroyed.

(B)    is closely connected with and individual object of a class.

(C)    can be called using the class name and function name.

(D)    is used when a dummy object must be created.

 

             d.   We can output text to an object of class ostream using the insertion operator<< becuase

 

(A)   the ostream class is a stream       

(B)   the insertion operator works with all classes.

(C) we are actually outputting to cout.

(D)  the insertion operator is overloaded in ostream.

                                                         

             e.   The statement f1.write((char*)&obj1, sizeof(obj1));          

 

(A)     writes the member function of obj1 to f1.      

(B)     Writes the data in obj1 to f1.

(C)     Writes the member function and the data of obj1 to f1.          

(D)    Writes the address of obj1 to f1.

 

 

 

 

 

             f.    To convert from a user defined class to a basic type, you would most likely use.

 

(A)     A built-in conversion function.      

(B)     A one-argument constructor.

(C)     A conversion function that’s a member of the class.    

(D)    An overloaded ‘=‘ operator.

 

             g.   Which of the following is not the characteristic of constructor.

 

(A)     They should be declared in the public section.

(B)     They do not have return type.

(C)     They can not be inherited.

(D)    They can be virtual.

 

             h.   Name the header file to be included for the use of built in function isalnum()

 

(A)    string.h                                         (B) process.h

(C) ctype.h                                          (D) dos.h

 

             i.    What is the output of given code fragment?

                   int f=1, i=2;

                   while(++i<5)

                   f*=i;

                   cout<<f;

 

(A)   12                                                (B)  24

(C) 6                                                   (D) 3

       

             j.    A class defined within another class is:

 

(A)  Nested class                                 (B)  Inheritance

(C)  Containership                               (D)  Encapsulation

 

 

Answer any FIVE Questions out of EIGHT Questions.

Each question carries 16 marks.

 

  Q.2     a.   Define the following terms related to Object Oriented Paradigm:

                   Encapsulation, Inheritance, Polymorphism, Data Abstraction                             (12)

       

             b.   Identify the errors in the following code fragment                                                 (4)

                                  ...

                   char ch; int vowels = 0, others = 0;

                   cout<<”enter character”;

                   while((ch>=’a’ &&ch<=z) (ch>=A && ch<=Z))

                   {

                   switch(ch)

                   {

                   case a:case A:case e:case E:case I:case I:case e:case O:case u:case U:++vowels:

                          break;

                   default:++others;

                   }}

                   cout<<”vowels are:”<<vowels;

                   cout<<”others are:”<<others;

                   ….

 

  Q.3     a.   Declare a class to represent bank account of customers with the following data members:Name of the depositor, Account number, Type of account(S for saving and C for Current), balance amount. The class also contains member functions to do the following:

 

                   (i) To initialise the data member (ii) To deposit money (iii) To withdraw money after checking the balance (minimum balance is Rs.1000) (iv) To display the data members.                                        (6)

 

             b.   How is the working of member function different from friend function and a non member function?                                                            (6)

 

             c.   Explain a pure virtual function with an example.                                                   (4)

 

  Q.4     a.   Discuss the various situations when a copy constructor is automatically invoked.                 (6)

 

             b.   How many times is the copy constructor called in the following code?                 (4)

                  

                   Apple func(Apple u)

                   {

                   Apple w=v;

                   Return w;

                   }

                   void main()

                   {

                   Apple x;

                   Apple y = func (x);

                   Apple z = func (y);

                   }

 

             c.   What are the advantages and disadvantages of inline functions?                           (6)          

 

  Q.5     a.   Define Rules for operator Overloading. Write a program to overload the subscript operator ‘[ ]’.                                                               (8)

            

             b.   How is a class converted into another class? Explain with one example.               (8)

 

  Q.6     a.   How does visibility mode control the access of members in the derived class? Explain with an example.                                                                  (6)

         

             b.   What is run time polymorphism? How it is achieved? Explain with an  

                   example?                                                                                                           (4)

 

 

 

 

             c.  Define a class loan with Principle, Period and Rate as data members. Incr (float) is a member function, which increases the rate of interest by the parameter value. If rate of interest is same for all loans, use appropriate declarations and implement the class.    (6)

 

  Q.7     a.   Write a program having a base class Student with data member rollno and member functions getnum() to input rollno and putnum() to display rollno.

                     A class Test is derived from class Student with data member marks and member functions getmarks() to input marks and putmarks() to display marks. Class Sports is also derived from class Student with data member score and member functions getscore() to input score and putscore() to display score. The class Result is inherited from two base classes, class Test and class Sports with data member total and a member function display() to display rollno, marks, score and the total(marks + score).  (12)

            

             b.   What will be the result of following expressions when they are executed in sequence?                      (4)

                                                                                                                                                                                           …

                   …

                   int a = 10;

                   int b = 20;

                   c = ++a     +    ++a   +  ++a;

                   b=b++       +    b++;

                   e=a++       +   --a       + b--;

                   f=b--  & ++a  +  b++;

                   cout<<c<<d<<e<<f;

                   …

                   …

  

Q.8       a.   What are generic classes? Why are they useful? Explain with an example how these are implemented in c++.                                                                                                                         (8)

 

             b.   Explain the following functions(with example) for manipulating file pointers:

                   seekg(),seekp(),tellg(),tellp().                                                                             (8)

 

  Q.9           Explain the following:

 

(i)                  Stream class hierarchy.

(ii)                Exception handling.

(iii)               Virtual class

(iv)              Abstract class                                                                  (4*4=16)