CS201 Solved Final Papers 249 Pages File
CS201 Solved Final Papers 249 Pages File
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
The syntax of the prototype of the overloaded operator function is: return-type operator
operator-symbol (parameter-list);
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, lets say buf, of our Stringclass, we
can write it simply as: buf ;
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
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 ( Marks: 1 ) - Please choose one
C++ is a case-sensitive language
True
False
Question No: 10 ( 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
include
#include
*ptr = arr[5] ;
ptr = arr[5] ;
#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 ( Marks: 1 ) - Please choose one
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.
we see a data type followed by & sign, its a reference. And when the & sign is being used
in the code with a variable name then it is the address of the variable
The default value of a parameter is provided inside the function prototype or function
definition.
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
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 ( Marks: 1 ) - Please choose one
Every class contains _______________.
Constructor
Destructor
Both a constructor and a destructor
None of the given options
Question No: 22 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
When an object of a class is defined inside another class then,
Destructor of enclosing class will be called first
we prefer to use new and delete operators as they are designed to work with classes and
objects
Question No: 26 ( Marks: 1 ) - Please choose one
With New keyword, data types and class members are initialized with meaningful values instead of garbage.
True
False
Question No: 27 ( Marks: 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 ( Marks: 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 ( Marks: 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 << class="Apple-convertedspace"> ; a new line is output besides flushing the buffer. Actually, it manipulates the output stream.
Question No: 30 ( Marks: 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] ;
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 )
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 ( Marks: 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 ( Marks: 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;
}
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)
}
}
FINALTERM EXAMINATION
Fall 2009
CS201- Introduction to Programming
Time: 120 min
Marks: 75
If we write a statement like s2 = s1; ___ will be the calling object and ____ will be passed to the =
operator as an argument.
s1, s1
s1, s2
s2, s1
s2, s2
0000128
0128128
1280000
0012800
The stream insertion and extraction operators are not already overloaded for _______
True
False
Overloaded new operator function takes parameter of type size_t and returns
void (nothing)
void pointer
object pointer
int pointer
Which of the following is the correct way to declare a variable x of integer type?
x int ;
integer x ;
int x;
x integer
True
False
One
Two
Three
True
False
True
False
We can also define a variable of user define data type (object) as static.
True
False
Class-Name operator + ( )
Let suppose
int a, b, c, d, e;
a = b = c = d = e = 42;
(a = b) = (c = d) = (e = 42);
What will be the range of numbers generated by function rand () % 9?
0 to 9
1 to 9
0 to 8
1 to 8
Which of the following is the correct function call having array named student of 10 elements as a
parameter.
addRecord(student[]) ;
addRecord(student) ;
addRecord(student[10]) ;
addRecord(*student) ;
True
False
Identifier is a name that can be given to variables, labels and functions.
True
False
If a class A declares itself a friend of class B and a class B declares itself a friend of class C then
Class A is also a friend of class C.
Class B is also a friend of class A.
Class A is also a friend of class C if A declares C as its friend.
Class A is also a friend of class C if C declares A as its friend.
Which of the following statement is best regarding declaration of friend function?
Friend function must be declared after public keyword.
Friend function must be declared after private keyword.
Friend function must be declared at the top within class definition.
It can be declared anywhere in class as these are not affected by the public and
private keywords.
Memory Address
Data values
Both Values and Memory
None of given of options
When memory for a program is allocated at run time then it is called ________
Destructor
Be a syntax error
Be a logical error
Not be an error at all
( Marks: 1 )
( Marks: 1 )
When memory is allocated dynamically using new operator within the constructor of class then what is an
appropriate place to de-allocate the memory?
( Marks: 2 )
What will be the output of following code, if user input a number 123?
int input ;
cin >> oct >> input;
cout << hex << input ;
( Marks: 2
( Marks: 3 )
When we call calloc function to allocate memory and its return a NULL pointer what does it mean?
( Marks: 3 )
( Marks: 3 )
What is the keyword this and what are the uses of this pointer?
( Marks: 5 )
What do you mean by garbage collection and how it works in JAVA and C++ ?
( Marks: 5 )
Explain the concept of separation of interface from the implementation in the context of classes, using a
real world example.
( Marks: 10 )
Write a simple program using the get() member function of cin object reading a text of 30 characters from
the keyboard, store them in an array and then using put() member function of cout object to display them
on the screen.
s( Marks: 10 )
Write a program which has a class List, This class should have Two data members, an array of integers
list[] and an integer variable length (i.e. number of elements in the list).The class should further contain a
default constructor, a Print() function which display the list and a Function insert() which insert an
element in the list and Assignment (= ) Operator function, which contain code for the assignment of one
object to other. .
In main function define two objects list1 and list2 and use the statement list2 = list1; and use (call ) print
function with both objects
MCQS of cs201
( eagle_eye )
[email protected]
.
Question # 1
What does 5 | 6 , evaluate to in decimal where | is bitwise OR operator?
1) :
2) :
3) :
4) :
Correct
Option
:
From :
Question # 2
We can also use member functions with cin and cout objects
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Question # 3
If the statements
int j,k;
j = 123;
k= 234;
int* q, * r;
cout < < *q < < ' ' < < * r ;
are executed, what will be displayed?
1) :
2) :
3) :
4) :
garbage values
Correct
Option
:
4
From :
Lecture 14
Question # 4
Which one of the following operators is a unary operator?
1) :
OR ( || )
2) :
AND ( &&)
3) :
XOR ( ^ )
4) :
Complement operator ( ~ )
Correct
Option
:
4
From :
Lecture 16
Question # 5
The statement i++; is equivalent to
1) :
i = i + i;
2) :
i = i + 1;
3) :
i = i - 1;
4) :
i --;
Correct
Option
:
2
From :
Lecture 16
Question # 6
A variable which is defined inside a function is called
1) :
Automatic variable
2) :
Global variable
3) :
Functional variable
4) :
Correct
Option
From :
Lecture 16
Question # 7
If we open a file stream myfile for reading, what will give us the current position of the file
pointer?
1) :
tellg()
2) :
tellp()
3) :
seekg()
4) :
seekp()
Correct
Option
:
1
From :
Lecture 19
Question # 8
Application Softwares are use to
1) :
Type letters
2) :
3) :
4) :
Develop Graphics
Correct
Option
:
3
From :
Lecture 2
Question # 9
When we write a class template the first line must be:
1) :
2) :
3) :
template < class T >, Here T can be replaced with any name but it is
preferable.
4) :
class template
Correct
Option
:
3
From :
Lecture 21
Question # 10
When a macro takes arguments then it is called_________________.
1) :
Function
2) :
Procedure
3) :
Parameterized macro
4) :
Simple macro
Correct
Option
:
3
From :
Lecture 23
Question # 11
By default an array of characters is passed by value to a function,
1) :
TRUE
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Lecture 23
Question # 12
Using dynamic memory is more efficient then the static memory.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 24
Question # 13
Using dynamic memory is more _____________ then the static memory.
1) :
Costly
2) :
Expansive
3) :
efficient
4) :
Difficult
Correct
Option
:
3
From :
Question # 14
Lecture 24
Before exiting the program, make sure that the allocated memory has freed.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 24
Question # 15
A preprocessor directive is identified by _________ symbol
1) :
2) :
3) :
4) :
##
Correct
Option
:
1
From :
Lecture 25
Question # 16
The default constructor has no arguments
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 26
Question # 17
The data members of the class are initialized at runtime
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 26
Question # 18
The data members of the class are initialized at creation Time
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Lecture 26
Question # 19
The function call to a default constructor
1) :
2) :
3) :
4) :
Correct
Option
:
4
From :
Lecture 26
Question # 20
A friend function of a class has access
1) :
2) :
3) :
4) :
Correct
Option
:
3
From :
Lecture 26
Question # 21
The new operator
1) :
2) :
3) :
4) :
Correct
Option
:
4
From :
Lecture 26
Question # 22
Explicitly write keyword private in the class definition
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 26
Question # 23
There is a class Student, Which one of the following is a valid destructor for this class.
1) :
Student();
2) :
~ Student();
3) :
~ Student(int);
4) :
int~ Student();
Correct
Option
:
2
From :
Lecture 27
Question # 24
The reserved words public and private comes under the category
1) :
structures
2) :
strings
3) :
accessibility modifiers
4) :
types of functions
Correct
Option
:
1
From :
Lecture 27
Question # 25
There is a class Student, Which one of the following is a valid destructor for this class.
1) :
Student();
2) :
Student(int);
3) :
~ Student();
4) :
~ Student(int);
Correct
Option
:
3
From :
Lecture 27
Question # 26
The function call to a default constructor
1) :
2) :
3) :
4) :
Correct
Option
:
2
From :
Lecture 27
Question # 27
The new operator
1) :
2) :
3) :
4) :
Correct
Option
:
4
From :
Lecture 28
Question # 28
The new operator
1) :
2) :
3) :
4) :
Correct
Option
From :
Lecture 28
Question # 29
Which of the following operators can not be overloaded?
1) :
new
2) :
delete
3) :
+=
4) :
sizeof
Correct
Option
:
2
From :
Lecture 28
Question # 30
Analyze the following code
class myclass
{
private:
float x,y;
public:
void myclass
(float a, float b)
{
x=a;
y=b;
}
void diplay()
{
cout<<ENDL<<X<<ENDL<<Y;
}
};
What is wrong with the above code?
1) :
2) :
3) :
4) :
Correct
Option
:
2
From :
Lecture 28
Question # 31
this is a pointer which always points to the current object.
1) :
TRUE
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 28
Question # 32
Which of the following is the correct C++ syntax to allocate space dynamically for an array
of 10 int?
1) :
new int(10) ;
2) :
new int[10] ;
3) :
int new(10) ;
4) :
int new[10];
Correct
Option
From :
Lecture 28
Question # 33
The function free() returns back the allocated memory got thorough calloc and malloc to
_____ .
1) :
stack
2) :
heap
3) :
4) :
Correct
Option
:
2
From :
Lecture 28
Question # 34
Whenever new operator is used, no number of bytes or sizeof operator is required.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 28
Question # 35
If the memory in the free store is not sufficient enough to fulfill the request, malloc()
True
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Lecture 28
Question # 36
A friend function
1) :
2) :
can access the private data of the class that declares it a friend
3) :
4) :
Correct
Option
:
2
From :
Lecture 29
Question # 37
A function declaration has the same relationship to a function definition that
1) :
2) :
3) :
4) :
Correct
Option
:
3
From :
Lecture 29
Question # 38
A friend function
1) :
2) :
3) :
4) :
can access the private data of the class that declares it a friend
Correct
Option
:
4
From :
Lecture 29
Question # 39
The reserved words public and private comes under the category
1) :
structures
2) :
strings
3) :
accessibility modifiers
4) :
types of functions
Correct
Option
:
3
From :
Lecture 29
Question # 40
The prototype of friend functions must be written ____ the class and its definition must be
written ____
1) :
2) :
3) :
4) :
Correct
Option
:
2
From :
Lecture 29
Question # 41
In functions that return reference, use __________variables.
1) :
Local
2) :
Global
3) :
Global or static
4) :
Correct
Option
:
3
From :
Lecture 30
Question # 42
Operator Overloading is quite similar to Function Overloading.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 30
Question # 43
There are two types of operators to overload: unary and binary.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 30
Question # 44
The declarator of Minus(-) member operator function is
1) :
2) :
operator Class-Name - ( )
3) :
4) :
Class-Name operator - ( )
Correct
Option
:
From :
Lecture 30
Question # 45
Operator functions written as non-members but friends of the class, get both the operands
as their arguments.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 30
Question # 46
We cannot do arithmetic with references like pointers.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 30
Question # 47
In functions that return reference, use global or static variables.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 30
Question # 48
In functions that return reference, use only static variables.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Lecture 30
Question # 49
The reference data types are used as ordinary variables without any dereference operator.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
From :
Lecture 30
Question # 50
Which of the following operators can not be overloaded?
1) :
new
2) :
delete
3) :
+=
4) :
sizeof
Correct
Option
:
3
From :
Lecture 31
Question # 51
The declarator of Plus (+) member operator function is
1) :
2) :
operator Class-Name + ( )
3) :
4) :
Class-Name operator + ( )
Correct
Option
:
1
From :
Lecture 31
Question # 52
We can create a new operator through operator overloading.
1) :
TRUE
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Lecture 31
Question # 53
In overloading the assignment (=) operator, which object will call the operator function?
1) :
2) :
3) :
4) :
Correct
Option
:
3
From :
Lecture 31
Question # 54
Which statement about operator overloading is false?
1) :
2) :
Certain overloaded operators can change the number of arguments they take.
3) :
4) :
Correct
Option
:
2
From :
Lecture 31
Question # 55
Initializing the data members in the definition of the class is ___________
1) :
syntax error
2) :
logical error
3) :
not an error
4) :
Correct
Option
:
2
From :
Lecture 31
Question # 56
When an array of object is created dynamically then there is no way to provide
parameterized constructors for array of objects.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
Question # 57
From :
Lecture 32
If we define an identifier with the statement #define PI 3.1415926 then during the
execution of the program the value of PI __________.
1) :
2) :
3) :
Remain constant.
4) :
Correct
Option
:
3
From :
Lecture 34
Question # 58
The default constructor is defined by the C++ compiler automatically for every class that
has no default constructor (parameterless constructor) defined already.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 36
Question # 59
The default constructor (parameterless constructor) is called for each element in the array
allocated with new.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 36
Question # 60
The new operator returns a Type *, accepts a parameter of type size_t.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Lecture 36
Question # 61
The new operator returns a void *, accepts a parameter of type size_t.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 36
Question # 62
The delete operator returns nothing (void) and accepts a pointer of void * to the memory
block.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 36
Question # 63
The delete operator returns nothing (void) and accepts a pointer of type * to the memory
block.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Lecture 36
Question # 64
By overloading new and delete operators, only allocation and deallocation part can be
overridden.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 36
Question # 65
new and delete can overload in c++
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Lecture 36
Question # 66
By overloading the array operator ( [] ), one can implement mechanism to check for array
bound.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 36
Question # 67
Stream insertion ( << ) and extraction operators ( >> ) are always implemented as
___________ functions.
1) :
Member
2) :
non-member
3) :
Inside
4) :
Out Side
Correct
Option
:
2
From :
Lecture 37
Question # 68
For operator >>, the second parameter must also be passed by reference.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
Question # 69
From :
Lecture 37
2) :
3) :
4) :
Correct
Option
:
4
From :
Lecture 38
Question # 70
A copy constructor
1) :
2) :
3) :
4) :
takes no arguments
Correct
Option
:
1
From :
Lecture 39
Question # 71
A copy constructor
1) :
takes no arguments
2) :
3) :
4) :
creates a new object that later may be assigned the data of an existing object
Correct
Option
:
3
From :
Lecture 39
Question # 72
A class can contain instances of other classes as its data members.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 40
Question # 73
The inner data members of the object are constructed and then the object itself.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 40
Question # 74
The order of destruction of an object is equle to this construction order, where the outer
object is destroyed first before the inner data members.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Lecture 40
Question # 75
Initializer list is used to initialize the inner objects at the construction time.
1) :
True
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 40
Question # 76
In C++, we can have structures or classes defined inside classes. Classes defined within
other classes are called ________ classes.
1) :
nested
2) :
Child
3) :
Parent
4) :
Branch
Correct
Option
:
1
From :
Lecture 40
Question # 77
Static member functions
1) :
2) :
3) :
4) :
Correct
Option
:
4
From :
Lecture 41
Question # 78
The template functions do NOT promote the code reuse
1) :
TRUE
2) :
FALSE
3) :
4) :
Correct
Option
From :
Lecture 41
Question # 79
In the member initializer list, the data members are initialized,
1) :
2) :
3) :
4) :
Correct
Option
:
3
From :
Lecture 41
Question # 80
It is possible to define a class within another class.
1) :
TRUE
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 41
Question # 81
When ever dynamic memory allocation is made in C/C++, it is freed_____________.
1) :
Explicitly
2) :
Implicitly
3) :
4) :
Correct
Option
:
1
From :
Lecture 42
Question # 82
User-defined manipulators are allowed in c++.
1) :
TRUE
2) :
FALSE
3) :
4) :
Correct
Option
:
1
From :
Lecture 42
Question # 83
It is a way of reusing the code when we contain objects of our already written classes into
a new class,
1) :
TRUE
2) :
False
3) :
4) :
Correct
Option
:
1
From :
Lecture 42
Question # 84
Structured Query Language is used for ______________
1) :
Databases Management
2) :
Networks
3) :
4) :
Correct
Option
:
1
From :
Lecture 45
Question # 85
In if structure the block of statements is executed only,
1) :
Type letters
2) :
3) :
4) :
Correct
Option
:
4
From :
Question # 86
Lecture 6
Loader transfers the executable code from main memory to hard disk.
1) :
TRUE
2) :
FALSE
3) :
4) :
Correct
Option
:
2
From :
Lecture 6
Question # 87
When break statement is encountered in switch statement, it
1) :
2) :
3) :
4) :
Correct
Option
:
3
From :
Lecture 7
Copyright Eagle_eye
Powered By: Group of Virtual's Experts
www.virtualinspire.com
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming
Ref No:
Time: 90 min
Question No: 1
Question No: 2
Question No: 3
Question No: 4
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
Overloaded new operator function takes parameter of type size_t and returns
void (nothing)
void pointer
object pointer
int pointer
Question No: 8
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
is a case-sensitive language
True
False
Question No: 10
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: 11
A
template function must have only generic data types.
True
False
Question No: 12
True
False
Question No: 13
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
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
Question No: 16
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 _____.
Question No: 19
Question No: 20
Question No: 21
Question No: 22
Question No: 23
Question No: 25
and Delete are also used with ___________ and data types as well.
Class, Objects
Structures, Pointers
Both Class and structures
None of above
Question No: 26
With
New keyword, data types and class members are initialized with meaningful values instead of garbage.
True
False
Question No: 27
( Marks: 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
( Marks: 2 )
( 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.
Question No: 30
( Marks: 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] ;
Question No: 31
( Marks: 3 )
Which one (copy constructor or assignment operator) will be called in each of the following code
segment?
1)
Matrix m1 (m2);
2)
3)
Matrix m1 = m2;
Ans:
1)
2)
3)
assignment operator
Question No: 32
( Marks: 3 )
What will be the output of following function if we call this function by passing int 5?
Ans:
1/5
Question No: 33
( Marks: 3 )
Identify the errors in the following member operator function and also correct them.
math * operator(math m);
}
ANS:
The errors are in the arguments of the member operation function and also in the body of operator
member function.
Question No: 34
( Marks: 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 <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;
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 )
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 <iostream.h>
math
{
mth operator + (obj1,obj2)
mth operator + (obj1,obj2)
{
mth operator + (obj1,obj2)
mth operator + (obj1,obj2)
}
}
www.virtualinspire.com
Spring 2010
CS201- Introduction to Programming
Time: 90 min
Marks: 58
Student Info
Student ID:
Center:
Exam Date:
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Total
Question No: 1
Question No: 2
Dealing with structures and functions passing by reference is the most economical method
True
False
Question No: 3
True
False
Question No: 4
Overloaded new operator function takes parameter of type size_t and returns
void (nothing)
void pointer
object pointer
int pointer
Question No: 5
When new operator is overloaded at global level then corresponding built-in new operator will not be
visible to whole of the program.
True
False
Question No: 6
If there is more than one statement in the block of a for loop, which of the following must be placed at
the beginning and the ending of the loop block?
parentheses ( )
braces { }
brackets [ ]
Question No: 7
The return type of a function that do not return any value must be ________
float
int
void
double
Question No: 8
JAVA
FORTRAN
Question No: 9
Like member functions, ______ can also access the private data members of a class.
Non-member functions
Friend functions
Question No: 10
It can be declared anywhere in class as these are not affected by the public and private keywords.
Question No: 11
Question No: 12
Functions
Operators
Manipulators
Objects
Question No: 13
True
False
Question No: 14
cast
cost
const
Question No: 15
True
False
Question No: 16
Which of the following function call is correct for the function prototype?
defaultParameters ( int a, int b = 7, char z = * );
defaultParameters (5);
Question No: 17
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: 18
True
False
Question No: 19
Question No: 20
The appropriate data type to store the number of rows and colums of the matrix is____________.
float
int
char
Question No: 21
data type
memory referee
value
Question No: 22
Decremented
Incremented
Multiplied
Question No: 23
NULL value has been defined in ______ and _________ header files.
Question No: 24
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this ,
_______________
Use templates
Question No: 25
Question No: 26
Question No: 27
( Marks: 2 )
Suppose there is a template function func having argument of type U and return type T. What will be
the C++ syntax to call this function, passing a variable x of type double and returning an int type?
http://vuattach.ning.com/
Question No: 28
( Marks: 2 )
Which variable will be used in inner code block if we have the same names of variable at outer code
block and inner code block?
Question No: 29
( Marks: 2 )
Question No: 30
( Marks: 2 )
Write the C++ code for the declaration of overloaded stream insertion and stream extraction operator
for the object d of type Date.
Question No: 31
( Marks: 3 )
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Question No: 32
( Marks: 3 )
If the requested memory is not available in the system then what does calloc/malloc and new operator
return?
Question No: 33
( Marks: 3 )
Question No: 34
( Marks: 5 )
What is difference between Unary and binary operators and how they can be overloaded?
Question No: 35
( Marks: 5 )
class Matrix
{
private:
int Elements[3][3];
};
Write the operator function of stream extraction operator (>>) for this class.
Question No: 36
( Marks: 5 )
What is meant by user interface and class interface in C++ ? And what role a class interface can play in
user interface [Marks 5] http://vuattach.ning.com/
FINALTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming
Question No: 1
Two
Three
Four
Five
Question No: 2
When x = 7; then the expression x%= 2; will calculate the value of x as,
Question No: 3
Decremented only
Incremented only
Multiplied only
Both 1 and 2
Question No: 4
True
False
Question No: 5
False
True
Question No: 6
delete operator is used to return memory to free store which is allocated by the new operator
True
False
Question No: 7
When we do dynamic memory allocation in the constructor of a class, then it is necessary to provide a
destructor.
True
False
Question No: 8
Parameterized constructor will call for first 2 objects and default constructor for remaining objects
Default constructor will call for first 3 objects and Parameterized constructor for remaining
objects
Question No: 9
What is the sequence of event(s) when allocating memory using new operator?
Question No: 10
Deleting an array of objects without specifying [] brackets may lead to memory leak
True
False
Question No: 11
Which of the following data type will be assumed if no data type is specified with constant?
short
float
int
double
Question No: 12
There is an array of characters having name course that has to be initialized by string programming
which of the following is the correct way to do this,
Question No: 13
Question No: 14
Class
Object
Compiler
Question No: 15
Loader loads the executable code from hard disk to main memory.
True
False
Question No: 16
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: 17
The prototype of friend functions must be written ____ the class and its definition must be written ____
Question No: 18
Like member functions, ______ can also access the private data members of a class.
Non-member functions
Friend functions
Question No: 19
iostream.h
stdlib.h
iomanip.h
fstream.h
Question No: 20
Functions
Operators
Manipulators
Objects
Question No: 21
If we want to use stream insertion and extraction operators with _______ then we have to overload these
operators.
objects of class
Question No: 22
only class
only objects
Question No: 23
looped
nested
overloaded
Question No: 24
Question No: 25
class M {
friend int operator!(const M &);
...
};
!s
operator!(s)
...
Member function
Non-member function
Question No: 26
When the compiler overloads the assignment (=) operator by default then __________
Question No: 27
If text is a pointer of class String then what is meant by the following statement?
text = new String [5];
Question No: 28
Question No: 29
The appropriate data type to store the number of rows and colums of the matrix is____________.
float
int
char
Question No: 30
Copy constructor becomes necessary while dealing with _______allocation in the class.
Dynamic memory
Static memory
Question No: 31
( Marks: 1 )
What is drawback of writing the definitions of all the functions before main function?
Question No: 32
( Marks: 1 )
Question No: 33
( Marks: 2 )
Question No: 34
( Marks: 2 )
Question No: 35
( Marks: 3 )
Question No: 36
( Marks: 3 )
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Question No: 37
( Marks: 3 )
Why stream insertion and stream extraction operators cannot be overloaded as member functions?
Question No: 38
( Marks: 5 )
What is difference between Unary and binary operators and how they can be overloaded?
Question No: 39
( Marks: 5 )
Question No: 40
( Marks: 10 )
Write the program that inputs an octal number from the user and then display the entered octal number
into hexadecimal number using manipulators (parameter-less, parameterized) and member function of
input/output streams.
Question No: 41
( Marks: 10 )
Note: Addition of vector Let suppose there are two vectors A and B with their x, y coordinates.
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming
Ref No: xxxxxxx
Time: 90 min
Marks: 58
Student Info
Student ID:
bcxxxxxxxxx
Center:
OPKST
Exam Date:
09-08-2001
Q No.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Total
Question No: 1
Question No: 2
Header file: fstream.h includes the definition of the stream classes __________.
Question No: 3
* operator
operator
None of given.
True
False
Question No: 5
Question No: 6
True
False
Question No: 7
Member function
Non-member function
Private function
Public function
Question No: 8
True
False
Question No: 9
File
Disk
Keyboard
RAM
Question No: 10
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: 11
Consider the following code segment. What will be the output of the following program?
int func(int) ;
int num = 10 ;
int main(){
int num ;
num = 5 ;
cout << num ;
cout << func(num) ;
}
int func(int x){
return num ;
}
5, 5
10, 5
5, 10
10, 10
Question No: 12
With template function, the compiler automatically detects the passed data and generates a new copy
of function using passed data.
True
False
Question No: 13
What will be the correct syntax to declare two-dimensional array of float data type?
float arr{2}{2} ;
float arr[2][2] ;
float arr[2,2] ;
float[2][2] arr ;
Question No: 14
Question No: 15
True
False
Question No: 16
While calling function, the arguments are assigned to the parameters from _____________.
left to right.
right to left
Question No: 17
looped
nested
overloaded
Question No: 18
If we define an identifier with the statement #define PI 3.1415926 then during the execution of the
program the value of PI __________.
Remain constant.
Question No: 19
Question No: 20
Constructor
Destructor
Question No: 21
Zero arguments
Question No: 22
Databases Management
Networks
Question No: 23
When a call to a user-defined function finishes, the variable defined inside the function is still in
existence.
True
False
Question No: 24
True
False
Question No: 25
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this ,
_______________ http://vustudents.ning.com
Use templates
Question No: 26
"delete" operator is used to return memory to free store, which is allocated by the "new" operator.
True
False
Question No: 27
( Marks: 2 )
Question No: 28
( Marks: 2 )
Question No: 29
( Marks: 2 )
How the data members of a class are initialized with meaningful values?
Question No: 30
( Marks: 2 )
Question No: 31
( Marks: 3 )
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Question No: 32
( Marks: 3 )
What is the keyword this and what are the uses of this pointer?
Question No: 33
( Marks: 3 )
Question No: 34
( Marks: 5 )
Write the general syntax of a class that has one function as a friend of a class along with definition of
friend function.
Question No: 35
( Marks: 5 )
Question No: 36
( Marks: 5 )
Write a program which defines five variables which store the salaries of five employees, using setw and
setfill manipulators to display all these salaries in a column.
Note: Display all data with in a particular width and the empty space should be filled with character x
Output should be displayed as given below:
xxxxxx1000
xxxxxx1500
xxxxx20000
xxxxx30000
xxxxx60000
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming
Ref No: 1555950
Time: 90 min
Marks: 58
Student Info
Student ID:
Center:
Exam Date:
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Total
Question No: 2
Dealing with structures and functions passing by reference is the most economical method
True
False
Question No: 3
True
False
Question No: 4
Overloaded new operator function takes parameter of type size_t and returns
void (nothing)
void pointer
object pointer
int pointer
Question No: 5
When new operator is overloaded at global level then corresponding built-in new operator will not be
visible to whole of the program.
True
False
Question No: 6
If there is more than one statement in the block of a for loop, which of the following must be placed at
the beginning and the ending of the loop block?
parentheses ( )
braces { }
brackets [ ]
Question No: 7
The return type of a function that do not return any value must be ________
http://vustudents.ning.com
float
int
void
double
Question No: 8
JAVA
FORTRAN
Question No: 9
Like member functions, ______ can also access the private data members of a class.
Non-member functions
Friend functions
Question No: 10
It can be declared anywhere in class as these are not affected by the public and private keywords.
Question No: 11
http://vustudents.ning.com
Question No: 12
Functions
Operators
Manipulators
Objects
Question No: 13
True
False
Question No: 14
cast
cost
const
Question No: 15
True
False
Question No: 16
Which of the following function call is correct for the function prototype?
defaultParameters ( int a, int b = 7, char z = * );
defaultParameters (5);
Question No: 17
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: 18
True
False
Question No: 19
Question No: 20
The appropriate data type to store the number of rows and colums of the matrix is____________.
float
int
char
Question No: 21
data type
memory referee
value
http://vustudents.ning.com
Question No: 22
Decremented
Incremented
Multiplied
Question No: 23
NULL value has been defined in ______ and _________ header files.
Question No: 24
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this ,
_______________
Use templates
Question No: 25
Question No: 26
Question No: 27
( Marks: 2 )
Suppose there is a template function func having argument of type U and return type T. What will be
the C++ syntax to call this function, passing a variable x of type double and returning an int type?
Question No: 28
( Marks: 2 )
Which variable will be used in inner code block if we have the same names of variable at outer code
block and inner code block?
Question No: 29
( Marks: 2 )
Question No: 30
( Marks: 2 )
Write the C++ code for the declaration of overloaded stream insertion and stream extraction operator for
the object d of type Date.
Question No: 31
( Marks: 3 )
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Question No: 32
( Marks: 3 )
If the requested memory is not available in the system then what does calloc/malloc and new operator
return?
Question No: 33
( Marks: 3 )
Question No: 34
( Marks: 5 )
What is difference between Unary and binary operators and how they can be overloaded?
Question No: 35
( Marks: 5 )
class Matrix
{
private:
int Elements[3][3];
};
Write the operator function of stream extraction operator (>>) for this class.
http://vustudents.ning.com
Question No: 36
( Marks: 5 )
What is meant by user interface and class interface in C++ ? And what role a class interface can play in
user interface [Marks 5]
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming
Ref No: 1555950
Time: 90 min
Marks: 58
Student Info
Student ID:
Center:
Exam Date:
10
11
12
13
14
15
16
Marks
Q No.
Total
Marks
Q No.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Marks
Q No.
Marks
Q No.
Marks
Question No: 2
Dealing with structures and functions passing by reference is the most economical method
True
False
Question No: 3
True
False
Question No: 4
Overloaded new operator function takes parameter of type size_t and returns
void (nothing)
void pointer
object pointer
int pointer
Question No: 5
When new operator is overloaded at global level then corresponding built-in new operator will not be
visible to whole of the program.
True
False
Question No: 6
If there is more than one statement in the block of a for loop, which of the following must be placed at
the beginning and the ending of the loop block?
parentheses ( )
braces { }
brackets [ ]
Question No: 7
The return type of a function that do not return any value must be ________
http://vustudents.ning.com
float
int
void
double
Question No: 8
JAVA
FORTRAN
Question No: 9
Like member functions, ______ can also access the private data members of a class.
Non-member functions
Friend functions
Question No: 10
It can be declared anywhere in class as these are not affected by the public and private keywords.
Question No: 11
http://vustudents.ning.com
Question No: 12
Functions
Operators
Manipulators
Objects
Question No: 13
True
False
Question No: 14
cast
cost
const
Question No: 15
True
False
Question No: 16
Which of the following function call is correct for the function prototype?
defaultParameters ( int a, int b = 7, char z = * );
defaultParameters (5);
Question No: 17
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: 18
True
False
Question No: 19
Question No: 20
The appropriate data type to store the number of rows and colums of the matrix is____________.
float
int
char
Question No: 21
data type
memory referee
value
http://vustudents.ning.com
Question No: 22
Decremented
Incremented
Multiplied
Question No: 23
NULL value has been defined in ______ and _________ header files.
Question No: 24
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this ,
_______________
Use templates
Question No: 25
Question No: 26
Question No: 27
( Marks: 2 )
Suppose there is a template function func having argument of type U and return type T. What will be
the C++ syntax to call this function, passing a variable x of type double and returning an int type?
Question No: 28
( Marks: 2 )
Which variable will be used in inner code block if we have the same names of variable at outer code
block and inner code block?
Question No: 29
( Marks: 2 )
Question No: 30
( Marks: 2 )
Write the C++ code for the declaration of overloaded stream insertion and stream extraction operator for
the object d of type Date.
Question No: 31
( Marks: 3 )
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
Question No: 32
( Marks: 3 )
If the requested memory is not available in the system then what does calloc/malloc and new operator
return?
Question No: 33
( Marks: 3 )
Question No: 34
( Marks: 5 )
What is difference between Unary and binary operators and how they can be overloaded?
Question No: 35
( Marks: 5 )
class Matrix
{
private:
int Elements[3][3];
};
Write the operator function of stream extraction operator (>>) for this class.
http://vustudents.ning.com
Question No: 36
( Marks: 5 )
What is meant by user interface and class interface in C++ ? And what role a class interface can play in
user interface [Marks 5]
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming
Ref No: xxxxxxx
Time: 90 min
Marks: 58
Student Info
Student ID:
bcxxxxxxxxx
Center:
OPKST
Exam Date:
09-08-2001
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Total
Question No: 1
Question No: 2
Header file: fstream.h includes the definition of the stream classes __________.
Question No: 3
* operator
operator
None of given.
Question No: 4
True
False
Question No: 5
Question No: 6
True
False
Question No: 7
Member function
Non-member function
Private function
Public function
Question No: 8
True
False
Question No: 9
File
Disk
Keyboard
RAM
Question No: 10
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: 11
Consider the following code segment. What will be the output of the following program?
int func(int) ;
int num = 10 ;
int main(){
int num ;
num = 5 ;
cout << num ;
cout << func(num) ;
}
int func(int x){
return num ;
}
5, 5
10, 5
5, 10
10, 10
Question No: 12
With template function, the compiler automatically detects the passed data and generates a new copy
of function using passed data.
True
False
Question No: 13
What will be the correct syntax to declare two-dimensional array of float data type?
float arr{2}{2} ;
float arr[2][2] ;
float arr[2,2] ;
float[2][2] arr ;
Question No: 14
Question No: 15
True
False
Question No: 16
While calling function, the arguments are assigned to the parameters from _____________.
left to right.
right to left
Question No: 17
looped
nested
overloaded
Question No: 18
If we define an identifier with the statement #define PI 3.1415926 then during the execution of the
program the value of PI __________.
Remain constant.
Question No: 19
Question No: 20
Constructor
Destructor
Question No: 21
Zero arguments
Question No: 22
Databases Management
Networks
Question No: 23
When a call to a user-defined function finishes, the variable defined inside the function is still in
existence.
True
False
Question No: 24
True
False
Question No: 25
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this ,
_______________
Use templates
Question No: 26
"delete" operator is used to return memory to free store, which is allocated by the "new" operator.
True
False
Question No: 27
( Marks: 2 )
Question No: 28
( Marks: 2 )
Question No: 29
( Marks: 2 )
How the data members of a class are initialized with meaningful values?
Question No: 30
( Marks: 2 )
Question No: 31
( Marks: 3 )
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Question No: 32
( Marks: 3 )
What is the keyword this and what are the uses of this pointer?
Question No: 33
( Marks: 3 )
Question No: 34
( Marks: 5 )
Write the general syntax of a class that has one function as a friend of a class along with definition of
friend function.
Question No: 35
( Marks: 5 )
Question No: 36
( Marks: 5 )
Write a program which defines five variables which store the salaries of five employees, using setw and
setfill manipulators to display all these salaries in a column.
Note: Display all data with in a particular width and the empty space should be filled with character x
Output should be displayed as given below:
xxxxxx1000
xxxxxx1500
xxxxx20000
xxxxx30000
xxxxx60000
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming
Ref No:
Time: 90 min
Marks: 58
Student Info
Student ID:
Center:
Exam Date:
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Total
Question No: 1
Sequential File
Data File
Record File
Question No: 2
#error
#define
#line
#ndefine
Question No: 3
True
False
Question No: 4
Question No: 5
Question No: 6
When we do dynamic memory allocation in the constructor of a class, then it is necessary to provide a
destructor. http://vustudents.ning.com
True
False
Question No: 7
Overloaded new operator function takes parameter of type size_t and returns
void (nothing)
void pointer
object pointer
int pointer
Question No: 8
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
is a case-sensitive language
True
False
Question No: 10
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: 11
True
False
Question No: 12
True
False
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
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
True
False
Question No: 17
True
False
Question No: 18
function prototype
function definition
Question No: 19
looped
nested
overloaded
Question No: 20
Data encapsulation
Question No: 21
Constructor
Destructor
Compile Time
Run Time
Link Time
Question No: 23
Question No: 24
True
False
Question No: 25
and Delete are also used with ___________ and data types as well.
Class, Objects
Structures, Pointers
None of above
Question No: 26
With New keyword, data types and class members are initialized with meaningful values instead of
garbage. http://vustudents.ning.com
True
False
Question No: 27
( Marks: 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
( Marks: 2 )
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.
Question No: 30
( Marks: 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] ;
Question No: 31
( Marks: 3 )
Which one (copy constructor or assignment operator) will be called in each of the following code
segment?
1)
Matrix m1 (m2);
2)
3)
Matrix m1 = m2;
Ans:
1)
2)
assignment operator
3)
Question No: 32
( Marks: 3 )
What will be the output of following function if we call this function by passing int 5?
Ans:
1/5
Question No: 33
( Marks: 3 )
Identify the errors in the following member operator function and also correct them.
http://vustudents.ning.com
math * operator(math m);
}
ANS:
The errors are in the arguments of the member operation function and also in the body of operator
member function.
Question No: 34
( Marks: 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 <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;
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: http://vustudents.ning.com
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 )
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 <iostream.h>
math
{
mth operator + (obj1,obj2)
mth operator + (obj1,obj2)
{
mth operator + (obj1,obj2)
mth operator + (obj1,obj2)
}
}
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming
Ref No: 1557656
Time: 90 min
Marks: 58
Student Info
Student ID:
Dc100200028
Center:
OPKST
Exam Date:
12/8/10
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Q No.
Marks
Total
Question No: 1
Data
Memory Address
Data Type
Values
Question No: 2
+
+
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
What is the sequence of event(s) when deallocating memory using delete operator?
Question No: 5
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
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
int
short
float
char
Question No: 8
True
False
Question No: 9
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; }
only 0
only 1
only 2
Question No: 10
True
False
Question No: 11
Signed integer
Un-signed integer
Signed double
Un-signed double
Question No: 12
Only Functions
Only Variables
Question No: 13
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
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
The first parameter of overloaded stream insertion operator is _________ where second parameter is
_______ http://vustudents.ning.com
Question No: 16
True
False
Question No: 17
True
False
Question No: 18
While calling function, the arguments are assigned to the parameters from _____________.
left to right.
right to left
Question No: 19
looped
nested
overloaded
Question No: 20
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
Remain constant.
Question No: 21
right
left
binary
unary
Question No: 22
If text is a pointer of class String then what is meant by the following statement?
text = new String [5];
Question No: 23
The return type of the operator function for << operator is __________.
void
Question No: 24
implement
design
analysis
Question No: 25
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
Question No: 26
true
false
Question No: 27
( Marks: 2 )
Answer:
Syntax of class template:
Question No: 28
( Marks: 2 )
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 )
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
3. func(5, 6) ;
Function call:
Function ; Function definition: numbers; Function declaration: 5&6
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(){
Question No: 32
( Marks: 3 )
Answer:
No, we cannot define two functions as func(intx, inty) func(int &x, int&y) because its give an error
function not initializing.
Question No: 33
( Marks: 3 )
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 )
Answer:
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
{
elements [ i ] = new double [ numCols ] ;
for ( int j = 0 ; j < numCols ; j ++ )
elements [ i ] [ j ] = 0.0 ;
}
}
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