Code: AC-11 / AT-22                                   Subject: OBJECT ORIENTED PROGRAMMING Flowchart: Alternate Process: JUNE 2007

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.       What will be the values of x, m and n after the execution of the following statements?

int x, m, n;

m = 10;                                                

n = 15;            

x = ++m  +  n++;

 

                   (A)  x=25, m=10, n=15                       (B)  x=26, m=11, n=16

(C)    x=27, m=11, n=16                      (D)  x=27, m=10, n=15                                       

 

b.      Which of the following will produce a value 10 if x = 9.7?

                                                                                                                              

                   (A)  floor(x)                                         (B)  abs(x)

(C)  log(x)                                           (D)  ceil(x)                                                           

 

             c.   The major goal of inheritance in c++ is:

                  

(A)    To facilitate the conversion of data types.

(B)    To help modular programming.

(C)    To extend the capabilities of a class.

(D)    To hide the details of base class.

 

             d.   Consider the following class definitions:

                   class a

                   {

                   };

                   class b: protected a

                   {

                   };

                   What happens when we try to compile this class?

(A)   Will not compile because class body of a is not defined.

(B)   Will not compile because class body of b is not defined.

(C) Will not compile because class a is not public inherited.

(D) Will compile successfully.

                                                         

             e.   Which of the following expressions is illegal?

 

(A)     .                                         (B)  (false && true)

(C)  bool (x) = (bool)10;                     (D)  float y = 12.67;          

             f.    The actual source code for implementing a template function is created when

 

(A)     The declaration of function appears.

(B)     The function is invoked.

(C)     The definition of the function appears.            

(D)    None of the above.

 

             g.   An exception is caused by

 

(A)     a runtime error.                           

(B)     a syntax error.

(C)  a problem in the operating system.

(C)     a hardware problem.

 

             h.   Which of the following statements are true in c++?

 

(A)    Classes can not have data as public members.

(B)    Structures can not have functions as members.

(C)    Class members are public by default. 

(D)    None of these.

 

             i.    What would be the output of the following program?

                   int main()

                   {

                   int x,y=10,z=10;

                   x = (y = =z);

                   cout<<x;

                   return 0;

                   }

(A)   1                                                  (B)  0

(C) 10                                                 (D) Error

       

             j.    What is the error in the following code?

                   class t

                   {

                   virtual void print();

                   }

 

(A)    No error.                                    

(B)    Function print() should be declared as static.

(C)  Function print() should be defined.     

(D)  Class t should contain data members.

 

 

 

Answer any FIVE Questions out of EIGHT Questions.

Each question carries 16 marks.

 

  Q.2     a.   What are the benefits of object oriented programming?  Explain.                         (8)

                  

             b.   Explain Inline functions and the situations where inline expansion may not work and why?                (8)

       

  Q.3     a.   What is a constructor?  What are the restrictions applied to them?  Explain Copy constructor with one example.                                                                                                            (8)

 

             b.   What is the output of following codes:

                   (i)  void main()

                        {

                         int a[] = {10,20,30,40,50};

                         int i;

                         for (i=0;i<5;i++)                           

                         {

                         cout<<”\nelement is “<<*(i+a)<<” “<<*(a+i)<<” “<<i[a]<<” “<<a[i];

                         }                                                  

                         }

 

                   (ii)  void main()

                         {

                         char *ptr = “xyzw”;

                         char ch;

                         ch = ++ *ptr ++;

                         cout <<ch;

                         cout << ch++;

                         }                                                                                                             (4+4)                      

                  

  Q.4     a.   Write a C++ program using classes and objects to simulate result preparation system for 20 students.                                                                    (8)

                   The data available for each student includes:

                   Name (includes first, mid and last name each of size 20 characters),

                   Rollno,

                   Marks in 3 subjects.

                   The percentage marks and grade are to be calculated from the following information          

                              Percentage marks                        grade

                                    <50                                          ‘F’

                                    50<60                                   ‘D’

                                    60<75                                   ‘C’

                                    75<90                                   ‘B’

                                    90<100                                 ‘A’                                          

 

             b.   Is it possible that a function is friend of two different classes?  If yes, then how it is implemented in C++.                                                                (8)

 

  Q.5     a.   Write a program to overload << and >> operator to I/O the object of a class.                    (8)

            

             b.   What is the difference between a virtual function and a pure virtual function?  Give example of each.                                                                       (8)

 

  Q.6     a.   Write a program for Conversion from Basic to Class Type.                                 (8)

         

             b.   How is polymorphism achieved at (i)  compile time and (ii)  run time?                  (8)

                  

  Q.7     a.   When do we make a class virtual?  Explain with an example.                               (8)

                                                                                                                                                

             b.   How does inheritance influence the working of constructor and destructor?

                   Given the following set of definitions

 

                   Class x                                                                                                                                                                                           {

                   };

                   class y: public x

                   {

                   };

                   class z: public y

                   {

                   };

                   z obj;

                   What order will the constructor and destructor be invoked?                                (8)

                    

Q.8       a.   Define a stream.  What are the three streams used for inputting, outputting and both for inputting and outputting?                                           (6)

 

             b.   Write a program to create a database of the students information such as name, roll no and the program should have the following facilities.        (10)

(i)                  Adds a new records to the file.

(ii)                Modifies the details of an record.

(iii)               Displays the contents of the file.                                                     

                  

  Q.9     a.   Write a function template for sorting a list of arrays.                                            (8)

 

             b.   Write a program to read three numbers x, y and z and evaluate R given by

                  

      Use exception handling to throw an exception in case division by zero is

      attempted.                                                                                                         (8)