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

CS201 Final term Solved Paper 2010 - 3

Friday 3 August 2012
FINALTERM  EXAMINATION
Spring 2010
CS201- Introduction to Programming
Shared by Zeehan
Checked by zubair hussain (MCQs)
vuZs Team
M a r k s: 58
Question No: 1      ( M a r k s: 1 ) 
*.doc is _____________ by type.
.
       Sequential File
       Random Access File
       Data File
       Record File
Question No: 2      ( M a r k s: 1 ) http://vuzs.net
Which of the following is NOT a preprocessor directive?
       #error
       #define
       #line
       #ndefine
Question No: 3      ( M a r k s: 1 ) http://vuzs.net
The return type of operator function must always be void.
       True
       False
The syntax of the prototype of the overloaded operator function is: return-type operator operator-symbol (parameter-list);
Question No: 4      ( M a r k s: 1 ) http://vuzs.net
What does (*this) represents?
       The current function of the class
       The current pointer of the class
       The current object of the class
       A value of the data member
Whenever an object calls a member function, the function implicitly gets a pointer from the calling object. That pointer is known as this pointer. ‘this’ is a key word. We cannot use it as a variable name. ‘this’ pointer is present in the function, referring to the calling object. For example, if we have to refer a member, let’s say buf, of our String class, we can write it simply as: buf ;
 
Question No: 5      ( M a r k s: 1 ) 
The statement cin.get (); is used to,
       Read a string from keyboard
       Read a character from keyboard
       Read a string from file
       Read a character from file

Question No: 6      ( M a r k s: 1 )
 When we do dynamic memory allocation in the constructor of a class, then it is necessary to provide a destructor.
       True
       False
Question No: 7      ( M a r k s: 1 ) 
 Overloaded new operator function takes parameter of type size_t and returns
       void (nothing)
       void pointer
       object pointer
       int pointer
Question No: 8      ( M a r k s: 1 ) http://vuzs.net
The second parameter of operator functions for << and >> are objects of the class for which we are overloading these operators.
       True
       False
The second parameter to operator << is an object of the class that we are overloading the operator for. Similar is the case for operator >>.
 
Question No: 9      ( M a r k s: 1 ) http://vuzs.net
 C++ is a case-sensitive language
       True
       False
Question No: 10      ( M a r k s: 1 ) http://vuzs.net
 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
       include
       #include
Question No: 11      ( M a r k s: 1 ) http://vuzs.net
 A template function must have only generic data types.
       True
       False
Its not compulsory, only min we have one generic data type but we can have native data type as well.
 
Question No: 12      ( M a r k s: 1 ) http://vuzs.net
 Template class can not have static variables.
       True
       False
Question No: 13      ( M a r k s: 1 ) http://vuzs.net
What will be the correct syntax to assign an array named arr of 5 elements to a pointer ptr?
       *ptr = arr ; 
       ptr = arr ;
       *ptr = arr[5] ;
       ptr = arr[5] ; 
Question No: 14      ( M a r k s: 1 ) http://vuzs.net
What will be the correct syntax to access the value of fourth element of an array using pointer ptr?
       ptr[3]
       (ptr+3)
       *(ptr+3)
       Both 1and 3
try this demo program to confirm result I wrote for you.
2 option will print the reference rest 1,3 are righ options

#include
 #include
// #include
 
main()
{
int myarr [4]= {0,1,2,3};
int *ptr ;
ptr = myarr;
cout<
cout<<*(ptr+3);
cout<<(ptr+3);
int i = 0;
cin>> i;
}
 
Question No: 15      ( M a r k s: 1 ) http://vuzs.net
 If most significant bit of un-signed number is 1 then it represents a positive number.
       True
       ► False
The most significant bit is used as a sign bit. If this bit is zero, the number is considered positive. However, if it is 1, the number will be considered negative.
Question No: 16      ( M a r k s: 1 ) http://vuzs.net
 If there is a symbol (& sign) used with the variable name followed by data type then it refers to _____ and if & is being used with variable name then it refers to _____.
       Address of variable, reference variable
       Reference variable, value of variable
       Reference variable, address of variable
       Address of variable, value of variable
we see a data type followed by & sign, it’s a reference. And when the & sign is being used in the code with a variable name then it is the address of the variable
Question No: 17      ( M a r k s: 1 ) http://vuzs.net
 We can also do conditional compilation with preprocessor directives.
       True
       False
Question No: 18      ( 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.
The default value of a parameter is provided inside the function prototype or function definition.
Question No: 19      ( M a r k s: 1 ) http://vuzs.net
 Classes defined inside other classes are called ________ classes
       looped
       nested
       overloaded
       none of the given options.
Question No: 20      ( M a r k s: 1 ) http://vuzs.net
 What purpose do classes serve?
       Data encapsulation
       Providing a convenient way of modeling real-world objects
       Simplifying code reuse
       All of the given options
Question No: 21      ( M a r k s: 1 ) http://vuzs.net
vuzs
 Every class contains _______________.
       Constructor
       Destructor
       ► Both a constructor and a destructor
       None of the given options
Question No: 22      ( M a r k s: 1 ) http://vuzs.net
 new operator is used to allocate memory from the free store during
       Compile Time
       Run Time
       Link Time
       None of the given options
Question No: 23      ( M a r k s: 1 ) http://vuzs.net
 When an object of a class is defined inside another class then,
      Destructor of enclosing class will be called first
  Destructor of inner object will be called first
       Constructor and Destructor will be called simultaneously
       None of the given options
Question No: 24      ( M a r k s: 1 ) http://vuzs.net
 It is possible to define a class within another class.
       True
       False
Question No: 25      ( M a r k s: 1 ) http://vuzs.net
 New and Delete are also used with ___________ and data types as well.
       Class, Objects
       Structures, Pointers
       Both Class and structures
       None of above
we prefer to use new and delete operators as they are designed to work with classes and objects
Question No: 26      ( M a r k s: 1 ) http://vuzs.net
 With New keyword, data types and class members are initialized with meaningful values instead of garbage.

       True
       False
Question No: 27      ( M a r k s: 2 )
 How many arguments a Unary Operator take? Can we make a binary operator as unary operator?
Ans: Unary operator takes only one aurgument like i++ or i— (Post increment or post decrement operators for intergers) or ++i,--i  (Pre increment or pre decrement operators for intergers) ,we can not make Unary operator as binary or binary as Unary operator.
Question No: 28      ( M a r k s: 2 )
 Which arithmetic operators cannot have a floating point operand?
Ans:
Modulus operator
This operator can only be used with integer operands ONLY
Question No: 29      ( M a r k s: 2 )
 What are manipulators? Give one example.
Ans:
The manipulators are like something that can be inserted into stream, effecting a change in the behavior. For example, if we have a floating point number, say pi (Š»), and have written it as float pi = 3.1415926 ; Now there is need of printing the value of pi up to two decimal places i.e. 3.14 . This is a formatting functionality. For this, we have a manipulator that tells about width and number of decimal points of a number being printed.
Some manipulators are parameter less. We simply use the name of the manipulator that works. For example, we have been using endl, which is actually a manipulator, not data. When we write cout << endl ; a new line is output besides flushing the buffer. Actually, it manipulates the output stream.
Question No: 30      ( M a r k s: 2 )
 Write down piece of code that will declare a matrix of 3x3. And initialize all its locations with 0;
Ans:
int matrix [3] [3] ;
 
include<iostream.h>
 
 
main () {
    int matrix [3][3];
    int anyvalue = 12
  
    for (int a=0;a<3;a++)
    { for (int b = 0;b<3;b++)
   { matrix[a][b]= anyvalue;
    cout<<matrix[a][b]<<endl;}}
    int i=0;
    cin>>i;
}
Question No: 31      ( M a r k s: 3 )
 Which one (copy constructor or assignment operator) will be called in each of the following code segment?
1) Matrix m1 (m2);
2) Matrix m1, m2;
m1 = m2;
3) Matrix m1 = m2;
Ans:
1) Matrix m1 (m2);   copy constructor
2) Matrix m1, m2;   
m1 = m2;              assignment operator
3) Matrix m1 = m2;  assignment operator
Question No: 32      ( M a r k s: 3 )
 What will be the output of following function if we call this function by passing int 5?
template T reciprocal(T x) {return (1/x); }
Ans:
1/5
Question No: 33      ( M a r k s: 3 )
 Identify the errors in the following member operator function and also correct them.
math * operator(math m);
math * operator (math m)
{
     math temp;
     temp.number= number * number;
     return number;
   
}
ANS:
The errors are in the arguments of the member operation function and also in the body of operator member function.
Correct function should be
math *operator(math *m);
math *operator (math *m)
{
     math temp;
     temp = m;
     temp.number= number * number;
     return temp.number;
   
}
 
Question No: 34      ( M a r k s: 5 )
 Write a program which defines three variables of type double which store three different values including decimal points, using setprecision manipulators to print all these values with different number of digits after the decimal number.
Ans:
#include
#include
int main ()
{
  double x1 = 12345624.72345
double x2 =  987654.12345
double x3 =  1985.23456
  cout << setprecision (3) << x1<< endl;
  cout << setprecision (4) << x2 << endl;
cout << setprecision (5) << x3<< endl;
  return 0;
}
Question No: 35      ( M a r k s: 5 )
 What are the advantages and disadvantages of using templates?
Ans:
Many thing can be possible without using templates but it do offer several clear advantages not offered by any other techniques:
Advanatages:
 • Templates are easier to write than writing several versions of your similar code for different types. You create only one generic version of your class or function instead of manually creating specializations.
• Templates are type-safe. This is because the types that templates act upon are known at compile time, so the compiler can perform type checking before errors occur.
 • Templates can be easier to understand, since they can provide a straightforward way of abstracting type information.
• It help in utilizing compiler optimizations to the extreme. Then of course there is room for misuse of the templates. On one hand they provide an excellent mechanism to create specific type-safe classes from a generic definition with little overhead.
Disadvantages:
On the other hand, if misused
• Templates can make code difficult to read and follow depending upon coding style.
• They can present seriously confusing syntactical problems esp. when the code is large and spread over several header and source files.
 • Then, there are times, when templates can "excellently" produce nearly meaningless compiler errors thus requiring extra care to enforce syntactical and other design constraints. A common mistake is the angle bracket problem.
Question No: 36      ( M a r k s: 5 )
 Suppose a program has a math class having only one data member number.
Write the declaration and definition of operator function to overload + operator for the statements of main function.
         math obj1, obj2;
         obj2= 10 + obj1  ;  
Ans:
#include
math
{
mth operator + (obj1,obj2)
mth operator + (obj1,obj2)
{
 mth operator + (obj1,obj2)
mth operator + (obj1,obj2)
}
}

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...