Thursday, July 14, 2011

[ vuZs.net ] CS201 Final Term Solved 3 Please check

FINALTERM  EXAMINATION

Spring 2010

 

 

Question No: 1      ( Marks: 1 ) - Please choose one

 Pointer is a variable which store,

 

       ► Data

       ► Memory Address

       ► Data Type

       ► Values

 

Question No: 2      ( Marks: 1 ) - Please choose one

 All preprocessor directives are started with the symbol______.

 

       ► *

       ► +

       ► @

       ► # ………Ans

 

Question No: 3      ( Marks: 1 ) - Please choose one

 Within the statement obj1=obj2;   obj1 will call the assignment operator function and obj2 will be passed as an argument to function.

 

       ► True

       ► False

 

Question No: 4      ( Marks: 1 ) - Please choose one

 What is the sequence of event(s) when deallocating memory using delete operator?

 

       ► Only block of memory is deallocated for objects

       ► Only destructor is called for objects

       ► Memory is deallocated first before calling destructor

       ► Destructor is called first before deallocating memory

 

Question No: 5      ( Marks: 1 ) - Please choose one

The second parameter of operator functions for << and >> are objects of the class for which we are overloading these operators.

 

      ► True

      ► False


Question No: 6      ( Marks: 1 ) - Please choose one

 To include code from the library in the program, such as iostream, a directive would be called up using this command.

 

       ► #include "iostream.h"

       ► include <iostream.h>

       ► include <iostream.h>

       ► #include <iostream.h>

 

Question No: 7      ( Marks: 1 ) - Please choose one

 The number 544.53 must be stored in _____ data type.

 

       ► int

       ► short

       ► float

       ► char

 

Question No: 8      ( Marks: 1 ) - Please choose one

 A template function can have different type of arguments.

 

      ► True

      ► False

 

Question No: 9      ( Marks: 1 ) - Please choose one

 For which values of the integer _value will the following code becomes an infinite loop?

 

int number=1;

while (true) {

            cout << number;

            if (number == 3) break;

            number +=  integer_value; }

 

       ► any number other than 1 or 2

       ► only 0

       ► only 1

       ► only 2


Question No: 10      ( Marks: 1 ) - Please choose one

Template class cannot have static variables.

 

       ► True

       ► False

 

Question No: 11      ( Marks: 1 ) - Please choose one

 Which of the following is used with bit manipulation?

 

       ► Signed integer

       ► Un-signed integer

       ► Signed double

       ► Un-signed double

 

Question No: 12      ( Marks: 1 ) - Please choose one

 Structure is a collection of ______________ under a single name.

 

       ► Only Functions

       ► Only Variables

       ► Both Functions and Variables

       ► None of the given options

 

Question No: 13      ( Marks: 1 ) - Please choose one

 Which of the following is the correct C++ syntax to allocate space dynamically for an array of 10 int?

 

       ► new int(10) ;

       ► new int[10] ;

       ► int new(10) ;

       ► int new[10];

 

Question No: 14      ( Marks: 1 ) - Please choose one

 Unary operator implemented as member function takes ____ arguments whereas non-member function takes _____ arguments.

 

       ► One, zero

       ► Zero, one

       ► One, two

       ► Two, one

 

Question No: 15      ( Marks: 1 ) - Please choose one

 The first parameter of overloaded stream insertion operator is _________ where second parameter is _______

 

       ► input stream, object of class

       ► object of class, output stream

       ► output stream, object of class

       ► object of class, input stream

 

Question No: 16      ( Marks: 1 ) - Please choose one

 We can also do conditional compilation with preprocessor directives.

 

       ► True

       ► False


Question No: 17      ( Marks: 1 ) - Please choose one

 If a symbolic constant has been defined, it will be an error to define it again.

 

       ► True

       ► False


Question No: 18      ( Marks: 1 ) - Please choose one

 While calling function, the arguments are assigned to the parameters from _____________.

 

       ► left to right.

       ► right to left

       ► no specific order is followed

       ► none of the given options.


Question No: 19      ( Marks: 1 ) - Please choose one

 Classes defined inside other classes are called ________ classes

 

       ► looped

       ► nested

       ► overloaded

       ► none of the given options.


Question No: 20      ( Marks: 1 ) - Please choose one

 If we define an identifier with the statement #define PI 3.1415926 then during the execution of the program the value of PI __________.

 

       ► cannot be replaced

       ► None of the given options

       ► Remain constant.

       ► can be changed by some operation

 

Question No: 21      ( Marks: 1 ) - Please choose one

 Assignment operator is -------------------------associative.

 

       ► right

       ► left

       ► binary

       ► unary

 

Question No: 22      ( Marks: 1 ) - Please choose one

 If text is a pointer of class String then what is meant by the following statement?

text = new String [5];

 

       ► Creates an array of 5 string objects statically

       ► Creates an array of 5 string objects dynamically

       ► Creates an array of pointers to string

       ► Creates a string Object

 

Question No: 23      ( Marks: 1 ) - Please choose one

The return type of the operator function for << operator is __________.

 

       ► class for which we overload operator

       ► reference of ostream class (ostream&)

       ► reference of istream class (istream&)

       ► void

 

Question No: 24      ( Marks: 1 ) - Please choose one

 The code is written to __________ the program.

 

       ► implement

       ► design

       ► analysis

       ► none of the given options.


Question No: 25      ( Marks: 1 ) - Please choose one

 Memory allocated at run time is a system resource and it is the responsibility of _____ to de-allocate the memory.

 

       ► System

       ► Programmer

       ► User of program

       ► None of given options

 

Question No: 26      ( Marks: 1 ) - Please choose one

 Templates are not type safe.

 

      ► true

      ► false


Question No: 27      ( Marks: 2 )

 Give the general syntax of class template.

 

Answer:

 

template <class T> // T is generic data type

class class-name()

{

    //      class definition

};

 

Question No: 28      ( Marks: 2 )

 What is difference between endl and \n?

 

Answer:

 

endl ……..inserts new line and flush the stream

where as

\n inserts new line only

 

 

 

Question No: 29      ( Marks: 2 )

 What is the this pointer? Give an example of its use.

 

Answer:

 

This pointer points to the current object. This pointer is implicitly available to every member fuction.

 

 

Question No: 30      ( Marks: 2 )

 Identify each of the following as function call, function definition and function declaration.

 

1.      int func(int num1, int num2);

 

            Answer: Function declaration

 

2.      int func(int, int);

        

           Answer: Function declaration

 

3.      func(5, 6) ;

    

      Answer: Function call

 

4.      int func(int num1, int num2){}

   

    Answer: Function definition

 

 

Question No: 31      ( Marks: 3 )

 Consider the following code segment. What will be the output of the following code segment?

 

class class1{

public:

class class2{

public:

class2()

{

cout << "Calling default constructor of class2\n" ;

}

};

class1(){

cout << "Calling default constructor of class1\n" ;

}

} ;

main(){

class1::class2 obj1;

class1 obj2 ;

}

 

Answer:

Calling default constructor of class2

Calling default constructor of class1

 

Question No: 32      ( Marks: 3 )

 

Is it possible to define two functions as given below? Justify your answer.

func(int x, int y)

func(int &x, int &y)

 

Answer:

 

no, this function overload is ambiguous because there is no way for complier to find out the way function is called. Both function calls are same.

 

Question No: 33      ( Marks: 3 )

What happens when we use new and delete operator?

 

Answer:

 

New operator

  • Determines the size of memory needed to store object
  • Calls the constructor of class
  • Returns pointer to the object

Delete operator:

  • Deletes the object
  • De-allocate the memory

 

Question No: 34      ( Marks: 5 )

What is the difference between function overloading and operator overloading? 

 

Answer:

Difference b/w function overloading and operator overloading is:

 

In function overloading, the functions have the same name but differ either by the number of arguments or the type of the arguments.

 

Operator overloading is to allow the same operator to be bound to more than one implementation, depending on the types of the operands.

 

 

Question No: 35      ( Marks: 5 )

Why the first parameter of operator function for << operator must be passed by reference?

 

Answer:

The first parameter of << is ostream and object cout is example of ostream object. This first parameter is always be passed by reference other complier will not allow you to do otherwise. The first object is returned back by reference. It is used for cascading. It cannot be passed by value. So only way is to pass by refence.

 

Question No: 36      ( Marks: 5 )

Read the given below code and explain what task is being performed by this function

 

Matrix :: Matrix ( int row , int col )

{

    numRows = row ;

    numCols = col ;

    elements = new ( double * ) [ numRows ] ;

    for ( int  i = 0 ; i < numRows ; i ++ )

            {

        elements [ i ] = new double [ numCols ] ;

        for ( int j = 0 ; j < numCols ; j ++ )

                elements [ i ] [ j ] = 0.0 ;

     }

}

 

 

 

Hint : This function belong to a matrix class, having

Number of Rows = numRows

Number of Columns = numCols

 

 

No comments:

Post a Comment