CS201 Solved Final Papers 249 Pages File
CS201 Solved Final Papers 249 Pages File
Marks: 58
#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 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.
► True
► False
Fall 2009
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
What will be the output of following statement?
► 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
► Zero
► One
► Two
► Three
► True
► False
► True
► False
► True
► False
► operator Class-Name + ( )
s ► Class-Name operator + ( )
Let suppose
int a, b, c, d, e;
a = b = c = d = e = 42;
This can be interpreted by the complier as:
► a = (b = (c = (d = (e = 42))));
► (a = b = (c = (d = (e = 42))));
► 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
► 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
► It can be declared anywhere in class as these are not affected by the public and
private keywords.
► Memory Address
► Data values
When memory for a program is allocated at run time then it is called ________
► Data encapsulation
► Member functions
► Utility functions
► Constructor
► Destructor
Date operator++(int )
► Be a syntax error
► Be a logical error
► logical expressions
► arithmetic expressions
► Dynamic allocation
( 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 ;
( Marks: 3 )
When we call calloc function to allocate memory and its return a NULL pointer what does it mean?
( Marks: 3 )
numRows = m.numRows ;
numCols = m.numCols ;
elements [ i ] [ j ] = m.elements [ i ] [ j ] ;
}
( 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 )
Question # 1
1) : 3
2) : 4
3) : 5
4) : 7
Correct
Option From :
:
Question # 2
We can also use member functions with cin and cout objects
1) : True
2) : FALSE Answer
3) :
4) :
Correct
Option From :
: 2
Question # 3
If the statements
int j,k;
j = 123;
k= 234;
int* q, * r;
cout < < *q < < ' ' < < * r ;
are executed, what will be displayed?
Correct
Option From : Lecture 14
: 4
Question # 4
1) : OR ( || )
2) : AND ( &&)
3) : XOR ( ^ )
Correct
Option From : Lecture 16
: 4
Question # 5
1) : i = i + i;
2) : i = i + 1; Answer
3) : i = i - 1;
4) : i --;
Correct
Option From : Lecture 16
: 2
Question # 6
1) : Automatic variable
2) : Global variable
Question # 7
If we open a file stream myfile for reading, what will give us the current position of the file
pointer?
1) : tellg() Answer
2) : tellp()
3) : seekg()
4) : seekp()
Correct
Option From : Lecture 19
: 1
Question # 8
1) : Type letters
4) : Develop Graphics
Correct
Option From : Lecture 2
: 3
Question # 9
template < class T >, Here T can be replaced with any name but it is
3) :
preferable. Answer
4) : class template
Correct
Option From : Lecture 21
: 3
Question # 10
1) : Function
2) : Procedure
4) : Simple macro
Correct
Option From : Lecture 23
: 3
Question # 11
1) : TRUE
2) : FALSE Answer
3) :
4) :
Correct
Option From : Lecture 23
: 2
Question # 12
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 24
: 1
Question # 13
1) : Costly
2) : Expansive
3) : efficient Answer
4) : Difficult
Correct
Option From : Lecture 24
: 3
Question # 14
Before exiting the program, make sure that the allocated memory has freed.
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 24
: 1
Question # 15
Answer
1) : #
2) : $
3) : %
4) : ##
Correct
Option From : Lecture 25
: 1
Question # 16
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 26
: 1
Question # 17
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 26
: 1
Question # 18
1) : True
2) : FALSE Answer
3) :
4) :
Correct
Option From : Lecture 26
: 2
Question # 19
Correct
Option From : Lecture 26
: 4
Question # 20
Correct
Option From : Lecture 26
: 3
Question # 21
Correct
Option From : Lecture 26
: 4
Question # 22
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 26
: 1
Question # 23
There is a class Student, Which one of the following is a valid destructor for this class.
1) : Student();
2) : ~ Student(); Answer
3) : ~ Student(int);
4) : int~ Student();
Correct
Option From : Lecture 27
: 2
Question # 24
The reserved words public and private comes under the category
1) : structures Answer
2) : strings
3) : accessibility modifiers
4) : types of functions
Correct
Option From : Lecture 27
: 1
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(); Answer
4) : ~ Student(int);
Correct
Option From : Lecture 27
: 3
Question # 26
Correct
Option From : Lecture 27
: 2
Question # 27
Correct
Option From : Lecture 28
: 4
Question # 28
Question # 29
1) : new
2) : delete
3) : +=
4) : sizeof
Correct
Option From : Lecture 28
: 2
Question # 30
Correct
Option From : Lecture 28
: 2
Question # 31
1) : TRUE Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 28
: 1
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) ;
Question # 33
The function free() returns back the allocated memory got thorough calloc and malloc to
_____ .
1) : stack
2) : heap Answer
Correct
Option From : Lecture 28
: 2
Question # 34
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 28
: 1
Question # 35
If the memory in the free store is not sufficient enough to fulfill the request, malloc()
function returns NO pointer.
1) : True
2) : FALSE Answer
3) :
4) :
Correct
Option From : Lecture 28
: 2
Question # 36
A friend function
2) : can access the private data of the class that declares it a friend Answer
Correct
Option From : Lecture 29
: 2
Question # 37
Correct
Option From : Lecture 29
: 3
Question # 38
A friend function
4) : can access the private data of the class that declares it a friend Answer
Correct
Option From : Lecture 29
: 4
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 From : Lecture 29
: 3
Question # 40
The prototype of friend functions must be written ____ the class and its definition must be
written ____
Correct
Option From : Lecture 29
: 2
Question # 41
1) : Local
2) : Global
Correct
Option From : Lecture 30
: 3
Question # 42
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 30
: 1
Question # 43
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 30
: 1
Question # 44
2) : operator Class-Name - ( )
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 Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 30
: 1
Question # 46
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 30
: 1
Question # 47
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 30
: 1
Question # 48
1) : True
2) : FALSE Answer
3) :
4) :
Correct
Option From : Lecture 30
: 2
Question # 49
The reference data types are used as ordinary variables without any dereference operator.
1) : True Answer
2) : FALSE
3) :
4) :
Question # 50
1) : new
2) : delete
3) : +=
4) : sizeof Answer
Correct
Option From : Lecture 31
: 3
Question # 51
2) : operator Class-Name + ( )
4) : Class-Name operator + ( )
Correct
Option From : Lecture 31
: 1
Question # 52
2) : FALSE Answer
3) :
4) :
Correct
Option From : Lecture 31
: 2
Question # 53
In overloading the assignment (=) operator, which object will call the operator function?
Correct
Option From : Lecture 31
: 3
Question # 54
2) : Certain overloaded operators can change the number of arguments they take. Answer
Question # 55
1) : syntax error
3) : not an error
Correct
Option From : Lecture 31
: 2
Question # 56
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 32
: 1
Question # 57
If we define an identifier with the statement #define PI 3.1415926 then during the
execution of the program the value of PI __________.
Correct
Option From : Lecture 34
: 3
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 Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 36
: 1
Question # 59
The default constructor (parameterless constructor) is called for each element in the array
allocated with new.
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 36
: 1
Question # 60
1) : True
2) : FALSE Answer
3) :
4) :
Correct
Option From : Lecture 36
: 2
Question # 61
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 36
: 1
Question # 62
The delete operator returns nothing (void) and accepts a pointer of void * to the memory
block.
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 36
: 1
Question # 63
The delete operator returns nothing (void) and accepts a pointer of type * to the memory
block.
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 36
: 2
Question # 64
By overloading new and delete operators, only allocation and deallocation part can be
overridden.
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 36
: 1
Question # 65
1) : True Answer
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 36
: 2
Question # 66
By overloading the array operator ( [] ), one can implement mechanism to check for array
bound.
1) : True
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 36
: 1
Question # 67
Stream insertion ( << ) and extraction operators ( >> ) are always implemented as
___________ functions.
1) : Member
2) : non-member
3) : Inside
4) : Out Side
Correct
Option From : Lecture 37
: 2
Question # 68
For operator >>, the second parameter must also be passed by reference.
1) : True
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 37
: 1
Question # 69
Static member functions
Correct
Option From : Lecture 38
: 4
Question # 70
A copy constructor
4) : takes no arguments
Correct
Option From : Lecture 39
: 1
Question # 71
A copy constructor
1) : takes no arguments
Correct
Option From : Lecture 39
: 3
Question # 72
1) : True
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 40
: 1
Question # 73
The inner data members of the object are constructed and then the object itself.
1) : True
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 40
: 1
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 From : Lecture 40
: 2
Question # 75
Initializer list is used to initialize the inner objects at the construction time.
1) : True
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 40
: 1
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 From : Lecture 40
: 1
Question # 77
Correct
Option From : Lecture 41
: 4
Question # 78
1) : TRUE
2) : FALSE
3) :
4) :
Question # 79
Correct
Option From : Lecture 41
: 3
Question # 80
1) : TRUE
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 41
: 1
Question # 81
2) : Implicitly
Correct
Option From : Lecture 42
: 1
Question # 82
1) : TRUE
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 42
: 1
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 From : Lecture 42
: 1
Question # 84
1) : Databases Management
2) : Networks
Correct
Option From : Lecture 45
: 1
Question # 85
1) : Type letters
Correct
Option From : Lecture 6
: 4
Question # 86
Loader transfers the executable code from main memory to hard disk.
1) : TRUE
2) : FALSE
3) :
4) :
Correct
Option From : Lecture 6
: 2
Question # 87
Correct
Option From : Lecture 7
: 3
Copyright © Eagle_eye
Powered By: Group of Virtual's Experts
www.virtualinspire.com
FINALTERM EXAMINATION
Spring 2010
Ref No:
Time: 90 min
Question No: 1 ( Marks: 1 ) - Please choose one
►Sequential File
►Data File
►Record File
►#error
►#define
►#line
►#ndefine
►True
►False
Question No: 4 ( Marks: 1 ) - Please choose one
When we do dynamic memory allocation in the constructor of a class, then it is necessary to provide a
destructor.
►True
►False
Overloaded new operator function takes parameter of type size_t and returns
►void (nothing)
►void pointer
►object pointer
►int pointer
The second parameter of operator functions for << and >> are objects of the class for which we are
overloading these operators.
►True
►False
C++
is a case-sensitive language
►True
►False
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>
►True
►False
►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] ;
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
If
most significant bit of un-signed number is 1 then it represents a positive number.
►True
►False
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 _____.
We
can also do conditional compilation with preprocessor directives.
►True
►False
The
default value of a parameter can be provided inside the ________________
►function prototype
►function definition
►both function prototype or function definition
►looped
►nested
►overloaded
►Data encapsulation
►Constructor
►Destructor
new
operator is used to allocate memory from the free store during
►Compile Time
►Run Time
►Link Time
It is
possible to define a class within another class.
►True
►False
New
and Delete are also used with ___________ and data types as well.
►Class, Objects
►Structures, Pointers
With
New keyword, data types and class members are initialized with meaningful values instead of garbage.
►True
►False
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.
Ans:
Modulus operator
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.
Write down piece of code that will declare a matrix of 3x3. And initialize all its locations with 0;
Ans:
1) Matrix m1 (m2);
m1 = m2;
3) Matrix m1 = m2;
Ans:
What will be the output of following function if we call this function by passing int 5?
Ans:
1/5
math temp;
return number;
ANS:
The errors are in the arguments of the member operation function and also in the body of operator
member function.
math temp;
temp = m;
return temp.number;
}
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
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:
• 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.
Write the declaration and definition of operator function to overload + operator for the statements of
main function.
obj2= 10 + obj1 ;
Ans:
#include <iostream.h>
math
……………………………………………………………………………
www.virtualinspire.com
FINALTERM EXAMINATION
Spring 2010
Time: 90 min
Marks: 58
Student Info
Student ID:
Center:
Exam Date:
Q No. 1 2 3 4 5 6 7 8 Total
Marks
Q No. 9 10 11 12 13 14 15 16
Marks
Q No. 17 18 19 20 21 22 23 24
Marks
Q No. 25 26 27 28 29 30 31 32
Marks
Q No. 33 34 35 36
Marks
Question No: 1 ( Marks: 1 ) - Please choose one
Dealing with structures and functions passing by reference is the most economical method
►True
►False
Question No: 3 ( Marks: 1 ) - Please choose one
►True
►False
Overloaded new operator function takes parameter of type size_t and returns
►void (nothing)
►void pointer
►object pointer
►int pointer
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
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 [ ]
The return type of a function that do not return any value must be ________
►float
►int
►void
►double
►B
►C
►FORTRAN
Like member functions, ______ can also access the private data members of a class.
►Non-member functions
►Friend functions
►It can be declared anywhere in class as these are not affected by the public and private keywords.
►Functions
►Operators
►Manipulators
►Objects
►True
►False
►cast
►cost
►const
Question No: 15 ( Marks: 1 ) - Please choose one
►True
►False
Which of the following function call is correct for the function prototype?
►defaultParameters (5);
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 ( Marks: 1 ) - Please choose one
►True
►False
The appropriate data type to store the number of rows and colums of the matrix is____________.
►float
►int
►char
►memory referee
►value
►Decremented
►Incremented
►Multiplied
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this ,
_______________
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/
Write the C++ code for the declaration of overloaded stream insertion and stream extraction operator
for the object d of type Date.
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
2)
void func2(){
static int x = 0 ;
x++;
If the requested memory is not available in the system then what does calloc/malloc and new operator
return?
What is difference between Unary and binary operators and how they can be overloaded?
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
► Two
► Three
► Four
► Five
Question No: 2 ( Marks: 1 ) - Please choose one
When x = 7; then the expression x%= 2; will calculate the value of x as,
►1
►3
►7
►2
► Decremented only
► Incremented only
► Multiplied only
► Both 1 and 2
► True
► False
► False
► True
► True
► False
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 ( Marks: 1 ) - Please choose one
► 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
Deleting an array of objects without specifying [] brackets may lead to memory leak
► True
► False
Question No: 11 ( Marks: 1 ) - Please choose one
Which of the following data type will be assumed if no data type is specified with constant?
► short
► float
► int
► double
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,
i. course[] = {„p‟, ‟r‟, ‟o‟, ‟g‟, ‟r‟, ‟a‟, ‟m‟, ‟m‟, ‟i‟, ‟n‟, ‟g‟};
ii. course[] = „programming‟ ;
iii. course[12] = “programming” ;
iv. course = “programming” ;
► Class
► Object
► Compiler
Loader loads the executable code from hard disk to main memory.
► True
► False
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];
The prototype of friend functions must be written ____ the class and its definition must be written ____
Like member functions, ______ can also access the private data members of a class.
► Non-member functions
► Friend functions
► iostream.h
► stdlib.h
► iomanip.h
► fstream.h
► Operators
► Manipulators
► Objects
If we want to use stream insertion and extraction operators with _______ then we have to overload these
operators.
► objects of class
► only class
► only objects
► nested
► overloaded
class M {
...
};
...
► Member function
► Non-member function
When the compiler overloads the assignment (=) operator by default then __________
If text is a pointer of class String then what is meant by the following statement?
The appropriate data type to store the number of rows and colums of the matrix is____________.
► float
► int
► char
Copy constructor becomes necessary while dealing with _______allocation in the class.
► Dynamic memory
► Static memory
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
2)
void func2(){
static int x = 0 ;
x++;
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?
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.
The class should also provide the following Overloaded operator capabilities.
Note: Addition of vector Let suppose there are two vectors A and B with their x, y coordinates.
FINALTERM EXAMINATION
Spring 2010
Time: 90 min
Marks: 58
Student Info
Center: OPKST
Marks
Q No. 9 10 11 12 13 14 15 16
Marks
Q No. 17 18 19 20 21 22 23 24
Marks
Q No. 25 26 27 28 29 30 31 32
Marks
Q No. 33 34 35 36
Marks
Question No: 1 ( Marks: 1 ) - Please choose one
Header file: fstream.h includes the definition of the stream classes __________.
►* operator
► operator
►None of given.
Question No: 4 http://vustudents.ning.com ( Marks: 1 ) - Please choose one
►True
►False
►True
►False
►Member function
►Non-member function
►Private function
►Public function
►True
►False
►Disk
►Keyboard
►RAM
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;
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 ;
return num ;
}
►5, 5
►10, 5
►5, 10
►10, 10
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 ( Marks: 1 ) - Please choose one
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 ;
►True
►False
Question No: 16 ( Marks: 1 ) - Please choose one
While calling function, the arguments are assigned to the parameters from _____________.
►left to right.
►right to left
►looped
►nested
►overloaded
►none of the given options.
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.
►Constructor
►Destructor
►Zero arguments
►None of the given options
►Databases Management
►Networks
When a call to a user-defined function finishes, the variable defined inside the function is still in
existence.
►True
►False
►True
►False
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
►Use strings to store all types
"delete" operator is used to return memory to free store, which is allocated by the "new" operator.
►True
►False
How the data members of a class are initialized with meaningful values?
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
2)
void func2(){
static int x = 0 ;
x++;
What is the keyword ‘this’ and what are the uses of ‘this’ pointer?
Write the general syntax of a class that has one function as a friend of a class along with definition of
friend function.
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
xxxxxx1000
xxxxxx1500
xxxxx20000
xxxxx30000
xxxxx60000
FINALTERM EXAMINATION
Spring 2010
Time: 90 min
Marks: 58
Student Info
Student ID:
Center:
Exam Date:
Q No. 1 2 3 4 5 6 7 8 Total
Marks
Q No. 9 10 11 12 13 14 15 16
Marks
Q No. 17 18 19 20 21 22 23 24
Marks
Q No. 25 26 27 28 29 30 31 32
Marks
Q No. 33 34 35 36
Marks
Question No: 1 http://vustudents.ning.com ( Marks: 1 ) - Please choose one
Dealing with structures and functions passing by reference is the most economical method
► True
► False
Question No: 3 ( Marks: 1 ) - Please choose one
► True
► False
Overloaded new operator function takes parameter of type size_t and returns
► void (nothing)
► void pointer
► object pointer
► int pointer
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
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 [ ]
The return type of a function that do not return any value must be ________
http://vustudents.ning.com
► float
► int
► void
► double
► JAVA
►B
►C
► FORTRAN
Like member functions, ______ can also access the private data members of a class.
► Non-member functions
► Friend functions
► It can be declared anywhere in class as these are not affected by the public and private keywords.
► Functions
► Operators
► Manipulators
► Objects
► True
► False
► cast
► cost
► const
► True
► False
Which of the following function call is correct for the function prototype?
► defaultParameters (5);
► defaultParameters (5, „8‟);
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
► True
► False
The appropriate data type to store the number of rows and colums of the matrix is____________.
► float
► int
► char
► data type
► memory referee
► value
http://vustudents.ning.com
► Decremented
► Incremented
► Multiplied
NULL value has been defined in ______ and _________ header files.
► Use templates
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?
Write the C++ code for the declaration of overloaded stream insertion and stream extraction operator for
the object d of type Date.
1)
void func1(){
int x = 0;
x++;
2)
void func2(){
static int x = 0 ;
x++;
If the requested memory is not available in the system then what does calloc/malloc and new operator
return?
What is difference between Unary and binary operators and how they can be overloaded?
class Matrix
private:
int Elements[3][3];
};
Write the operator function of stream extraction operator (>>) for this class.
http://vustudents.ning.com
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
Time: 90 min
Marks: 58
Student Info
Student ID:
Center:
Exam Date:
Q No. 1 2 3 4 5 6 7 8 Total
Marks
Q No. 9 10 11 12 13 14 15 16
Marks
Q No. 17 18 19 20 21 22 23 24
Marks
Q No. 25 26 27 28 29 30 31 32
Marks
Q No. 33 34 35 36
Marks
Question No: 1 http://vustudents.ning.com ( Marks: 1 ) - Please choose one
Dealing with structures and functions passing by reference is the most economical method
► True
► False
Question No: 3 ( Marks: 1 ) - Please choose one
► True
► False
Overloaded new operator function takes parameter of type size_t and returns
► void (nothing)
► void pointer
► object pointer
► int pointer
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
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 [ ]
The return type of a function that do not return any value must be ________
http://vustudents.ning.com
► float
► int
► void
► double
► JAVA
►B
►C
► FORTRAN
Like member functions, ______ can also access the private data members of a class.
► Non-member functions
► Friend functions
► It can be declared anywhere in class as these are not affected by the public and private keywords.
http://vustudents.ning.com
► Functions
► Operators
► Manipulators
► Objects
Question No: 13 ( Marks: 1 ) - Please choose one
► True
► False
► cast
► cost
► const
Question No: 15 ( Marks: 1 ) - Please choose one
► True
► False
Which of the following function call is correct for the function prototype?
► defaultParameters (5);
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 ( Marks: 1 ) - Please choose one
► True
► False
The appropriate data type to store the number of rows and colums of the matrix is____________.
► float
► int
► char
► data type
► memory referee
► value
http://vustudents.ning.com
► Decremented
► Incremented
► Multiplied
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this ,
_______________
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?
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 )
Write the C++ code for the declaration of overloaded stream insertion and stream extraction operator for
the object d of type Date.
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++;
If the requested memory is not available in the system then what does calloc/malloc and new operator
return?
What is difference between Unary and binary operators and how they can be overloaded?
class Matrix
private:
int Elements[3][3];
};
Write the operator function of stream extraction operator (>>) for this class.
http://vustudents.ning.com
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
Time: 90 min
Marks: 58
Student Info
Center: OPKST
Q No. 1 2 3 4 5 6 7 8 Total
Marks
Q No. 9 10 11 12 13 14 15 16
Marks
Q No. 17 18 19 20 21 22 23 24
Marks
Q No. 25 26 27 28 29 30 31 32
Marks
Q No. 33 34 35 36
Marks
Question No: 1 ( Marks: 1 ) - Please choose one
Header file: fstream.h includes the definition of the stream classes __________.
►* operator
► operator
►None of given.
Question No: 4 ( Marks: 1 ) - Please choose one
►True
►False
►True
►False
►Member function
►Non-member function
►Private function
►Public function
►True
►False
►Disk
►Keyboard
►RAM
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;
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 ;
return num ;
}
►5, 5
►10, 5
►5, 10
►10, 10
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 ( Marks: 1 ) - Please choose one
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 ;
►True
►False
Question No: 16 ( Marks: 1 ) - Please choose one
While calling function, the arguments are assigned to the parameters from _____________.
►left to right.
►right to left
►looped
►nested
►overloaded
►none of the given options.
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.
►Constructor
►Destructor
►Zero arguments
►None of the given options
►Databases Management
►Networks
When a call to a user-defined function finishes, the variable defined inside the function is still in
existence.
►True
►False
►True
►False
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this ,
_______________
►Use templates
►Use strings to store all types
"delete" operator is used to return memory to free store, which is allocated by the "new" operator.
►True
►False
How the data members of a class are initialized with meaningful values?
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
2)
void func2(){
static int x = 0 ;
x++;
What is the keyword ‘this’ and what are the uses of ‘this’ pointer?
Write the general syntax of a class that has one function as a friend of a class along with definition of
friend function.
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
xxxxxx1000
xxxxxx1500
xxxxx20000
xxxxx30000
xxxxx60000
FINALTERM EXAMINATION
Spring 2010
Ref No:
Time: 90 min
Marks: 58
Student Info
Student ID:
Center:
Exam Date:
Q No. 1 2 3 4 5 6 7 8 Total
Marks
Q No. 9 10 11 12 13 14 15 16
Marks
Q No. 17 18 19 20 21 22 23 24
Marks
Q No. 25 26 27 28 29 30 31 32
Marks
Q No. 33 34 35 36
Marks
Question No: 1 ( Marks: 1 ) - Please choose one
►Sequential File
►Data File
►Record File
►#error
►#define
►#line
►#ndefine
►False
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
Overloaded new operator function takes parameter of type size_t and returns
►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
C++
is a case-sensitive language
►True
►False
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>
A
template function must have only generic data types.
►True
►False
►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] ;
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
If
most significant bit of un-signed number is 1 then it represents a positive number.
►True
►False
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
We
can also do conditional compilation with preprocessor directives.
►True
►False
The
default value of a parameter can be provided inside the ________________
►function prototype
►function definition
►looped
►nested
►overloaded
►Data encapsulation
►Constructor
►Destructor
new
operator is used to allocate memory from the free store during
►Compile Time
►Run Time
►Link Time
►None of the given options
It is
possible to define a class within another class.
►True
►False
New
and Delete are also used with ___________ and data types as well.
►Class, Objects
►Structures, Pointers
►None of above
With New keyword, data types and class members are initialized with meaningful values instead of
garbage. http://vustudents.ning.com
►True
►False
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.
Ans: http://vustudents.ning.com
Modulus operator
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.
Write down piece of code that will declare a matrix of 3x3. And initialize all its locations with 0;
Ans:
Which one (copy constructor or assignment operator) will be called in each of the following code
segment?
1) Matrix m1 (m2);
m1 = m2;
3) Matrix m1 = m2;
Ans:
What will be the output of following function if we call this function by passing int 5?
Ans:
1/5
Identify the errors in the following member operator function and also correct them.
http://vustudents.ning.com
math temp;
return number;
}
ANS:
The errors are in the arguments of the member operation function and also in the body of operator
member function.
math temp;
temp = m;
return temp.number;
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
return 0;
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
• 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.
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.
Ans:
#include <iostream.h>
math
……………………………………………………………………………
FINALTERM EXAMINATION
Spring 2010
Time: 90 min
Marks: 58
Student Info
Center: OPKST
Q No. 1 2 3 4 5 6 7 8 Total
Marks
Q No. 9 10 11 12 13 14 15 16
Marks
Q No. 17 18 19 20 21 22 23 24
Marks
Q No. 25 26 27 28 29 30 31 32
Marks
Q No. 33 34 35 36
Marks
Question No: 1 ( Marks: 1 ) - Please choose one
► Data
► Memory Address
► Data Type
► Values
►*
►+
+
►@
►#
Within the statement obj1=obj2; obj1 will call the assignment operator function and obj2 will be passed
as an argument to function.
► True
► False
What is the sequence of event(s) when deallocating memory using delete operator?
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
► #include “iostream.h”
► include <iostream.h>
► include <iostream.h>
► #include <iostream.h>
► int
► short
► float
► char
► True
► False
For which values of the integer _value will the following code becomes an infinite loop?
int number=1;
while (true) {
if (number == 3) break;
number += integer_value; }
► any number other than 1 or 2
► only 0
► only 1
► only 2
► True
► False
► Un-signed integer
► Signed double
► Un-signed double
► Only Functions
► Only Variables
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 ( Marks: 1 ) - Please choose one
Unary operator implemented as member function takes ____ arguments whereas non-member function
takes _____ arguments.
► One, zero
► Zero, one
► One, two
► Two, one
The first parameter of overloaded stream insertion operator is _________ where second parameter is
_______ http://vustudents.ning.com
► input stream, object of class
► True
► False
► True
► False
While calling function, the arguments are assigned to the parameters from _____________.
► left to right.
► right to left
► nested
► overloaded
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.
► can be changed by some operation
► right
► left
► binary
► unary
► void
► implement
► design
► analysis
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
► true
► false
Answer:
class class-name()
definition of class
};
Answer:
The difference between endl and \n is that endl is use to start a new line for the next row
Answer:
Identify each of the following as function call, function definition and function declaration.
and Num2
2. int func(int, int);
Function call:
3. func(5, 6) ;
Function call:
Function ; Function definition: Integer; Function declaration: Num1 and Num2 from
user
Consider the following code segment. What will be the output of the following code segment?
class class1{
public:
class class2{
public:
class2(){
cout << “Calling default constructor of class2\n” ;
};
class1(){
};
main(){
class1::class2 obj1;
class1 obj2 ;
func(int x, int y)
Answer:
No, we cannot define two functions as func(intx, inty) func(int &x, int&y) because it‟s give an error
function not initializing.
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.
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
Read the given below code and explain what task is being performed by this function
numRows = row ;
numCols = col ;
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