We are Permanently Move to www.VUpk.net Please Join us there.

CS201 Final Term paper Solved 2009 - 6

Saturday 4 August 2012
FINALTERM  EXAMINATION
Fall 2009
CS201- Introduction to Programming
Time: 120 min
M a r k s: 75
 
Question No: 1      ( M a r k s: 1 ) http://vuzs.net
 In C/C++ if we define an array of size eight (8) i.e. int Arr [8]; then the last element of this array will be stored at,
 
       ► Arr[0]
       ► Arr[8]
       ► Arr[7]
       ► Arr[-1]
 
Question No: 2      ( M a r k s: 1 ) http://vuzs.net
 When an array is passed to a function then default way of passing this array is,
 
       ► By data
       ► By reference
       ► By value
       ► By data type
 
Question No: 3      ( M a r k s: 1 ) http://vuzs.net
 Array is a data structure which store
 
      ► Memory addresses
      ► Variables
      ► Data Type
      ► Data
 
Question No: 4      ( M a r k s: 1 ) http://vuzs.net
 We can also create an array of user define data type.
 
       ► True
       ► False
 
Question No: 5      ( M a r k s: 1 ) http://vuzs.net
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: 6      ( M a r k s: 1 ) http://vuzs.net
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
 
Question No: 7      ( M a r k s: 1 ) http://vuzs.net
We can delete an array of objects without specifying [] brackets if a class is not doing dynamic memory allocation internally.
 
       ► True
       ► False
 
Question No: 8      ( M a r k s: 1 ) http://vuzs.net
The second parameter of operator functions for are objects of the class for which we are overloading these operators.
 
       ► True
       ► False
 
Question No: 9      ( M a r k s: 1 ) http://vuzs.net
 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 ;
 
Question No: 10      ( M a r k s: 1 ) http://vuzs.net
 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: 11      ( M a r k s: 1 ) http://vuzs.net
 What does STL stand for?
 
       ► Source template library
       ► Standard template library
       ► Stream template library
       ► Standard temporary library
 
Question No: 12      ( M a r k s: 1 ) http://vuzs.net
 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
 
Question No: 13      ( M a r k s: 1 ) http://vuzs.net
 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: 14      ( M a r k s: 1 ) http://vuzs.net
 new and delete are _____ whereas malloc and free are _____.
 
       ► Functions, operators
       ► Classes, operators
       ► Operators, functions
       ► Operators, classes
 
Question No: 15      ( M a r k s: 1 ) http://vuzs.net
 Friend functions are _____ of a class.
 
       ► Member functions
       ► Public member functions
       ► Private member functions
       ► Non-member functions
 
Question No: 16      ( M a r k s: 1 ) http://vuzs.net
 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: 17      ( M a r k s: 1 ) http://vuzs.net
 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

Question No: 18      ( M a r k s: 1 ) http://vuzs.net
 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) ;
 
Question No: 19      ( M a r k s: 1 ) http://vuzs.net
 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
 
Question No: 20      ( M a r k s: 1 ) http://vuzs.net
 We can also do conditional compilation with preprocessor directives.
 
      ► True
      ► False

Question No: 21      ( M a r k s: 1 ) http://vuzs.net
 The programs, in which we allocate static memory, run essentially on ________
 
       ► Heap
       ► System Cache
       ► None of the given options
       ► Stack

Question No: 22      ( M a r k s: 1 ) http://vuzs.net
 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.
 
Question No: 23      ( M a r k s: 1 ) http://vuzs.net
 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: 24      ( M a r k s: 1 ) http://vuzs.net
 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
 
Question No: 25      ( M a r k s: 1 ) http://vuzs.net
 With user-defined data type variables (Objects), self assignment can produce __________.
 
       ► Syntax error
       ► Logical error
       ► Link error
       ► Non of the given options
 
Question No: 26      ( M a r k s: 1 ) http://vuzs.net
 Assignment operator is used to initialize a newly declared object from existing object.
 
       ► True
       ► False
 
Question No: 27      ( M a r k s: 1 ) http://vuzs.net
 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
 
Question No: 28      ( M a r k s: 1 ) http://vuzs.net
 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      ( M a r k s: 1 ) http://vuzs.net
 new operator allocates memory from free store and return _____________.
 
       ► A pointer
       ► A reference
       ► An integer
       ► A float
 
Question No: 30      ( M a r k s: 1 ) http://vuzs.net
 "new" and "delete" keywords are _____________ in C++ language.
 
       ► Built-in- Function
       ► Operators
       ► Memory Allocation Function
       ► None of  the given options
 
Question No: 31      ( M a r k s: 1 )
 What is a constructor in class?
 
Answer:
 
Constructors are used to create, and can initialize, objects of their class type.
The name of this function is same as the name of the class, having no return type.
This is in the public section of our class.
If we do not write a constructor, C++ writes a default constructor for us.
 
Question No: 32      ( M a r k s: 1 )
What are the two types of conversion for user-defined data types?
 
Answer:
  • Conversion by constructor
  • Constructor by operator
 
Question No: 33      ( M a r k s: 2 )
Is there a way to increase the size of already allocated memory chunk ? Can the same chunk be increased or not?
 
Answer:
#include
main()
{
            char *ptr;
            ptr=(char*)malloc(20*sizeof(char));
            realloc(ptr,25*sizeof(char));
 
/*        
            char *ptr1;
            ptr1=new char[20];
            delete ptr1;
            ptr1=new char[25];
            system("pause");
*/
}
Question No: 34      ( M a r k s: 2 )
 Give the general syntax of class template.
 
Answer:
 
template // T is generic data type
class class-name
{
            //class definition;
};
 
 
Question No: 35      ( M a r k s: 3 )
What is the difference between structure and class? 
Answer:
 
In C++ structures are very similar to classes except the default visibility i-e default visibility in structure is public and private in classes
 
Question No: 36      ( M a r k s: 3 )
How many arguments does binary member operator function and binary non-member operator function take?
 
Answer:
 
member function with one parameter
 
and
 
 non-member function with two parameters.
 
Question No: 37      ( M a r k s: 3 )
Find the error in the given code  
for ( int i=0; i
{
for(int j=0; j
{
elements[i , j] = m.elements[i][j];       
}
}
 
Answer:
 
elements[i , j] should be elements[i] [ j]
 
 
Question No: 38      ( M a r k s: 5 )
Write the C++ syntax for making a class friend of other class.
 
Answer:
 
friend class Y;
 
or
 
class myclass
{
friend class otherClass;
}
 
Question No: 39      ( M a r k s: 5 )
What is a template function? Give the general syntax of writing a template function.
 
template // T is generic data type
class my-class-name
{
            //class definition;
};
 
template
class name :: functionname(argument list)
{
            //function body;
};
 
Question No: 40      ( M a r k s: 10 )
Write a program which contains a class student. The class should contain two char pointer variablesName, 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.
 
 
 
#include
class student
{
            private:
                        char Name[100];
                        char department[100];
            public:
                        student()
                        {
                                    cout << "object created" <
                        }
                        void setname()
                        {
                                    cout << "name ?" <
                                    cin >> Name;
                        }
                        void setdepartment()
                        {
                                    cout << "dep name ?" << endl;
                                    cin >> department;
                        }
                        friend ostream & operator << (ostream &  , student );
};
ostream & operator << (ostream & out , student s)
{
            cout << s.Name << endl;
            cout << s.department << endl;
            return out;
}
main()
{
            student a,b;
            a.setname();
            a.setdepartment();
           
            b.setname();
            b.setdepartment();
            cout << a <
            cout << b <
            system("pause");
}
Question No: 41      ( M a r k s: 10 )
What is Standard Template Library (STL) also describe its advantages?

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...