PROMOTE MY BLOG: JUST CLICK BELOW BUTTON

Search Any Paper On This Blog

Saturday, December 4, 2010

CS304- Object Oriented Programming Solved Past Papers

MIDTERM  EXAMINATION
Spring 2010
CS304- Object Oriented Programming (Session - 3)

   
Question No: 1    ( Marks: 1 )    - Please choose one
Which one of the following terms best represents the statement given below,
” Hiding details of an object from the other parts of a program”

       ► Obfustication.       ► Data Mining.       ► Compilation.       ► Encapsulation
   
Question No: 2    ( Marks: 1 )    - Please choose one
By default, which  access level is assigned to members of a class?
       ► Public       ► Private       ► Local       ► protected

   
Question No: 3    ( Marks: 1 )    - Please choose one
Which one of the following features of OOP is used to deal with only relevant details?
       ► Abstraction       ► Information hiding       ► Object       ► Inheritance
   
Question No: 4    ( Marks: 1 )    - Please choose one
Which is true about specialization in case of inheritance?
       ► In specialization derived class has some restricted behavior of its own.
       ► In specialization derived class shows some extended behavior of its parent.
       ► In specialization derived class should be abstract.
       ► None of the given.
   
Question No: 5    ( Marks: 1 )    - Please choose one
By default all members of a class are,
       ► Public       ► Protected       ► Private       ► Public & protected
   
Question No: 6    ( Marks: 1 )    - Please choose one
   Which construct is the source for the creation of an object?
       ► Destructor of the class
       ► New operator
       ► Delete operator
       ► Constructor of the class
   
Question No: 7    ( Marks: 1 )    - Please choose one
Which of the following is an example of accessor function?
       ► constructor for intilizing objects       ► getter for getting data member values
       ► destructor to free the memory space       ► none of the given
Question No: 8    ( Marks: 1 )    - Please choose one
What will be the value of the variable data and data2 respectively on calling function given below 4th time in a single execution of program?
void func()
{
static int data = 4;
int data2 = 4;
++data;
++data2;

}

       ► 8, 5       ► 5, 8       ► 5, 5       ► 7, 5
   
Question No: 9    ( Marks: 1 )    - Please choose one
If a static variable is not explicitly initialized at the time of its definition then,
       ► The compiler will give an error message               ► The compiler will give a warning message
       The compiler will initialize it with value Zero.       ► None of the given
   
Question No: 10    ( Marks: 1 )    - Please choose one
this pointer does not point to current object of any class,
       ► True       ► False
Question No: 11    ( Marks: 1 )    - Please choose one
Consider the call given below of an overloaded operator "+",
Rational_number_1 + Rational_number_2
Where Rational_number_1 and Rational_number_2 are the two objects of Rational_number class (a user defined class). Identify which of the above two objects will be passed as an argument to the overloaded operator function?



       ► Rational_number_1       ► Rational_number_2
       ► Both Rational_number_1 & Rational_number_2       ► any of the two objects, randomly
   
Question No: 12    ( Marks: 1 )    - Please choose one
Which of the following operators can not be overloaded?
       ► Scope resolution  operator ( :: )       ► Insertion operator ( << )
       ► Extraction operator ( >> )       ► The relation operator ( > )
   
Question No: 13    ( Marks: 1 )    - Please choose one
Identify which of the following overloaded operator function’s declaration is appropriate for the given call?
Rational_number_1 + 2.325
Where Rational_number_1 is an object of user defined class Rational_number.
       ► Rational_number operator+( Rational_number & obj);
       ► Rational_number operator+(double& obj);
       Rational_number operator+(Rational_number &obj, double& num);
       ► operator+(double& obj);
Question No: 14    ( Marks: 1 )    - Please choose one
To convert from a user-defined class to a basic type, you would most likely use
       ► a built-in conversion operator.        ► a one-argument constructor.
       ► an overloaded = operator.        a conversion operator that’s a member of the class.
   
Question No: 15    ( Marks: 1 )    - Please choose one
Destructor can be overloaded
       ► True       ► False
   
Question No: 16    ( Marks: 1 )    - Please choose one
For more than one member in initializer list, then we use ________ to separate them

       ► Dot (.)       ► Comma (,)       ► Colon (:)       ► Semicolon (;)
   
Question No: 17    ( Marks: 2 )
Explain two benefits of getter functions.
Ans:

1.Getter function provide an interface to retrieve data from nay object
2.prevent the user to change the value of object.

   
Question No: 18    ( Marks: 2 )
Write a statement that a member function can use to return the entire object of which it is a member, without creating any temporary objects.

    Ans:
we can write:-
  Int MyInt(3);
so we can treat int as having a constructor that takes a single argument that is an int. Although this notation isn't normally used like that it is often used in constructors. We could write:-

  Track::Track(Float_t mass, Float_t energy) {
    fMass = mass;
    SetEnergy(energy);
  }
as:-

  Track::Track(Float_t mass, Float_t energy): fMass(mass) {
    SetEnergy(energy);
  }
the assignment has become an initialization. The colon after the argument list signals this construction. If more than one variable is initialized like this they must be separated by commas. Although the syntax is not exactly intuitive, it does allow the compiler to optimize the code.
Question No: 19    ( Marks: 2 )
Tell the two ways to indicate the compiler that we are overloading post increment operator.

Ans:

Int x=1, y=1;
1. Cout <<++x;
2. ++x=y

    uestion No: 20    ( Marks: 3 )
What are binary operators? Give an example of binary operators overloading using any class.

Ans:
Binary operator works on two quantities. Following are the examples of binary operators

+, -, *, /
following is the example of binary operator overloading for a member function of a class.


TYPE class_name:operator_symbol(TYPE rhs)
{
/* Code
}
Question No: 21    ( Marks: 3 )
Consider the class given below you have to overload stream insertion (<<) and stream extraction operators (>>) for this class.
class Circle{
           
    int x,y;
    int radius;
   
public:
    Circle(int a, int b, int c): x(a),y(b),radius(c){}
   
     friend ostream & operator << (ostream & os, const Circle & c);
     friend istream & operator >> (istream & os, Circle & c);
           
};
   
Question No: 22    ( Marks: 5 )
Write any two advantage(s) of declaring a member function as const?

Ans:

  1. A member function that does not affect the state of an object (its instance variables) is to be declared const.
  1. If the behavior of an object is dependent on data outside the object, this data is not to be modified by const member functions.
  2. Member functions declared as const may not modify member data and are the only functions which may be invoked on a const object. (Such an object is clearly unusable without const methods). A const declaration is an excellent insurance that objects will not be modified (mutated) when they should not be. A great advantage that is provided by C++ is the ability to overload functions with respect to their const-ness. (Two member functions may have the same name where one is const and the other is not).
Some functions in our programs are general purpose functions to show or access
data, they are supposed to do read only tasks only however there are chances that
they can change the state of data members of the class while accessing the data
members due to programming mistake, c++ provides the solution of this problem
using constant member functions.
We make those functions as constant who need only read only access (for example
such functions that will only display data or will return the value of data members).
When we make them constant compiler generates an error if these functions try to
change the value of data members of the class.
www.allvupastpapers.blogspot.com

No comments:

Post a Comment

PLEASE COMMENT ABOUT YOUR VISIT AND MY SITE

Note: Only a member of this blog may post a comment.