We are Permanently Move to vupk.net Please Join us there.

CS201 Final Term Solved paper 2009 - 3

FINAL TERM EXAMINATION
Spring 2009

CS201- Introduction to Programming

Question No: 1                    ( Marks: 1 ) - Please choose one
When we define an array of objects then,
· Destructor will call once for whole array
· Destructor will call for each object of the array
· Destructor will never call
· Depends on the size of array
 
Question No: 2                    ( Marks: 1 ) - Please choose one
We can also create an array of user define data type
· True
· False
 
Question No: 3                   ( Marks: 1 ) - Please choose one
What is the sequence of event(s) when allocating memory using new operator?
· Only block of memory is allocated for objects
· Only constructor is called for objects
· Memory is allocated first before calling constructor
· Constructor is called first before allocating memory
If a single object is allocated, operator new is called to allocate memory, and then the constructor is called to initialize the object.
·   If an array of objects is allocated, operator new[] is called to allocate memory for the whole array, and then the constructor is called for each element of the array.
·   When a single object is deleted, the destructor for the object is called first, and then operator delete is called to free the memory occupied by the object.
· When an array of objects is deleted, the destructor for each element of the array object is called first, and then operator delete[] is called to free the memory occupied by the array.

Question No: 4                    ( Marks: 1 ) - Please choose one
We can delete an array of objects without specifying [] brackets if a class is not doing dynamic memory allocation internally
· True
· False
Although, this is good to deallocate an array of objects without specifying array operator ([]) as there is no dynamic memory allocation occurring from inside the Date class. But this is a bad practice.
 
Question No: 5                   ( Marks: 1 ) - Please choose one
The declarator of Plus (+) member operator function is
·   Class-Name  operator + (Class-Name  rhs)
·   Operator Class-Name + ( )
·   Operator Class-Name + ( rhs)
· Class-Name  operator + ( )
Page 371,373 example are here
Complex operator + (Complex & );
Complex operator + (parameter-list);
The syntax of the prototype of the overloaded operator function is:
return-type operator operator-symbol (parameter-list);
operator is the keyword here. An example of this will be as follows:
Complex operator + (Complex & );
 
Question No: 6                   ( 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 (not sure)
· False

Question No: 7                   ( Marks: 1 ) - Please choose one
Which  of  the  following  is  correct  way  to  initialize  a  variable  x  of  int  type  with value 10?
· int x ; x = 10 ;
· int x = 10 ;
· int x, x = 10;
· x = 10 ;
variable already created in question only it is asking for initialization.
 
Question No: 8                    ( Marks: 1 ) - Please choose one
Default mechanism of function calling in case of array is                              and in case of variable is _              
· Call by value, call by reference
· Call by referene, call by reference
· Call by reference, call by value
· Call by value, call by value
 
Question No: 9                    ( Marks: 1 ) - Please choose one
What does STL stand for?
· Source template library
· Standard template library
· Stream template library
· Standard temporary library
STL stands for Standard Template Library
Question No: 10                    ( Marks: 1 ) - Please choose one
Skill(s) that is/are needed by programmers                                                                    
· Paying attention to detail
· Think about the reusability
· Think about user interface
· All of the given options
Programming is an important activity as people life and living depends on the programs one make. Hence while programming one should
o Paying attention to detail
o Think about the reusability.
o Think about user interface
o Understand the fact the computers are stupid
o Comment the code liberally

Question No: 11                    ( Marks: 1 ) - Please choose one
For which array, the size of the array should be one more than the number of elements in an array?
· int
· double
· float
· char

Question No: 12                  ( Marks: 1 )     - Please choose one
new and delete are                            whereas malloc and free are              
· Functions, operators
· Classes, operators
· Operators, functions
· Operators, classes
new and delete are operators in c++
C functions like malloc() and free() functions can also be used from within C++ code
 
Question No: 13                    ( Marks: 1 ) - Please choose one
The prototype of friend functions must be written                             the class and its definition
must be written                        
· inside, inside the class
· inside, outside the class
· outside, inside the class
· outside, outside the class
 
Question No: 14                    ( Marks: 1 ) - Please choose one
Friend function of a class are                                  of a class.
· Non-member functions not sure
· Friend functions
· Any function outside class
· None of the given options

Question No: 15                    ( Marks: 1 ) - Please choose one
If overloaded plus operator is implemented as non-member function then which
of the following statement will be true for the statement given below?
obj3 = obj1 + obj2 ;
· obj2 will be passed as an argument to + operator whereas obj2 will drive the + operator
· obj1 will drive the + operator whereas obj2 will be passed as an argument
to + operator
· Both objects (obj1, obj2) will be passed as arguments to the + operator
· Any of the objects (obj1, obj2) can drive the + operator
 c3 = c1 + c2 ; In the above statement ( c3 = c1 + c2; ), c1 is the object that is calling or driving the + operator. c2 object is being passed as an argument to the + operator. So c1 and c2 objects are added by the + operator and resultant
 
Question No: 16                    ( Marks: 1 ) - Please choose one
Which  one  of  the  following  is  the  declaration  of  overloaded  pre-increment operator implemented as member function?
· Class-name operator +() ;
· Class-name operator +(int) ;
· Class-name operator ++() ;
· Class-name operator ++(int) ;
Overloading Unary Operators
// Preincrement operator overloaded as a member function.
Date Date::operator++()
{
   helpIncrement();
   return *this;  // value return; not a reference return
}
 
// Postincrement operator overloaded as a member function.
// Note that the dummy integer parameter does not have a
// parameter name.
Date Date::operator++(int)
{
   Date temp = *this;
   helpIncrement();
 
   // return non-incremented, saved, temporary object
   return temp;   // value return; not a reference return
}
 
Question No: 17                    ( Marks: 1 ) - Please choose one
For cin, the source is normally a                                    and destination can be               
· File, native data type
· Disk, user-define type
· Keyboard, variable
· File, user-define type
For cin, the source is normally keyboard and the destination can be an ordinary variable i.e. native-data type variable. It could be some area of memory or our own data type, i.e. object for which we h
Question No: 18                    ( Marks: 1 ) - Please choose one
We can do condition compilation with pre processor directives.
· True
· False
All the preprocessor directives start with the sharp sign (#). We can also do conditional compilation with it.
Question No: 19                    ( Marks: 1 ) - Please choose one
 
The programs, in which we allocate static memory, run essentially on                                      
· Heap
· System Cache
· None of the given options
· Stack
The programs, in which we allocate static memory, run essentially on stack
Question No: 20                    ( Marks: 1 ) - Please choose one
A template function must have at least ---------- or more arguments
 
· Zero
· One
· Two
· Three
The function arguments must contain at least one generic data type. Normal function declaration is: return_type function_name(argument_list)
Question No: 21                    ( Marks: 1 ) - Please choose one
The default value of a parameter can be provided inside the                                                      
· function prototype
· function definition
· both function prototype or function definition
· none of the given options
The default value of a parameter is provided inside the function prototype or function definition.
Question No: 22                    ( 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
 
While calling function, the arguments are assigned to the parameters from left to right.
 
Question No: 23                    ( Marks: 1 ) - Please choose one
When an operator function is defined as member function for a binary Plus (+)
operator then the number of argument it take is/are
 
· Zero
· One
· Two
· N arguments
Operators as member functions
Aside from the operators which must be members, operators may be overloaded as member or non-member functions. The choice of whether or not to overload as a member is up to the programmer. Operators are generally overloaded as members when they:
change the left-hand operand, or
1.         require direct access to the non-public parts of an object.
When an operator is defined as a member, the number of explicit parameters is reduced by one, as the calling object is implicitly supplied as an operand. Thus, binary operators take one explicit parameter and unary operators none. In the case of binary operators, the left hand operand is the calling object, and no type coercion will be done upon it. 
 
Question No: 24                    ( Marks: 1 ) - Please choose one
new operator allocates memory from free store and return                                               
· A pointer
· A reference
· An integer
· A float
new Operator (C++)
Allocates memory for an object or array of objects of type-name from the free store and returns a suitably typed, nonzero pointer to the objec
 
Question No: 25                    ( Marks: 1 ) - Please choose one
With                   user-defined    data    type    variables    (Objects),     self    assignment     can produce        
 
· Syntax error not sure
· Logical error
· Link error
· Non of the given options
 
Question No: 26                    ( Marks: 1 ) Write Simple Program
Assignment operator is used to initialize a newly declared object from existing object
·                                               True
·                                                False

Question No: 27                    ( Marks: 1 ) Briefly define/Justify
When an object of a class is defined inside an other class then,
· Constructor of enclosing class will be called first
· Constructor of inner object will be called first
· Constructor and Destructor will be called simultaneously
· None of the given options
A class can contain instances of other classes as its data members. • It is a way of reusing the code when we contain objects of our already written classes into a new class.
 • The inner data members of the object are constructed and then the object itself.
The order of destruction of an object is reverse to this construction order, where the outer object is destroyed first before the inner data members.
 • Initializer list is used to initialize the inner objects at the construction time.
 • In C++, we can have structures or classes defined inside classes. Classes defined within other classes are called nested classes.
Question No: 28                    ( Marks: 1 ) Brief answer required
In the member initializer list, the data members are initialized,
· From left to right
· From right to left
· In the order in which they are defined within class
· None of the given options
 
Question No: 29                    ( Marks: 1) - Brief answer required
"new" and "delete" keywords are                                              in C++ language
· Built-in- Function
· Operators
· Memory Allocation Function
· None of the given options

Question No: 30                    ( Marks: 2 ) - Brief answer required
What are the two types of conversion for user-defined data types?
There are two types of conversion: implicit and explicit.
Question No: 31                    ( Marks: 2 ) - Brief answer required
Give the general syntax of class template.
The syntax of the template class is
 template
class class-name()
{ definition of class };
Question No: 32                    ( Marks: 2 ) - Brief answer required
What is a constructor in class?
The name of this function is same as the name of the class,
 having no return type. This function is called constructor.
Question                 No:    33                       (    Marks:    2    )    -    Brief    answer    required
Is there a way to increase the size of already allocated memory chunk ? Can the same chunk be increased or not?
 
Can the same chunk be increased or not? The answer is yes. we can reallocate the same memory with a new size according to our requirement. The function that reallocates the memory is realloc.
 
 
Question No: 34                    ( Marks: 3 ) - Write Program
What is the difference between structure and class?.
The ONLY DIFFERENCES between classes and structures are
1)  classes DEFAULT to having private members.  Structures DEFAULT to having public members. These defaults can be changed so classes can be made to work like structures and vice versa.

2)  classes DEFAULT to inheriting privately from base classes.  Structures DEFAULT to inheriting public from base classes. These defaults can be changed so classes can be made to work like structures and vice versa
.
 
Question No: 35                    ( Marks: 3 ) - Write Program
How  many  arguments  does  binary  member  operator  function  and  binary  non- member operator function take?
When an operator function is defined as member function for a binary Plus (+)
operator then the number of argument it take is/are
 
Question No: 36                    ( Marks: 2 ) - Write Program
Find the error in the given code for ( int i=0; imRows; i++)
{
for(int j=0; jumCols; j++)
{
elements[i , j] = m.elements[i][j];
}
}
 
Question No: 37                   ( Marks: 5 ) - Write Program
Write the C++ syntax for making a class friend of other class
Question No: 38                   ( Marks: 5 ) - Write Program
What  is  a  template  function?  Give  the  general  syntax  of  writing  a  template function
Question No: 39                   ( Marks: 10 ) - Write Program
What is Standard Template Library (STL) also describe its advantages?
 The standard template library is the collection of functions of very common use. Their every day use is so important that two researchers wrote a whole library of these functions. This library is a part of the official standard of C++. It is called STL i.e. Standard Template Library. As a library, it is a tested code base. Some one has written, tested and compiled for the ultimate use of programmers. We can use these templates and can implement different concepts for our own data types. Equally is true about the use of the array data type. Our code will become very small with the use of this tested facility. Similarly, there is no bug or error in it. Thus, if we have a tested and tried code base, we should try our best to write programs by using it. STL is a lot of important code, pre-developed for us. It is available as a library. We can write programs by using it. Thus our programs will be small and error free
Question No: 40                    ( Marks: 10 ) - Write Program
Write  a  program  which  contains  a  class  student The  class  should  contain  two char  pointer  variables  Name,  and  department The  class  should  further  contain constructors,  overload  the  stream insertion  operator  (<<)  for  this  class  In  main function create two objects and display these objects vuzs
#includestream>
#includenio>
#include stdlib> using namespace std; class student {
private:
char name[30] ;
char department[30] ;
public:

0 comments:

Post a Comment