Sunday, June 5, 2011

CS201 Final Term Past Solved Paper 2


FINALTERM  EXAMINATION
Spring 2010
CS201- Introduction to Programming
Ref No: 1557656
Time: 90 min
Marks: 58
Student Info
Student ID:


Center:


Exam Date:




For Teacher's Use Only
Q No.
1
2
3
4
5
6
7
8
Total
Marks
      
      
      
      
      
      
      
      
      
Q No.
9
10
11
12
13
14
15
16

Marks
      
      
      
      
      
      
      
      
      
Q No.
17
18
19
20
21
22
23
24

Marks
      
      
      
      
      
      
      
      
      
Q No.
25
26
27
28
29
30
31
32

Marks
      
      
      
      
      
      
      
      
      
Q No.
33
34
35
36





Marks
      
      
      
      
      
      
      
      
      





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______.

       *

       +
+

       @

       #



Question No: 3    http://vustudents.ning.com  ( 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. http://vustudents.ning.com



       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     http://vustudents.ning.com ( 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. http://vustudents.ning.com

       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 _______ http://vustudents.ning.com



       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. http://vustudents.ning.com



       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. http://vustudents.ning.com







       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:
Syntax of class template:

template <class T>
 class class-name()
{
 definition of class
};




Question No: 28      ( Marks: 2 )
 

What is difference between endl and \n?

Answer:
The difference between endl and  \n is that endl  is use to start a new line for the next row
And \n is a new line character.



Question No: 29      ( Marks: 2 )
 

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

Answer:
This pointer is use to points to the current object in programming.

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);
       Function call:
      Function ; Function definition: Integer; Function declaration: Num1
       and Num2


2.      int func(int, int);
         Function call:
        Function ; Function definition: Integer; Function declaration: integers
       

3.      func(5, 6) ;
    
      Function call:
      Function ; Function definition: numbers; Function declaration: 5&6


4.      int func(int num1, int num2){}
       Function call:
       Function ; Function definition: Integer; Function declaration: Num1 and Num2 from   
       user


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 ;
}




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, we cannot define two functions as func(intx, inty) func(int &x, int&y) because it’s give an error function not initializing.

Question No: 33      ( Marks: 3 )
 

What happens when we use new and delete operator?

Answer:
When we use new operator to create objects the memory space is allocated for the object and then its constructor is called. Similarly, when we use delete operator with our objects, the destructor is called for the object before deallocating the storage to the object.






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:
Operator<<'s first parameter must be an ostream passed by reference. Its second parameter, the IntList that is printed, does not have to be passed as a const-reference parameter; however it is more efficient to pass it by reference than by value (since that avoids a call to the copy constructor), and it should not be modified by operator<<, so it should be a const reference parameter


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

Answer:
In this code the matrix function is defined, it get the number of rows from the user and create the row of matrix and then get the columns from the user and create the columns. The New is showing for creating more array space for the data which user enters. The elements [i][j] will print the data in matrix form. http://vustudents.ning.com

1 comment:

Contact Form

Name

Email *

Message *