Final Solved Papers cs201
Final Solved Papers cs201
Spring 2010
CS201- Introduction to Programming
Ref No:
Time: 90 min
Marks: 58
Student Info
Student ID:
Center:
Exam Date:
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
Question No: 3 ( Marks: 1 ) - Please choose one
► True
► False
► True
► False
► void (nothing)
► void pointer
► object pointer
► int pointer
► True
► False
► False
► #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
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
► True
► False
► function prototype
► function definition
► both function prototype or function definition
► looped
► nested
► overloaded
► Data encapsulation
► Destructor
► Compile Time
► Run Time
► Link Time
► True
► False
► Class, Objects
► Structures, Pointers
► None of above
► True
► False
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.
http://vustudents.ning.com/
Ans:
1) Matrix m1 (m2); copy constructor
2) Matrix m1, m2;
m1 = m2; assignment operator
3) Matrix m1 = m2; assignment operator
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.
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;
}
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)
}
}
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming
Marks: 58
Question No: 1 ( Marks: 1 ) - Please choose one
*.doc is _____________ by type.
.
► Sequential File
► Random Access File
► Data File
► Record File
Question No: 2 ( Marks: 1 ) - Please choose one
Which of the following is NOT a preprocessor directive?
► #error
► #define
► #line
► #ndefine
Question No: 3 ( Marks: 1 ) - Please choose one
The return type of operator function must always be void.
► True
► False
The syntax of the prototype of the overloaded operator function is: return-type operator
operator-symbol (parameter-list);
Question No: 4 ( Marks: 1 ) - Please choose one
What does (*this) represents?
► The current function of the class
► The current pointer of the class
► The current object of the class
► A value of the data member
Whenever an object calls a member function, the function implicitly gets a pointer from the
calling object. That pointer is known as this pointer. ‘this’ is a key word. We cannot use it as
a variable name. ‘this’ pointer is present in the function, referring to the calling object. For
example, if we have to refer a member, let’s say buf, of our String class, we can write it
simply as: buf ;
main()
{
int myarr [4]= {0,1,2,3};
int *ptr ;
ptr = myarr;
cout<
cout<<*(ptr+3);
cout<<(ptr+3);
int i = 0;
cin>> i;
}
include<iostream.h>
main () {
int matrix [3][3];
int anyvalue = 12
}
ANS:
The errors are in the arguments of the member operation function and also in the body of
operator member function.
Correct function should be
math *operator(math *m);
math *operator (math *m)
{
math temp;
temp = m;
temp.number= number * number;
return temp.number;
}
Question No: 34 ( Marks: 5 )
Write a program which defines three variables of type double which store three different
values including decimal points, using setprecision manipulators to print all these values
with different number of digits after the decimal number.
Ans:
#include
#include
int main ()
{
double x1 = 12345624.72345
double x2 = 987654.12345
double x3 = 1985.23456
cout << setprecision (3) << x1<< endl;
cout << setprecision (4) << x2 << endl;
cout << setprecision (5) << x3<< endl;
return 0;
}
Question No: 35 ( Marks: 5 )
What are the advantages and disadvantages of using templates?
Ans:
Many thing can be possible without using templates but it do offer several clear
advantages not offered by any other techniques:
Advanatages:
• Templates are easier to write than writing several versions of your similar code for
different types. You create only one generic version of your class or function instead of
manually creating specializations.
• Templates are type-safe. This is because the types that templates act upon are known at
compile time, so the compiler can perform type checking before errors occur.
• Templates can be easier to understand, since they can provide a straightforward way of
abstracting type information.
• It help in utilizing compiler optimizations to the extreme. Then of course there is room
for misuse of the templates. On one hand they provide an excellent mechanism to create
specific type-safe classes from a generic definition with little overhead.
Disadvantages:
On the other hand, if misused
• Templates can make code difficult to read and follow depending upon coding style.
• They can present seriously confusing syntactical problems esp. when the code is large
and spread over several header and source files.
• Then, there are times, when templates can "excellently" produce nearly meaningless
compiler errors thus requiring extra care to enforce syntactical and other design
constraints. A common mistake is the angle bracket problem.
Question No: 36 ( 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
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
Solved with references by Farhat Qudsia
Question No: 1 ( Marks: 1 ) - Please choose one
For being copy able, both arrays need to be of same data type and same size
► True
► False
► True
► False
Overloaded new operator function takes parameter of type size_t and returns
► void (nothing)
► void pointer
► object pointer
► int pointer
new operator takes a parameter of type size_t. This parameter holds the size of
the object being allocated, and the compiler automatically sets its value
whenever we use new. Also note that the new operator returns a void pointer.
Any new operator we write must have this parameter and return type.
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 [ ]
BLOCK – is a group of one ore more statements enclosed in curly braces {}.
Question No: 7 ( Marks: 1 ) - Please choose one
The return type of a function that do not return any value must be ________
► float
► int
► void
► double
There may be some functions which do not return any value. For such functions,
the
return_value_type is void
Question No: 8 ( Marks: 1 ) - Please choose one
► JAVA
►B
►C
► FORTRAN
Like member functions, ______ can also access the private data members of a
class.
► Non-member functions
► Friend functions
► Any function outside class
The operator overloading functions for overloading (), [], -> or the assignment
(=) Operators must be declared as class members
► Operators
► Manipulators
► Objects
Similarly flush was a manipulator for which we could write cout << flush that
means flushing the output buffer. So it manipulates the output
► True
► False
► cast
► cost
► const
► True
► False
Just like ordinary methods, constructors can be overloaded in order to make it so
that an object can be created with different attributes specified
Question No: 16 ( Marks: 1 ) - Please choose one
Which of the following function call is correct for the function prototype?
defaultParameters ( int a, int b = 7, char z = ‘*’ );
► 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
► 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
► Decremented
► Incremented
► Multiplied
NULL value has been defined in ______ and _________ header files.
NULL has been defined in the header files stdlib.h and stddef.h.
A Matrix can be composed of ints, floats or doubles as their elements. Best way
is to handle this , _______________
► Use templates
setprecision. This is the parameterized, inline- manipulator that sets the places
after the decimal point.
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++;
cout << x << endl ;
}
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.
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
Time: 90 min
Marks: 58
Question No: 1 ( Marks: 1 ) - Please choose one
► An arithmetic
► Logical
► Relational
► Unary
► isdigit(int c)
► isxdigit(int c )
► tolower(int c)
► Electro-Mechanical, 4
► Electro-physical, 5
► Electro-Mechanical, 7
►*
► ++
►@
►#
When we use manipulators in our program then which header file should be
included?
► iostream.h
► stdlib.h
► stdio.h
► iomanip.h
Question No: 6 ( Marks: 1 ) - Please choose one
► True
► False
► #error
► #define
► #line
► #ndefine
► True
► False
Question No: 9 ( Marks: 1 ) - Please choose one
► Member function
► Non-member function
► Private function
► Public function
► True
► False
► True
► False
The second parameter of operator functions for << and >> are objects of the
class for which we are overloading these operators.
► True
► False
► Zero
► One
► Two
► Three
► True
► False
► True
► False
Which character is inserted at the end of string to indicate the end of string?
► new line
► tab
► null
► carriage return
► calculation
► reading
The object _______________may be used both for file input and file output
► fstream,
► ifstream,
► ofstream,
► Call by value
► Heap
► System Cache
► Stack
► void
► void pointer
► pointer to an object
► void pointer
► int
It is a way of reusing the code when we contain objects of our already written
classes into a new class,
► True
► False
► true
► false
The functions used for dynamic memory allocation return pointer of type ______
► int
► float
► void
► double
Answer:
Write the general syntax for the declaration of pre-increment and post-increment
member operator function.
What is difference between Unary and binary operators and how they can be
overloaded?
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
xxxxxx1500
xxxxx20000
xxxxx30000
xxxxx60000
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming
Solved by Farhat Qudsia & Zuabir Hussain
Marks: 58
Question No: 1 ( Marks: 1 ) - Please choose one
In if structure the block of statements is executed only,
► When the condition is false
► When it contain arithmetic operators
► When it contain logical operators
► When the condition is true
Question No: 2 ( Marks: 1 ) - Please choose one
Header file: fstream.h includes the definition of the stream classes
__________.
► ifstream, fstream, cout
► ifstream, fstream, ofstream
► fstream, cin, cout
► None of the above
Question No: 3 ( Marks: 1 ) - Please choose one
To access the data members of structure _______ is used.
► dot operator (.)
► * operator
► operatorà
► None of given.
Question No: 4 ( Marks: 1 ) - Please choose one
eof( ), bad( ), good( ), clear( ) all are manipulators.
► True
► False
Question No: 5 ( Marks: 1 ) - Please choose one
Which kind of functions can access private member variables of a class?
► Friend functions of the class
► Private member functions of the class
► Public member functions of the class
► Friend, private and public functions
Question No: 6 ( Marks: 1 ) - Please choose one
The return type of operator function must always be void.
► True
► False
Question No: 7 ( Marks: 1 ) - Please choose one
Friend function of a class is ______________ .
► Member function
► Non-member function
► Private function
► Public function
Question No: 8 ( Marks: 1 ) - Please choose one
Function implementation of friend function must be defined outside the class.
► True
► False (any where in the class)
Question No: 9 ( Marks: 1 ) - Please choose one
The normal source of cin object is,
► File
► Disk
► Keyboard
► RAM
Question No: 10 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
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 ;
Question No: 14 ( Marks: 1 ) - Please choose one
The first parameter of operator function for << operator,
► Must be passed by value
► Must be passed by reference
► Can be passed by value or reference
► Must be object of class
Question No: 15 ( Marks: 1 ) - Please choose one
Heap is constantly changing in size.
► 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
► no specific order is followed
► none of the given options.
Question No: 17 ( Marks: 1 ) - Please choose one
Classes defined inside other classes are called ________ classes
► looped
► nested
► overloaded
► none of the given options.
Question No: 18 ( Marks: 1 ) - Please choose one
If we define an identifier with the statement #define PI 3.1415926 then
during the execution of the program the value of PI __________
► can not be replace
► None of the given options
► Remain constant.
► can be changed by some operation
Question No: 19 ( Marks: 1 ) - Please choose one
Which value is returned by the destructor of a class?
► A pointer to the class.
► An object of the class.
► A status code determining whether the class was destructed correctl
► Destructors do not return a value.
Question No: 20 ( Marks: 1 ) - Please choose one
Every class contains _______________.
► Constructor
► Destructor
► Both a constructor and a destructor
► None of the given options
Question No: 21 ( Marks: 1 ) - Please choose one
A template function must have
► One or more than one arguments
► Only one argument
► Zero argument
► None of the given options
http://groups.google.com/group/vuZs/
Question No: 22 ( Marks: 1 ) - Please choose one
Structured Query Language is used for ______________
► Databases Management
► Networks
► Writing Operating System
► none of the given options
Question No: 23 ( Marks: 1 ) - Please choose one
When a call to a user-defined function finishes, the variable defined inside the
function is still in existence.
► True
► False
Question No: 24 ( Marks: 1 ) - Please choose one
The precedence of an operator can be changed through operator overloading.
► True
► False
Question No: 25 ( Marks: 1 ) - Please choose one
A Matrix can be composed of ints, floats or doubles as their elements. Best way
is to handle this , _______________
► Write a separate class to handle each
► Use templates
► Use strings to store all types
► None of the given options
A Matrix can be composed of ints, floats or doubles as their elements. Instead of
handling these data types separately, we can write Matrix class as a template
class and write code once for all native data types.
Write Matrix class as a template class and write code once for all native data
types
Question No: 26 ( Marks: 1 ) - Please choose one
"delete" operator is used to return memory to free store, which is allocated by
the "new" operator.
► True
► False
Question No: 27 ( Marks: 2 )
What is the difference between switch statement and if statement.
Question No: 28 ( Marks: 2 )
How can we initialize data members of contained object at construction time?
Question No: 29 ( Marks: 2 )
How the data members of a class are initialized with meaningful values?
Question No: 30 ( Marks: 2 )
Can we overload new and delete operators?
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 )
Suppose an object of class A is declared as data member of class B.
(i) The constructor of which class will be called first?
(ii) The destructor of which class will be called first?
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 )
Write down the disadvantages of the templates.
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
CS201 - Introduction to programming
Final Term Spring 2010
Operator overloading can be performed through__________________.
► Classes
► Functions
► Operators
► Reference
► malloc
► calloc
► realloc
► free
► #ndefine
list of preprocessors
• #include • #include “filename” • #define • #undef • #ifdef • #ifndef • #if •
#else • #elif • #endif • #error • #line • #pragma • #assert
► False
if we are allocating an array of objects, there is no way to pass arguments to
objects’ constructors. Therefore it is required that the objects that are stored in
such an array have a no-argument constructor.
► False
Question No: 10 ( Marks: 1 ) - Please choose one
We can not define a function as a friend of a Template class.
► True
► False
Class templates can have friends. A class or class template, function, or function
template can be a friend to a template class. Friends can also be specializations
of a class template or function template, but not partial specializations.
► 6,6,8
► 6,8,8
► 6,6,6
The malloc function differs from calloc in the way that the space allocated by
malloc is not initialized and contains any values initially.
Question No: 23 ( Marks: 1 ) - Please choose one
The function free() returns back the allocated memory got thorough calloc and
malloc to _____ .
► stack
► heap
► stack and heap
► None of the given options
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.
Question No: 26 ( Marks: 1 ) - Please choose one
A Matrix can be composed of ints, floats or doubles as their elements. Best way
is to handle this , _______________
► Write a separate class to handle each
► Use templates
► Use strings to store all types
► None of the given options
A Matrix can be composed of ints, floats or doubles as their elements. Instead of
handling these data types separately, we can write Matrix class as a template
class and write code once for all native data types. While writing this template
class, the better approach to write will be, to go with a simple data type (e.g.
double) first to write a Matrix class and then extend it to a template class later.
What will be the output of following code, if user input a number 123?
int input ;
cin >> oct >> input;
cout << hex << input ;
53
Rational: it will take 123 as octal and print it in hex form which is 53.
Answer:
void String::operator = ( const String &other )
{ int length ;
length = other.length();
delete buf;
buf = new char [length + 1];
strcpy( buf, other.buf ); }
FINALTERM EXAMINATION
Spring 2009
· Zero
· One
· Two
· Three
The function arguments must contain at least one generic data type. Normal function declaration is:
return_type function_name(argument_list)
Question No: 21 ( Marks: 1 ) - Please choose one
The default value of a parameter can be provided inside the
· function prototype
· function definition
· both function prototype or function definition
· none of the given options
The default value of a parameter is provided inside the function prototype or function definition.
Question No: 22 ( Marks: 1 ) - Please choose one
While calling function, the arguments are assigned to the parameters from
· left to right
· right to left
· no specific order is followed
· none of the given options
While calling function, the arguments are assigned to the parameters from left to right.
· Zero
· One
· Two
· N arguments
Operators as member functions
Aside from the operators which must be members, operators may be overloaded as member or non-
member functions. The choice of whether or not to overload as a member is up to the programmer.
Operators are generally overloaded as members when they:
change the left-hand operand, or
1. require direct access to the non-public parts of an object.
When an operator is defined as a member, the number of explicit parameters is reduced by one, as the
calling object is implicitly supplied as an operand. Thus, binary operators take one explicit parameter
and unary operators none. In the case of binary operators, the left hand operand is the calling object,
and no type coercion will be done upon it.
2) classes DEFAULT to inheriting privately from base classes. Structures DEFAULT to inheriting
public from base classes. These defaults can be changed so classes can be made to work like structures
and vice versa.
FINALTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming
Question No: 1( Marks: 1 ) - Please choose one
There are mainly -------------------- types of software
► Two
► Three
► Four
► Five
Software is categorized into two main categories
System Software
Application Software
What is the sequence of event(s) when allocating memory using new operator?
► Only block of memory is allocated for objects
► Only constructor is called for objects
► Memory is allocated first before calling constructor
► Constructor is called first before allocating memory
·
If a single object is allocated, operator new is called to allocate memory, and
then the constructor is called to initialize the object.
· If an array of objects is allocated, operator new[] is called to
allocate memory for the whole array, and then the constructor is called for each
element of the array.
· When a single object is deleted, the destructor for the object is
called first, and then operator delete is called to free the memory occupied by
the object.
· When an array of objects is deleted, the destructor for each
element of the array object is called first, and then operator delete[] is called to
free the memory occupied by the array.
► new int(10) ;
► new int[10] ;
► int new(10) ;
► int new[10];
For example, we want to allocate an array of 10 ints dynamically. Then the
statement will be like this: int *iptr; iptr = new int[10]; P# 332
Question No: 17( Marks: 1 ) - Please choose one
The prototype of friend functions must be written ____ the class and its
definition must be written ____
► iostream.h
► stdlib.h
► iomanip.h
► fstream.h
To do stream manipulations, we have to include a header file having the
name iomanip.h. We can understand that iomanip is a short hand for input
output manipulation. P# 427
Question No: 20( Marks: 1 ) - Please choose one
The endl and flush are _______
www.vuzs.net/
► Functions
► Operators
► Manipulators
► Objects
Similarly flush was a manipulator for which we could write cout << flush that
means flushing the output buffer. So it manipulates the output.
P # 435 / 436
Question No: 21( Marks: 1 ) - Please choose one
If we want to use stream insertion and extraction operators with _______ then
we have to overload these operators.
► int, float, double
► objects of class
► int, float, object
► int, char, float
stream extraction operator is used with different data types
of int, double and float. The three lines given above can be written in
one cascading line: cin >> i >> d >> f;
In order to use these insertion ( << ) and extraction ( >> ) operators with
classes, we have to overload these operators. www.vuzs.net
When the compiler overloads the assignment (=) operator by default then
__________
Assignment Operator
What is drawback of writing the definitions of all the functions before main
function?
Question No: 32( Marks: 1 )
How do we provide the default values of function parameters?
Question No: 33( Marks: 2 )
What is difference between endl and \n?
Question No: 34( Marks: 2 )
When does an object get destroyed?
Question No: 35( Marks: 3 )
What is the difference between structure and class?
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?
FINALTERM EXAMINATION
Fall 2009
► 0000128
► 0128128
► 1280000
► 0012800
default alignment is from left due to this it first prints 4 Zeros(setw=7, digit=3 i.e 1-2-8,) 7-3=4 Zeros vuzs
The stream insertion and extraction operators are not already overloaded for _______
► Built-in data types
► User-defined data types
► Both built-in and user-defined types
► None of the given options
www.vuzs.net
The constructors can be overloaded. We can write as many constructors as we require. At one
time, the compiler will call the correct version of the constructor".P# 323 these solutions are
meant to host at vuzs site only
Overloaded new operator function takes parameter of type size_t and returns
► void (nothing)
► void pointer
► object pointer
► int pointer
Also note that the new operator returns a void pointer. Any new operator we write must have
this parameter and return type.
Which of the following is the correct way to declare a variable x of integer type?
► x int ;
► integer x ;
► int x;
► x integer
Reserve words cannot be used as a variable name.
► True
► False
There are few data types in C language. These data types are reserved words of C language.
The reserve words can not be used as a variable manes. P# 17
► Zero
► One
► Two
► Three
The function arguments must contain at least one generic data type. P# 499
We can write overloaded template functions as long as there is use of different number or
type of arguments.. P # 503
We can also define a variable of user define data type (object) as static.
► True
► False
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);
a = (b = (c = (d = (e = 42) ) ) );
void main()
{
int a[5],b[5],c[5],i;
structures do not occupy any memory until it is associated with the structure variable
An 'Identifier' means any name that the user creates in his/her program. These names can be
of variables, functions and labels
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.
If we want a two-way relationship, OtherClass will have to declare ClassOne as a friend
class, resulting in a complete two-way relationship
When memory for a program is allocated at run time then it is called ________
Once the static variables are created, they exist for the life of the program. They do not die.
In the member initialize list, the data members are initialized,
► From left to right
► From right to left
► In the order in which they are defined within class
► None of the given options
The truth tables are very important. These are still a tool available for analyzing logical
expressions.
( Marks: 1 )
What does getline() member function of cin stream do?
Another member function of cin is getline(). It reads a complete buffer i.e. the number of
character specified up to a delimiter we specify. We can write something like:
cin.getline(char *buffer, int buff_size, char delimiter = ‘\n’)
( 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?
Whenever we allocate memory with the new operator, it is our responsibility to de-allocate
this memory after the termination of the program. To do this de-allocation, we have an
operator delete. To de-allocate the memory, allocated with p = new int ; we will write delete
(p) ;
It will not delete the p rather, it will send the memory gotten and pointed by p back to the free
store.
( 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?
Calloc function takes two arguments. The first argument is the required space in terms of
numbers while the second one is the size of the space
Now we have to see what happens when either we ask for too much memory at a time of
non-availability of enough memory on the heap or we ask for memory that is available on the
heap , but not available as a single chunk?. In this case, the call to calloc will fail. When a
call to memory allocation functions fails, it returns a NULL pointer.
( Marks: 3 )
Read the given code and explain code functionality.
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.
this pointer points to the current object.
( Marks: 5 )
What do you mean by garbage collection and how it works in JAVA and C++ ?
JAVA gives the concept of garbage collection with the use of references. Due to this garbage
collection, we are free from the headache of de- allocating the memory. We allocate and use
the memory. When it is no longer in use, JAVA automatically deletes (frees) it through
garbage collection But in C and C++ languages, we have to take care of de-allocating the
memory. In classes where we use dynamic memory, we have to provide destructors to free
this memory. The languages keep evolving, new constructs will keep evolving in existing or
new languages.
( 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.
( Marks: 10 )
FINALTERM EXAMINATION
Fall 2008
CS201- Introduction to Programming
Question No: 1 ( Marks: 1 ) - Please choose one
There are mainly -------------------- types of software
► Two
► Three
► Four
► Five
www.vuzs.net/
We have a manipulator setw (a short for set width), it takes as an argument the width in
number of spaces. So to print our numbers in four spaces we write cout << setw(4) <<
number ;
Question No: 5 ( Marks: 1 ) - Please choose one
eof( ), bad( ), good( ), clear( ) all are manipulators.
► True
► False
Stream Manipulations P# 433
there are two ways of overloading operators, either as class members or non-members. But
these insertion ( << ) and extraction ( >> ) operators cannot be overloaded as members.
P#446
Question No: 14 ( Marks: 1 ) - Please choose one
A template function must have at least ---------- generic data type
► Zero
► One
► Two
► Three
We generally use the variable name as T (T evolves from template). However, it is not
something hard and fast. After the variable name, we start writing the function definition.
The function arguments must contain at least one generic data type. P# 499
As we know, the array index is one less than the size of the array. P# 103
The size of array is 100. but it's index will be from 0 to 99. we will initlize all the
elements of the array to 0.
Question No: 17 ( Marks: 1 ) - Please choose one
The name of an array represents address of first location of array element.
► True
► False
The name of the array is a constant pointer which contains the memory is the address of first
element of the array
For member operator, the object on the left side of the + operator is driving this + operation.
Therefore, the driving object on the left is available by this pointer to + operator function.
But the object on the right is passed explicitly to the + operator as an argument.
Question No: 26 ( Marks: 1 ) - Please choose one
Which one of the following is the declaration of overloaded pre-increment operator
implemented as member function?
► Class-name operator +() ;
► Class-name operator +(int) ;
► Class-name operator ++() ;
► Class-name operator ++(int) ;
Initialization of static data members is done at file scope which means almost at the vuzs
global scope. We initialize it outside of the main.
Question No: 28 ( Marks: 1 ) - Please choose one
Class is a user defined___________.
► data type
► memory referee
► value
► none of the given options.
A class is a user defined data type and it can be used inside other classes in the same way
as native data types are used.
Question No: 29 ( Marks: 1 ) - Please choose one
We can also define a user-defines manipulators.
► True
► False
Parameterized manipulators require one or more arguments. setfill (near the bottom of the
iomanip.h header file) is an example of a parameterized manipulator. You can create your own
parameterized manipulators and your own simple manipulators.
On the stack, automatic variables are being created and destroyed all the time
Question No: 31 ( Marks: 1 )
How do we provide the default values of function parameters?
Question No: 32 ( Marks: 1 )
Why do java consider pointer as dangerous
JAVA, describe pointers as dangerous . if we assign a memory through a pointer where the
pointer is destroyed, the memory remains allocated and is wasted. To address these things,
there are only references in JAVA instead of pointers. JAVA gives the concept of garbage
collection with the use of references. Due to this garbage collection, we are free from the
headache of de- allocating the memory. We allocate and use the memory. When it is no
longer in use, JAVA automatically deletes (frees) it through garbage collection
Question No: 33 ( Marks: 2 )
What is memory leak?
There is a requirement that if the constructor of a class allocates the memory, it is necessary
to write a destructor of that class. We have to provide a destructor for that class, so that when
that object ceases to exist, the memory allocated by the constructor, is returned to the free
store. It is critically important. Otherwise, when the object is destroyed, there will be an
unreferenced block of memory. It cannot be used by our program or by any other program.
It’s a memory leak that should be avoided.
Question No: 34 ( Marks: 2 )
What does optimization the of code means?
Optimization is the process of transforming a piece of code to make more efficient
without changing its output or side-effects. The only difference vuzs visible to the code’s
user should be that it runs faster and/or consumes less memory.
Question No: 35 ( Marks: 3 )
What is the difference between structure and class?