FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming
Ref No:
Time: 90 min
Marks: 58
Question No: 1 ( Marks: 1 ) - Please choose one
*.doc is _____________ by type.
.
► Sequential File
► Random Access File
► Data File
► Record File
Question No: 2 ( Marks: 1 ) - Please choose one
Which of the following is NOT a preprocessor directive?
► #error
► #define
► #line
► #ndefine
Question No: 3 ( Marks: 1 ) - Please choose one
The return type of operator function must always be void.
► True
► False
Question No: 4 ( Marks: 1 ) - Please choose one
What does (*this) represents?
By : Adeel Abbas
► The current function of the class
► The current pointer of the class
► The current object of the class
► A value of the data member
Question No: 5 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 7 ( Marks: 1 ) - Please choose one
► void (nothing)
► void pointer
► object pointer
► int pointer
Question No: 8 ( 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: 9 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 10 ( Marks: 1 ) - Please choose one
► #include “iostream.h”
► include <iostream.h>
► include <iostream.h>
► #include <iostream.h>
Question No: 11 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 12 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 13 ( Marks: 1 ) - Please choose one
What will be the correct syntax to assign an array named arr of 5 elements to a pointer ptr? By : Adeel Abbas
► *ptr = arr ;
► ptr = arr ;
► *ptr = arr[5] ;
► ptr = arr[5] ;
Question No: 14 ( Marks: 1 ) - Please choose one
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
Question No: 15 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 16 ( Marks: 1 ) - Please choose one
By : Adeel Abbas
► Address of variable, reference variable
► Reference variable, value of variable
► Reference variable, address of variable
► Address of variable, value of variable
Question No: 17 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 18 ( Marks: 1 ) - Please choose one
► function prototype
► function definition
► both function prototype or function definition
► none of the given options.
Question No: 19 ( Marks: 1 ) - Please choose one
► looped
► nested
► overloaded
► none of the given options.
Question No: 20 ( Marks: 1 ) - Please choose one
► Data encapsulation
► Providing a convenient way of modeling real-world objects
► Simplifying code reuse
► All of the given options
Question No: 21 ( Marks: 1 ) - Please choose one
► Constructor
► Destructor
► Both a constructor and a destructor
► None of the given options
Question No: 22 ( Marks: 1 ) - Please choose one
► Compile Time
► Run Time
► Link Time
► None of the given options
Question No: 23 ( Marks: 1 ) - Please choose one
► 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 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 25 ( Marks: 1 ) - Please choose one
► Class, Objects
► Structures, Pointers
► Both Class and structures
► None of above
Question No: 26 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 27 ( Marks: 2 )
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 ( Marks: 2 )
Ans:
Modulus operator
This operator can only be used with integer operands ONLY
Question No: 29 ( Marks: 2 )
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.
By : Adeel Abbas
Question No: 30 ( Marks: 2 )
Ans:
int matrix [3] [3] ;
matrix [0] [0] = 0;
matrix [0] [1] = 0;
matrix [0] [2] = 0;
matrix [1] [0] = 0;
matrix [1] [2] = 0;
matrix [1] [2] = 0;
matrix [2] [0] = 0;
matrix [2] [1] = 0;
matrix [2] [2] = 0;
we can also do it as given below
int matrix [3][3] = { 0 }; //all elements 0
Question No: 31 ( Marks: 3 )
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 ( Marks: 3 )
template <class T>
T reciprocal(T x)
{
return (1/x);
}
T reciprocal(T x)
{
return (1/x);
}
Ans:
1/5
Question No: 33 ( Marks: 3 )
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 ( Marks: 5 )
Ans:
#include <iostream>
#include <iomanip>
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;
By : Adeel Abbas
return 0;
}
Question No: 35 ( Marks: 5 )
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 ( Marks: 5 )
Write the declaration and definition of operator function to overload + operator for the statements of main function.
math obj1, obj2;
obj2= 10 + obj1 ;
#include <iostream.h>
math
{
mth operator + (obj1,obj2)
mth operator + (obj1,obj2)
{
mth operator + (obj1,obj2)
mth operator + (obj1,obj2)
}
}
…………………………………………………………………………
By ADEEL ABBAS, Bhakkar. AdeelAbbasbk@gmail.com
No comments:
Post a Comment
PLEASE COMMENT ABOUT YOUR VISIT AND MY SITE
Note: Only a member of this blog may post a comment.