CS201 Objective Mega File-1 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 102

CS201 Latest Solved MCQs

http://vustudents.ning.com
http://vustudents.ning.com

Quiz Start Time: 09:34 PM Time Left 82


sec(s)

Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1


While developing a program; should we think about the user interface? //handouts main
reusability hay..us ki yahan option hi nahi hay
Select correct option:

Yes

No

Quiz Start Time: 09:34 PM Time Left 75


sec(s)

Question # 2 of 10 ( Start time: 09:35:20 PM ) Total Marks: 1


A character is stored in the memory in _________
Select correct option:

byte

integer

string

None of the given

http://vustudents.ning.com 1
CS201 Latest Solved MCQs
http://vustudents.ning.com
Quiz Start Time: 09:34 PM

Question # 3 of 10 ( Start time: 09:36:21 PM ) Total Marks: 1


These functions seekg() and seekp() requires an argument of type ____________to let
them how many bytes to move forward or backward.
Select correct option:

int

short

long

double

Quiz Start Time: 09:34 PM Time Left 85


sec(s)

Question # 4 of 10 ( Start time: 09:37:30 PM ) Total Marks: 1


dereferencing operator is represented by _______
Select correct option:

None of the given

http://vustudents.ning.com 2
CS201 Latest Solved MCQs
http://vustudents.ning.com
Quiz Start Time: 09:34 PM Time Left 86
sec(s)

Question # 5 of 10 ( Start time: 09:38:55 PM ) Total Marks: 1


______________ transfers the executable code from main memory to hard disk.

Select correct option:

Loader

Debugger

Compiler

Linker

Quiz Start Time: 09:34 PM Time Left 85


sec(s)

Question # 6 of 10 ( Start time: 09:40:21 PM ) Total Marks: 1


When the logical operator OR (||) combine two expressions exp1 and exp2 then the result
will be false only, //bitwise “or” applies here….
Select correct option:

When both exp1 and exp2 are true

When both exp1 and exp2 are false

When exp1 is true and exp2 is false

When exp1 is false and exp2 is true

http://vustudents.ning.com 3
CS201 Latest Solved MCQs
http://vustudents.ning.com
Quiz Start Time: 09:34 PM Time Left 79
sec(s)

Question # 7 of 10 ( Start time: 09:41:43 PM ) Total Marks: 1


suppose we have int y[10]; To access the 4th element of the array we write_________
Select correct option:

y[4];

y[3];

y[2];

none of given

Quiz Start Time: 09:34 PM Time Left 82


sec(s)

Question # 8 of 10 ( Start time: 09:43:10 PM ) Total Marks: 1


we have opened a file stream myfile for reading (getting), myfile.tellg () gives us the
current get position of the file pointer. It returns a whole number of type___________
Select correct option:

long

int

short

double

http://vustudents.ning.com 4
CS201 Latest Solved MCQs
http://vustudents.ning.com
Quiz Start Time: 09:34 PM Time Left 80
sec(s)

Question # 9 of 10 ( Start time: 09:44:42 PM ) Total Marks: 1


ofstream is used for________
Select correct option:

Input file stream

Output file stream

Input and output file stream

All of the given

Quiz Start Time: 09:34 PM Time Left 80


sec(s)
http://vustudents.ning.com

Question # 10 of 10 ( Start time: 09:46:11 PM ) Total Marks: 1


A structure is a collection of _____________under a single name.
Select correct option:

values

variables

data

None of the given

http://vustudents.ning.com 5
CS201 Latest Solved MCQs
http://vustudents.ning.com

Question No: 1 ( Marks: 1 ) - Please choose one


In C/C++ the string constant is enclosed ……………. corrected r red one
► In curly braces
► In small braces
► In single quotes
► In double quotes

Question No: 2 ( Marks: 1 ) - Please choose one


The size of int data type is
► 1 bytes
► 2 bytes
► 3 bytes
► 4 bytes

Question No: 3 ( Marks: 1 ) - Please choose one


In Flow chart process is represented by

► Rectangle
► Arrow symbol
► Oval
► Circle

Question No: 4 ( Marks: 1 ) - Please choose one


If the break statement is missed in switch statement then,// a break statement with no
label always completes abruptly, the reason being a break with no label. If no switch,
while, do, or for statement in the immediately enclosing method, constructor or
initializer encloses the break statement, a compile-time error occurs.

► The compiler will give error


► This may cause a logical error
► No effect on program
► Program stops its execution

Question No: 5 ( Marks: 1 ) - Please choose one


When we are using const keyword with a variable x then initializing it at the time of
declaration is,

► Must
► Optional
► Not necessary
► A syntax error

http://vustudents.ning.com 6
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 6 ( Marks: 1 ) - Please choose one
Which of the following is the correct way to assign an integer value 5 to element of a
matrix say ‘m’ at second row and third column?

► m[2][3] = 5 ;

► m[3][2] = 5 ;

► m[1][2] = 5 ;
► m[2][3] = ‘5’;

Question No: 7 ( Marks: 1 ) - Please choose one


How many total elements must be in two-dimensional array of 3 rows and 2 columns?

►4
►5
►6
►7

Question No: 8 ( Marks: 1 ) - Please choose one


Which of the following is the correct statement for the following declaration?
const int *ptr.
►ptr is a constant pointer

►ptr is constant integer pointer

►ptr is a constant pointer to int

►ptr is a pointer to const int

Question No: 9 ( Marks: 1 ) - Please choose one


Consider the following code segment. What will be the output of this code segment?As
arrays starts from 0 index………at 1st position is 3………n at position 4th is 5…
……5-3=2

int arr[6] = {2, 3, 7, 4, 5, 6} ;


int *ptr1 =&arr[1] ;
int *ptr2 = &arr[4] ;
cout << (ptr2-ptr1) ;

►3

http://vustudents.ning.com 7
CS201 Latest Solved MCQs
http://vustudents.ning.com
►9
► 12
►2

Question No: 10 ( Marks: 1 ) - Please choose one


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: 11 ( Marks: 1 ) - Please choose one


C is a/an ______ language
►low level
►object based
►object oriented
►function oriented

Question No: 13 ( Marks: 1 ) - Please choose one


The variables having a name, type and size are just like empty boxes.
►False
►True

Question No: 14 ( Marks: 1 ) - Please choose one

What's wrong with this for loop?


for (int k = 2, k <=12, k++)

► the increment should always be ++k


► the variable must always be the letter i when using a for loop
► there should be a semicolon at the end of the statement
► the commas should be semicolons

Question No: 15 ( Marks: 1 ) - Please choose one


Most efficient method of dealing with structure variables is to define the structure
globally

►True
 ►False

http://vustudents.ning.com 8
CS201 Latest Solved MCQs
http://vustudents.ning.com

Question No: 16 ( Marks: 1 ) - Please choose one


Syntax of union is identical to ______
►Structure
►Class
►Function
►None of the given options

FINALTERM EXAMINATION
Fall 2008
CS201- Introduction to Programming
Time: 120 min
Marks: 75
Question No: 1 ( Marks: 1 ) - Please choose one

There are mainly -------------------- types of software.//

► Two
► Three
► Four
► Five

Question No: 2 ( Marks: 1 ) - Please choose one

seekg() and write() are functionally _________________ .//


Write() Writes a specified number of bytes from a memory location to the file.
seekg() Moves the file position indicator to a specific location in the file.
The Position property of TFileStream simplifies seeking in a file and performs the
same function as the ifstream methods tellg() and seekg(). You can read Position to
determine the current file position, or you can write to Position to move the file
position.

► Different
► Identical
► Two names of same function
► None of the above

Question No: 3 ( Marks: 1 ) - Please choose one


When a pointer is incremented, it actually jumps the number of memory addresses

► According to data type


► 1 byte exactly
► 1 bit exactly
► A pointer variable can not be incremented

http://vustudents.ning.com 9
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 4 ( Marks: 1 ) - Please choose one

setw is a parameterized manipulator.

► True
► False

Question No: 5 ( Marks: 1 ) - Please choose one

eof( ), bad( ), good( ), clear( ) all are manipulators.

► True
► False

Question No: 6 ( Marks: 1 ) - Please choose one

In functions that return reference, use __________variables.

► Local
► Global
► Global or static
► None of the given option

Question No: 7 ( Marks: 1 ) - Please choose one

The declarator of Plus (+) member operator function is


//not confirmed

► Class-Name operator + (Class-Name rhs)


► operator Class-Name + ( )
► operator Class-Name + ( rhs)
► Class-Name operator + ( )

Question No: 8 ( Marks: 1 ) - Please choose one

The compiler does not provide a copy constructor if we do not provide it……….

//Normally it provides but in some cases of classes it is good practice to provide user
define copy constructor…
► True
► False

Question No: 9 ( Marks: 1 ) - Please choose one

http://vustudents.ning.com 10
CS201 Latest Solved MCQs
http://vustudents.ning.com
What is the functionality of the following syntax to delete an array of 5 objects named arr
allocated using new operator?
delete arr ;

► Deletes all the objects of array


► Deletes one object of array
► Do not delete any object
► Results into syntax error

Question No: 10 ( Marks: 1 ) - Please choose one

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

Question No: 11 ( Marks: 1 ) - Please choose one


What is the sequence of event(s) when deallocating memory using delete operator?

► Only block of memory is deallocated for objects


► Only destructor is called for objects
► Memory is deallocated first before calling destructor
► Destructor is called first before deallocating memory

Question No: 12 ( Marks: 1 ) - Please choose one

new and delete operators cannot be overloaded as member functions.

► True
► False

Question No: 13 ( Marks: 1 ) - Please choose one

The operator function of << and >> operators are always the member function of a class.

► True
► False

Question No: 14 ( Marks: 1 ) - Please choose one

http://vustudents.ning.com 11
CS201 Latest Solved MCQs
http://vustudents.ning.com
A template function must have at least ---------- generic data type

► Zero
► One
► Two
► Three

Question No: 15 ( Marks: 1 ) - Please choose one


If we do not mention any return_value_type with a function, it will return an _____
value.

► int
► void
► double
► float

Question No: 16 ( Marks: 1 ) - Please choose one

Suppose a program contains an array declared as int arr[100]; what will be the size of
array?

►0
► 99
► 100
► 101

Question No: 17 ( Marks: 1 ) - Please choose one


The name of an array represents address of first location of array element.

► True
► False

Question No: 18 ( Marks: 1 ) - Please choose one


Reusing the variables in program helps to save the memory

► True
► False

Question No: 19 ( Marks: 1 ) - Please choose one


Which of the following option is true about new operator to dynamically allocate
memory to an object?
// new is an operator that allows dynamic memory allocation on the heap. Except for a
form called the "placement new", new attempts to allocate enough memory on the heap
for the new data and, if successful, returns the address to the newly allocated memory.
However if new can not allocate memory on the heap it will throw an exception of type
std::bad_alloc. This removes the need to explicitly check the result of an allocation.

http://vustudents.ning.com 12
CS201 Latest Solved MCQs
http://vustudents.ning.com
► The new operator determines the size of an object
► Allocates memory to object and returns pointer of valid type
► Creates an object and calls the constructor to initialize the object
► All of the given options

Question No: 20 ( Marks: 1 ) - Please choose one


new and delete are _____ whereas malloc and free are _____.

► Functions, operators
► Classes, operators
► Operators, functions
► Operators, classes

Question No: 21 ( Marks: 1 ) - Please choose one

Like member functions, ______ can also access the private data members of a class.
► Non-member functions
► Friend functions
► Any function outside class
► None of the given options

Question No: 22 ( Marks: 1 ) - Please choose one

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.

Question No: 23 ( Marks: 1 ) - Please choose one


The operator function overloaded for an Assignment operator (=) must be
► Non-member function of class
► Member function of class
► Friend function of class
► None of the given options

Question No: 24 ( Marks: 1 ) - Please choose one


For non-member operator function, object on left side of the operator may be

► Object of operator class


► Object of different class
► Built-in data type
► All of the given options

http://vustudents.ning.com 13
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 25 ( Marks: 1 ) - Please choose one
The operator function will be implemented as _____, if obj1 drive the - operator whereas
obj2 is passed as arguments to - operator in the statement given below.
obj3 = obj1 - obj2;

► Member function
► Non-member function
► Friend function
► None of the given options

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) ;

Question No: 27 ( Marks: 1 ) - Please choose one

The static data members of a class are initialized _______

► at file scope
► within class definition
► within member function
► within main function

Question No: 28 ( Marks: 1 ) - Please choose one

Class is a user defined___________.

► data type
► memory referee
► value
► none of the given options.

Question No: 29 ( Marks: 1 ) - Please choose one


We can also define a user-defines manipulators.

► True
► False

http://vustudents.ning.com 14
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 30 ( Marks: 1 ) - Please choose one
Automatic variable are created on ________.

► Heap
► Free store
► static storage
► stack

Current

Question No: 1 ( Marks: 1 ) - Please choose one

Compiler is a

► System software
► Application Software
► Driver
► Editor

Question No: 2 ( Marks: 1 ) - Please choose one

Operating System is

► An application software
► System Software
► Computer Language
► Interpreter

Question No: 3 ( Marks: 1 ) - Please choose one

Which one is the correct syntax for defining an identifier PI with preprocessor directive?

► #define PI 3.1415926;
► #define PI 3.1415926
► #define PI = 3.1415926 ;
► #define PI = 3.1415926

Question No: 4 ( Marks: 1 ) - Please choose one

Character strings are arrays of characters that can store

► Only one character


► Limited number of characters
► Number of characters specified.
► None of the given option

http://vustudents.ning.com 15
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 5 ( Marks: 1 ) - Please choose one
Which of the following is NOT a preprocessor directive?

► #error
► #define
► #line
► #ndefine

Question No: 6 ( 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: 7 ( Marks: 1 ) - Please choose one


Let suppose int a, b, c, d, e;, a = b = c = d = e = 42;
This can be interpreted by the complier as:// assignment is right-associative.

► a = (b = (c = (d = (e = 42))));
► (a = b = (c = (d = (e = 42))));
► a = b = (c = (d = (e = 42)));
► (a = b) = (c = d) = (e = 42);

Question No: 8 ( Marks: 1 ) - Please choose one

Friend function of a class is ______________ . http://vustudents.ning.com

► Member function

► Non-member function

► Private function

► Public function

Question No: 9 ( Marks: 1 ) - Please choose one

Function implementation of friend function must be defined outside the class.

► True
► False

http://vustudents.ning.com 16
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 10 ( Marks: 1 ) - Please choose one
When we define an array of objects then,

► Constructor will be called once for whole array


► Constructor will be called for each object of the array
► Constructor will never call
► Depends on the size of array

Question No: 11 ( Marks: 1 ) - Please choose one

The stream objects cin and cout are included in which header file?
► iostream.h
► fstream.h
► istream.h
► ostream.h

Question No: 12 ( Marks: 1 ) - Please choose one

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

Question No: 13 ( Marks: 1 ) - Please choose one


Missing semicolon ‘;’ at the end of C++ statement is

► Logical error
► Syntax error
► Runtime error
► None of the given options

Question No: 14 ( Marks: 1 ) - Please choose one

An array stores the numbers into consecutive memory locations.

► True
► False

http://vustudents.ning.com 17
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 15 ( Marks: 1 ) - Please choose one

The template functions do NOT promote the code reuse

► True
► False

Question No: 16 ( Marks: 1 ) - Please choose one

What will be the correct syntax for initialization of pointer ptr of type int with variable x?

► int ptr = &x ;


► int ptr = x ;
► int *ptr = &x ;
► int ptr* = &x ;

Question No: 17 ( Marks: 1 ) - Please choose one

Which of the following function calling mechanism is true for the function prototype
given below?
float func(float &);

► Call by value
► Call by reference using pointer
► Call by reference using reference variable
► None of the given options

Question No: 18 ( Marks: 1 ) - Please choose one

If overloaded plus operator is implemented as non-member function then which of the


following statement will be true for the statement given below?
obj3 = obj1 + obj2 ;

► obj2 will be passed as an argument to + operator whereas obj2 will drive the
+ operator
► obj1 will drive the + operator whereas obj2 will be passed as an argument to +
operator
► Both objects (obj1, obj2) will be passed as arguments to the + operator
► Any of the objects (obj1, obj2) can drive the + operator

http://vustudents.ning.com 18
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 19 ( Marks: 1 ) - Please choose one
Which of the following object(s) will call the member operator function within the
statement given below?
obj1=obj2+obj3;

► Object obj1
► Object obj2
► Object obj3
► Any of the object

Question No: 20 ( Marks: 1 ) - Please choose one

For cin, the source is normally a ________ and destination can be ______.

► File, native data type


► Disk, user-define type
► Keyboard, variable
► File, user-define type

Question No: 21 ( Marks: 1 ) - Please choose one

The static data members of a class will be ________


► shared by objects
► created for each object
► initialized within class
► initialized within main function

Question No: 22 ( Marks: 1 ) - Please choose one

Which of the following function cannot be overloaded?


► Member functions
► Utility functions
► Constructor
► Destructor

Question No: 23 ( Marks: 1 ) - Please choose one

The region of memory, available for allocation at run time in C language is called
________ memory whereas in C++ language is called as ________________.

► Heap, Stack
► Stack, Free Store
► Heap, Free Store
► None of above

http://vustudents.ning.com 19
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 24 ( Marks: 1 ) - Please choose one

A variable which is defined inside a function is called

► Automatic variable
► Global variable
► Functional variable
► None of the given option

Question No: 25 ( Marks: 1 ) - Please choose one

The default copy constructor provides member wise assignment.


► True
► False

Question No: 26 ( Marks: 1 ) - Please choose one

The code is written to __________ the program.


► implement
► design
► analysis
► none of the given options.

Question No: 27 ( 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: 28 ( Marks: 1 ) - Please choose one

To avoid dangling reference, always return the reference of a local variable from a
function.

► True
► False

Question No: 29 ( Marks: 1 ) - Please choose one

Analysis is the -------------- step in designing a program.

► Last
► Middle
► Post Design

http://vustudents.ning.com 20
CS201 Latest Solved MCQs
http://vustudents.ning.com
► First

Question No: 30 ( 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: 1 ( Marks: 1 ) - Please choose one

In C/C++ if we define an array of size eight (8) i.e. int Arr [8]; then the last element of
this array will be stored at,

► Arr[0]
► Arr[8]
► Arr[7]
► Arr[-1]

Question No: 2 ( Marks: 1 ) - Please choose one

When an array is passed to a function then default way of passing this array is,

► By data
► By reference
► By value
► By data type

Question No: 3 ( Marks: 1 ) - Please choose one

Array is a data structure which store

► Memory addresses
► Variables
► Data Type
► Data

Question No: 4 ( Marks: 1 ) - Please choose one

We can also create an array of user define data type.

► True
► False

http://vustudents.ning.com 21
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 5 ( Marks: 1 ) - Please choose one

When we define an array of objects then,

► Destructor will call once for whole array


► Destructor will call for each object of the array
► Destructor will never call
► Depends on the size of array

Question No: 6 ( Marks: 1 ) - Please choose one

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

Question No: 7 ( Marks: 1 ) - Please choose one

We can delete an array of objects without specifying [] brackets if a class is not doing
dynamic memory allocation internally.

► True
► False

Question No: 8 ( Marks: 1 ) - Please choose one

The second parameter of operator functions for << and >> are objects of the class for
which we are overloading these operators.

► True
► False

Question No: 9 ( Marks: 1 ) - Please choose one

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 ;

http://vustudents.ning.com 22
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 10 ( Marks: 1 ) - Please choose one

Default mechanism of function calling in case of array is _____ and in case of variable is
___. http://vustudents.ning.com

► Call by value, call by reference


► Call by referene, call by reference
► Call by reference, call by value
► Call by value, call by value

Question No: 11 ( Marks: 1 ) - Please choose one

What does STL stand for?

► Source template library


► Standard template library
► Stream template library
► Standard temporary library

Question No: 12 ( Marks: 1 ) - Please choose one

Skill(s) that is/are needed by programmers _______________________.

► Paying attention to detail


► Think about the reusability
► Think about user interface
► All of the given options

Question No: 13 ( Marks: 1 ) - Please choose one

For which array, the size of the array should be one more than the number of elements in
an array?

► int
► double
► float
► char

http://vustudents.ning.com 23
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 14 ( Marks: 1 ) - Please choose one

new and delete are _____ whereas malloc and free are _____.

► Functions, operators
► Classes, operators
► Operators, functions
► Operators, classes

Question No: 15 ( Marks: 1 ) - Please choose one

Friend functions are _____ of a class.

► Member functions
► Public member functions
► Private member functions
► Non-member functions

Question No: 16 ( Marks: 1 ) - Please choose one

The prototype of friend functions must be written ____ the class and its definition must
be written ____

► inside, inside the class


► inside, outside the class
► outside, inside the class
► outside, outside the class

Question No: 17 ( Marks: 1 ) - Please choose one

If overloaded plus operator is implemented as non-member function then which of the


following statement will be true for the statement given below?
obj3 = obj1 + obj2 ;

► obj2 will be passed as an argument to + operator whereas obj2 will drive the
+ operator
► obj1 will drive the + operator whereas obj2 will be passed as an argument to +
operator
► Both objects (obj1, obj2) will be passed as arguments to the + operator
► Any of the objects (obj1, obj2) can drive the + operator

http://vustudents.ning.com 24
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 18 ( 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) ;

Question No: 19 ( Marks: 1 ) - Please choose one

For cin, the source is normally a ________ and destination can be ______.

► File, native data type


► Disk, user-define type
► Keyboard, variable
► File, user-define type

Question No: 20 ( Marks: 1 ) - Please choose one

We can also do conditional compilation with preprocessor directives.


► True
► False

Question No: 21 ( Marks: 1 ) - Please choose one

The programs, in which we allocate static memory, run essentially on ________

► Heap
► System Cache
► None of the given options
► Stack

Question No: 22 ( 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.

http://vustudents.ning.com 25
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 23 ( 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: 24 ( Marks: 1 ) - Please choose one

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: 25 ( Marks: 1 ) - Please choose one

With user-defined data type variables (Objects), self assignment can produce
__________.

► Syntax error
► Logical error
► Link error
► Non of the given options

Question No: 26 ( Marks: 1 ) - Please choose one

Assignment operator is used to initialize a newly declared object from existing object.

► True
► False

Question No: 27 ( Marks: 1 ) - Please choose one

When an object of a class is defined inside an other class then,

► Constructor of enclosing class will be called first


► Constructor of inner object will be called first
► Constructor and Destructor will be called simultaneously
► None of the given options

http://vustudents.ning.com 26
CS201 Latest Solved MCQs
http://vustudents.ning.com
Question No: 28 ( Marks: 1 ) - Please choose one

In the member initializer 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

Question No: 29 ( Marks: 1 ) - Please choose one

new operator allocates memory from free store and return _____________.

► A pointer
► A reference
► An integer
► A float

Question No: 30 ( Marks: 1 ) - Please choose one

"new" and "delete" keywords are _____________ in C++ language.


► Built-in- Function
► Operators
► Memory Allocation Function
► None of the given options

http://vustudents.ning.com 27
Almost 300 Solved MCQs of CS201
By

http://vustudents.ning.com
Default constructor takes _________.

one parameter
two parameters
no parameters
character type parameter

All the preprocessors directives start with ________.

$
&
#
_

The members of a class declared with the keyword struct are _____________by default.

static
private
protected
public

Loops are _______________ Structure


Decision
Sequential
Repetition
None of the given options

We cannot use ______________ pointer for storing and reading data from it.

NULL
integer
double
zero

http://vustudents.ning.com 1
When an object of a class is defined inside another class then,

Destructor of enclosing class will be called first


Destructor of inner object will be called first
Constructor and Destructor will be called simultaneously
None of the given options
Consider the following code segment. Which of the following will be called while
executing code at line 2? String s1 , s2; s1 = s2 ;

Copy constructor
Default constructor
Assignment operator
Parameterized constructor

We cannot increment ________________.

pointers
arrays
references
variables

In statement Matrix m2 = m1 ;

Assignment operator is being used


Copy constructor is being used.
Statement has syntax error
None of the given options

From the following; which on is the correct syntax of an array declaration: array size is 5
and it is of float data type?

float [5] name;


name[5] float;
float name[5];
None of the given options

If an array has 50 elements, what is allowable range of subscripts?


0 – 49
1 – 49
0 – 50
1 – 50

http://vustudents.ning.com 2
A structure is a collection of _____________under a single name.

values
variables
data
None of the given

If a function has not been declared before its definition, It is a

logical error
syntax error
run time error
None of these

When the if statement consists more than one statement then enclosing these statement in
curly braces is,

Not required
Good programming
Relevant
Must

__________ allow us to have a memory location and use it as int or char interchangeably

structures
union
construct
None of the given

In Analysis, we try to have a______________

Determined the inputs


Break up of problem
Precise problem statement
None of the given

_______________function give the position of the next character to be read from that
file.

tellp()
tellg()
seekg()
seekp()

http://vustudents.ning.com 3
Pointers store the ____________________ http://vustudents.ning.com

value of a variable
memory address
characters
None of the given

In order to get the right most digit of a number, we divide this number by 10 and take its

Remainder
Quotient
Divisor
None of the given options

___________ Returns true if c is a digit and false otherwise.

int isalpha( int c )


int isalnum( int c )
int isxdigit( int c )
int isdigit( int c )

If int a = 50; then the value of a/= 3; will be,

15
18
16
17

_______________________ contains functions for manipulations of character data.

ctype.h
iostream.h
string.h
None of the given
____________________ Returns true if c is a digit or a letter and false otherwise.

int isalpha( int c )


int isalnum( int c )
int isxdigit( int c )
int isdigit( int c )

http://vustudents.ning.com 4
If int sum = 54; Then the value of the following statement is sum = sum - 3 ;

52
50
51
57

To get the value stored at a memory address, we use the________________

referencing operator
dereferencing operator
simple operator
None of the given

In C/C++; by default arguments are passed by _______ to a function.

Reference
Value
Type
Data

The string in the array is terminated by a _______

zero
nil
null
one

Structures are syntactically defined with the word_____________.

struc
struct
structure
None of the given

C is widely known as development language of _______ operating system.

Linux
Unix
Windows
Mac OS

http://vustudents.ning.com 5
http://vustudents.ning.com

At the___________, we try to break up the problem into functional units

analysis phase
design phase
Implementation phase
None of the given

While developing a program; should we think about the user interface?

Yes
No

What will be the result of arithmetic expression 5+25/5*5?

45
6
30
9

Why we use "cin"? http://vustudents.ning.com

To send data to printer


To read data from keyboard
To display message
To display output on the screen

_________operator uses the sign ^.

Bit-wise OR
Exclusive OR
AND Operator
NOT operator

http://vustudents.ning.com 6
C++ is a_________________ language.

High level
Low level
Machine
Fourth Generation

12 & 8 = (1000) 2 =________. & is used to AND two numbers bit-wise

4
8
6
12

From the following; which one is used as an assignment operator?

Equal sign ‘=’


Double equal sign ‘==’
Both equal and double equal sign
None of the given options

What will be the value of ‘a’ and ‘b’ after executing the following statements? int a = 9;
int b = a++; cout<<

10,9
9,10
9,9
10,10

These functions seekg() and seekp() requires an argument of type ____________to let
them how many bytes to move forward or backward.

int
short
long
double

http://vustudents.ning.com 7
A character is stored in the memory in _________

byte
integer
string
None of the given

dereferencing operator is represented by _______

*
+

None of the given

______________ transfers the executable code from main memory to hard disk.

Loader
Debugger
Compiler
Linker

When the logical operator OR (||) combine two expressions exp1 and exp2 then the result
will be false only,

When both exp1 and exp2 are true


When both exp1 and exp2 are false
When exp1 is true and exp2 is false
When exp1 is false and exp2 is true

suppose we have int y[10]; To access the 4th element of the array we write_________

y[4];
y[3];
y[2];
none of given

http://vustudents.ning.com 8
we have opened a file stream myfile for reading (getting), myfile.tellg () gives us the
current get position of the file pointer. It returns a whole number of type___________

long
int
short
double

ofstream is used for________

Input file stream


Output file stream
Input and output file stream
All of the given

A structure is a collection of _____________under a single name.

values
variables
data
None of the given

The first character of a variable name must be an alphabet or

► Underscore

► Digit

► Special character

► Comma

Suppose int multi[5][10]; when we are using **multi , it means,

► Single dereferencing

► Single referencing

► Double referencing

► Double dereferencing

http://vustudents.ning.com 9
eof( ), bad( ), good( ), clear( ) all are manipulators.

► True

► False

http://vustudents.ning.com

It is possible to return an object from a function through this pointer.

► True

► False

Function implementation of friend function must be defined outside the class.

► True

► False

The default scope for members of structures is public whereas the default visibility for
class members is private.

► True

► False

The operator function of << and >> operators are always the member function of a class.

► True

► False

http://vustudents.ning.com 10
How many bytes are occupied by declaring following array of characters?

char str[] = “programming”;

► 10

► 11

► 12

► 13

What does STL stand for?

► Source template library

► Standard template library

► Stream template library

► Standard temporary library

Which of the following array is the most suitable for storing a matrix structure

► Single-dimensional array

► Two-dimensional array

► Three-dimensional array

► Four-dimensional array

What will be the output of following code segment?

main(){

int x = 5 ;

int x = 4 ;

http://vustudents.ning.com 11
cout << x << “,” ;

cout << x ;

► 5, 5

► 4, 4

► 4, 5

► 5, 4

Single line comments explaining code would be preceded like in the following example.

► /*

► //

►/

► //*

The ________ statement interrupts the flow of control.

► switch

► continue

► goto

► break

http://vustudents.ning.com 12
Which of the following will be the correct function call for function prototype given
below?

int func (int &);

► func(int num);

► func(&num);

► func(num);

► func(*num);

If there is a symbol (& sign) used with the variable name followed by data type then it
refers to _____ and if & is being used with variable name then it refers to _____.

► Address of variable, reference variable

► Reference variable, value of variable

► Reference variable, address of variable

► Address of variable, value of variable

Which of the following operator the compiler overloads for objects by default?

► + operator

► - operator

► = operator

► == operator

http://vustudents.ning.com 13
If overloaded plus operator is implemented as member function then which of the
following option will be true for the statement given below?

obj3 = obj1 + obj2 ;

► obj1 will be passed as an argument to + operator whereas obj2 will drive the +
operator

► obj1 will drive the + operator whereas obj2 will be passed as an argument to +
operator

► Both objects (obj1, obj2) will be passed as arguments to the + operator

► Any of the objects (obj1, obj2) can drive the + operator

The operator function will be implemented as _____, if both objects (obj1, obj2) are
passed as arguments to - operator in the statement given below.

obj3 = obj1 - obj2;

► friend function

► member function

► non-member function

► either non-member or friend function

The input/output streams cin and cout are ________ therefore have _______.

► Structures, function

► Objects, member functions

► Functions, objects

► None of the given options

http://vustudents.ning.com 14
What will be the output of following statement?

cout << setfill(‘0’) << setw(7) << 128

► 0000128

► 0128128

► 1280000

► 0012800

http://vustudents.ning.com

The static data members of a class will be ________

► shared by objects

► created for each object

► initialized within class

► initialized within main function

Which of the following is used for allocating space for static variables?

► Heap

► Static storage area

► Free store

► Stack

http://vustudents.ning.com 15
Templates provide way of abstracting ______________ information.

► type

► data

► method

► access

A pointer is a special type of variable that contain ___________

► Memory Address

► Data values

► Both Values and Memory

► None of given of options

Which is NOT a protection level provided by classes in C++?

► protected

► hidden

► private

► public

Users must not know about ____________________.

► Functions Name within Class

► Class implementation of Functionality and Interfaces

► Methods Functionality with in Class

► None of the given options

http://vustudents.ning.com 16
Assignment operator is used to initialize a newly declared object from existing object

► True

► False

The operator function for << (stream insertion) >> and stream extraction must be

► Member function of class

► Non-member function of class

► Both member and non-member function

► None of the given options

http://vustudents.ning.com

A template function must have

► One or more than one arguments

► Only one argument

► Zero arguments

► None of the given options

Truth tables are used for analyzing ___________.

► logical expressions

► arithmetic expressions

► both logical and arithmetic expressions

► none of the given options.

http://vustudents.ning.com 17
Which of the following array is the most suitable for storing a matrix structure?

► Single-dimensional array

► Two-dimensional array

► Three-dimensional array

► Four-dimensional array

How many bytes are occupied by declaring following array of characters?


char str[] = “programming”;

► 10

► 11

► 12

► 13

11 bytes for 11characters of word programming and 1 for '\n'

When we do dynamic memory allocation in the constructor of a class, then it is necessary


to provide a destructor.

► True

► False

http://vustudents.ning.com 18
The prototype of friend functions must be written ____ the class and its definition must
be written ____
► inside, inside the class

► inside, outside the class

► outside, inside the class

► outside, outside the class

Copy constructor becomes necessary while dealing with _______allocation in the class.

► Dynamic memory
► Static memory
► Both Dynamic and Static memory
► None of the given options

Dealing with structures and functions passing by reference is the most economical
method

► True
► False

1st...what is the function of flush commond?

1): when we specify the buffer size, normally the operating system or compiler does this
for us. A typical size of buffer is 512 bytes. When the information is of 512 byte size,
output will take place. But in the program, we may want at some point that whatever is in
the buffer, show them. For that purpose the normal mechanism is flush. Flush the stream.
The flush command forces the data from the buffer to go to its destination which is
normally a screen or file and make the buffer empty. Lec 34

2nd...what are the types of tamplates?


a template is a sketch to draw some shape or figure.
There are two different types of templates in C++ language i.e.’ function templates
and class templates. Lec 41

http://vustudents.ning.com 19
The declarator of Plus (+) member operator function is

► Class-Name operator + (Class-Name rhs)


► operator Class-Name + ( )
► operator Class-Name + ( rhs)
► Class-Name operator + ( )

12 & 8 = (1000) 2 =________. & is used to AND two numbers bit-wise

Select correct option:

4
8
6
12

Is ka answer 8 hy, see handouts page number 246.

Truth table for &

Bit1 Bit2 Bit1 & Bit2


1 1 1
1 0 0
0 1 0
0 0 0

Therefore, when we apply the conditions, we get

12 = 1 1 1 0 (binary conversion of 12)


8 = 1 0 0 0 (binary conversion of 8)
------------------------------------------------------------
1 0 0 0, which is equals to 8
The reserved words public and private comes under the category

Which of the following operators can not be overloaded?


1) :new
2) :delete
3) :+=
4) :sizeof

http://vustudents.ning.com 20
The reserved words public and private comes under the category

1) :structures
2) :strings
3) :accessibility modifiers
4) :types of functions

Question No: 10 ( Marks: 1 ) - Please choose one


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

Question No: 11 ( Marks: 1 ) - Please choose one


What is the sequence of event(s) when deallocating memory using delete operator?

► Only block of memory is deallocated for objects


► Only destructor is called for objects
► Memory is deallocated first before calling destructor
► Destructor is called first before deallocating memory

Question No: 12 ( Marks: 1 ) - Please choose one


new and delete operators cannot be overloaded as member functions.
► True
► False

Question No: 13 ( Marks: 1 ) - Please choose one


The operator function of << and >> operators are always the member function of a
class.

► True
► False

Question No: 14 ( Marks: 1 ) - Please choose one


A template function must have at least ---------- generic data type

► Zero
► One
► Two
► Three

http://vustudents.ning.com 21
Question No: 15 ( Marks: 1 ) - Please choose one
If we do not mention any return_value_type with a function, it will return an _____
value.

► int
► void
► double
► float

Question No: 16 ( Marks: 1 ) - Please choose one


Suppose a program contains an array declared as int arr[100]; what will be the size of
array?

►0
► 99
► 100
► 101

Question No: 17 ( Marks: 1 ) - Please choose one


The name of an array represents address of first location of array element.

► True
► False

Question No: 18 ( Marks: 1 ) - Please choose one


Reusing the variables in program helps to save the memory

► True
► False

Question No: 19 ( Marks: 1 ) - Please choose one

Which of the following option is true about new operator to dynamically allocate
memory to an object?

► The new operator determines the size of an object


► Allocates memory to object and returns pointer of valid type
► Creates an object and calls the constructor to initialize the object
► All of the given options

http://vustudents.ning.com 22
Question No: 20 ( Marks: 1 ) - Please choose one
new and delete are _____ whereas malloc and free are _____.

► Functions, operators
► Classes, operators
► Operators, functions
► Operators, classes

Question No: 21 ( Marks: 1 ) - Please choose one


Like member functions, ______ can also access the private data members of a class.

► Non-member functions
► Friend functions
► Any function outside class
► None of the given options

Question No: 22 ( Marks: 1 ) - Please choose one


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.

Question No: 23 ( Marks: 1 ) - Please choose one


The operator function overloaded for an Assignment operator (=) must be

► Non-member function of class


► Member function of class
► Friend function of class
► None of the given options

Question No: 24 ( Marks: 1 ) - Please choose one


For non-member operator function, object on left side of the operator may be

► Object of operator class


► Object of different class
► Built-in data type
► All of the given options

http://vustudents.ning.com 23
Question No: 25 ( Marks: 1 ) - Please choose one
The operator function will be implemented as _____, if obj1 drive the - operator whereas
obj2 is passed as arguments to - operator in the statement given below.
obj3 = obj1 - obj2;

► Member function
► Non-member function
► Friend function
► None of the given options

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) ;

Question No: 27 ( Marks: 1 ) - Please choose one


The static data members of a class are initialized _______

► at file scope
► within class definition
► within member function
► within main function

Question No: 28 ( Marks: 1 ) - Please choose one


Class is a user defined___________.

► data type
► memory referee
► value
► none of the given options.

http://vustudents.ning.com

Question No: 29 ( Marks: 1 ) - Please choose one


We can also define a user-defines manipulators.

► True
► False

http://vustudents.ning.com 24
Question No: 30 ( Marks: 1 ) - Please choose one
Automatic variable are created on ________.

► Heap
► Free store
► static storage
► stack
Question No: 3 ( Marks: 1 ) - Please choose one

A pointer variable can be,

► Decremented only

► Incremented only

► Multiplied only

► Both 1 and 2

Question No: 4 ( Marks: 1 ) - Please choose one

setprecision is a parameter less manipulator.

► True

► False
Question No: 5 ( Marks: 1 ) - Please choose one

We can change a Unary operator to Binary operator through operator overloading.

► False

► True

http://vustudents.ning.com 25
What is the functionality of the following statement?

String str[5] = {String(“Programming”), String(“CS201”)};

► Default constructor will call for all objects of array

► Parameterized constructor will call for all objects of array

► 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

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” ;

Choose the correct options.

► (i) and (ii) only

► (i) and (iv) only

► (i) and (iii) only

► (ii) and (iii) only

http://vustudents.ning.com 26
Overloaded member operator function is always called by _______

► Class

► Object

► Compiler

► Primitive data type

Consider the following code segment

class M {
friend int operator!(const M &);
...
};

!s // code of line implies that operator!(s)


...

Let assume if s is an object of the class then function is implemented as ___________

► Member function

► Non-member function

► Binary operator function

► None of the given options

None of the given options

http://vustudents.ning.com 27
Copy constructor becomes necessary while dealing with _______allocation in the class.

► Dynamic memory

► Static memory

► Both Dynamic and Static memory

► None of the given options

1) C/C++ string constant is enclosed in http://vustudents.ning.com

Small braces

Curly braces

Double quote

Single quote

2) Unary operator takes argument

Zero

One

Two

Three

3) When define array of objects

Constructor will call

Destructor will call

http://vustudents.ning.com 28
The size of int data type is
► 1 bytes
► 2 bytes
► 3 bytes
► 4 bytes

In Flow chart process is represented by


► Rectangle
► Arrow symbol
► Oval
► Circle

If the break statement is missed in switch statement then,


► The compiler will give error
► This may cause a logical error
► No effect on program
► Program stops its execution

When we are using const keyword with a variable x then initializing it at the time of
declaration is,
► Must
► Optional
► Not necessary
► A syntax error

Which of the following is the correct way to assign an integer value 5 to element of a
matrix say ‘m’ at second row and third column?
► m[2][3] = 5 ;
► m[3][2] = 5 ;
► m[1][2] = 5 ;
► m[2][3] = ‘5’;

How many total elements must be in two-dimensional array of 3 rows and 2 columns?
►4
►5
►6
►7

http://vustudents.ning.com 29
Which of the following is the correct statement for the following declaration?
const int *ptr.
► ptr is a constant pointer
ptr is constant integer pointer ►
► ptr is a constant pointer to int
ptr is a pointer to const int ►

Consider the following code segment. What will be the output of this code segment?
int arr[6] = {2, 3, 7, 4, 5, 6} ;
int *ptr1 =&arr[1] ;
int *ptr2 = &arr[4] ;
cout << (ptr2-ptr1) ;
►3
►9
► 12
►2

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] ; ►

The variables having a name, type and size are just like empty boxes.
►False
True ►

What's wrong with this for loop?


for (int k = 2, k <=12, k++)
► the increment should always be ++k
► the variable must always be the letter i when using a for loop
► there should be a semicolon at the end of the statement
► the commas should be semicolons

http://vustudents.ning.com 30
Most efficient method of dealing with structure variables is to define the structure
globally
► True
False ►

Syntax of union is identical to ______


► Structure
► Class
► Function
► None of the given options

Like member functions, ______ can also access the private data members of a class.

Non-member functions

► Friend functions

Any function outside class

None of the given options

Function created with in function called?

nested
overloaded
grouped
none of them

http://vustudents.ning.com 31
Come and join us at WebLyceum
For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc
Go to http://www.weblyceum.com and click Register

In Case of any Problem Contact Administrators


Rana Muhammad Safdar ([email protected])
Bilal Farooq ([email protected])

Come and join us at VU Social


For Non-Study Material Sharing, Chatting, etc,
Go to http://www.vusocial.com and click Register

(Weblyceum is not responsible for any solved content)

Collected and Composed by Bilal Farooq ([email protected])


FINALTERM EXAMINATION
Fall 2009
CS201- Introduction to Programming

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

If we write a statement like s2 = s1; s2 will be the calling object and s1 will be
passed to the = operator as an argument. P# 397

cout << setfill(‘0’) << setw(7) << 128 ;

► 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

Constructors can not be overloaded like ordinary functions.


► True
► False

The constructors can be overloaded. We can write as many constructors as we

Collected and Composed by Bilal Farooq ([email protected])


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

A template function must have at least ---------- generic data type

► Zero
► One
► Two
► Three

The function arguments must contain at least one generic data type. P# 499

Template functions can also be overloaded


► True
► False

Collected and Composed by Bilal Farooq ([email protected])


We can write overloaded template functions as long as there is use of different
number or type of arguments.. P # 503

We can not make a member function of a class as template function.


► True
► False not sure

When break statement is encountered in switch statement, it


► Stops the entire program
► Stops the execution of current statement
► Exits from switch statement
► None of the given options

We can also define a variable of user define data type (object) as static.
► True
► False

The declarator of Plus (+) member operator function is

► Class-Name operator + (Class-Name rhs)


► operator Class-Name + ( )
► operator Class-Name + ( rhs)
► 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);
a = (b = (c = (d = (e = 42) ) ) );

What will be the range of numbers generated by function rand () % 9?


► 0 to 9
► 1 to 9

Collected and Composed by Bilal Farooq ([email protected])


► 0 to 8
► 1 to 8
When 6 divides any number, the remainder will always be less than 6. Ther
result will be between therefore we will add 1. 1 + rand ( ) % 6;

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) ;
when we pass array we don’t give limit of array
Example:
Pass array to function

Declaring structures does not mean that memory is allocated.


Example:
► True
► False

structures do not occupy any memory until it is associated with the structure
variable

Identifier is a name that can be given to variables, labels and functions.


► True
► False

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

Which of the following statement is best regarding declaration of friend function?

Collected and Composed by Bilal Farooq ([email protected])


► 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.

Friend is a very strong statement. It is too strong to be affected by public or private we


can put it anywhere in the class

A pointer is a special type of variable that contain ___________


► Memory Address
► Data values
► Both Values and Memory
► None of given of options

Pointer is a special type of variable that contains a memory address.

When memory for a program is allocated at run time then it is called ________

► static memory allocation


► dynamic memory allocation
► stack memory allocation
► virtual memory allocation
When we create an object of the class at run time, it will allocate memory
according to our requirement. So there is no waste of memory and the situations
in which we want to store large data in small memory or vice versa are
prevented. So we do dynamic memory allocation inside these classes.

What purpose do classes serve?


► Data encapsulation
► Providing a convenient way of modeling real-world objects
► Simplifying code reuse
► All of the given options

Which of the following function cannot be overloaded?


► Member functions
► Utility functions
► Constructor
► Destructor

Collected and Composed by Bilal Farooq ([email protected])


The destructors can be summarized as The destructors cannot be overloaded. The
destructors take no arguments. The destructors don’t return a value

The following prototype of unary operator function indicates that it is


____________ .
Date operator++(int )

► Member functions of post increment operator


► Member functions of pre increment operator
► Non-member functions of post increment operator
► Non-member functions of pre increment operator
Overloading Unary Operators
// Preincrement operator overloaded as a member function.
Date Date::operator++()
{
helpIncrement();
return *this; // value return; not a reference return
}

// Postincrement operator overloaded as a member function.


// Note that the dummy integer parameter does not have a
// parameter name.
Date Date::operator++(int)
{
Date temp = *this;
helpIncrement();

// return non-incremented, saved, temporary object


return temp; // value return; not a reference return
} // This paper was solved by vuzs Team and meant for hosting
at vuzs otherwise its stolen contents

Static variable which is defined in a function is initialized __________.


► Only once during its life time
► Every time the function call
► Compile time of the program
► None of the above

Collected and Composed by Bilal Farooq ([email protected])


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

If we do not indent the code properly it will __________________


► Be a syntax error
► Be a logical error
► Not be an error at all
► None of the given options

we Indent the code for better readability and understanding

Truth tables are used for analyzing ___________.


► logical expressions
► arithmetic expressions
► both logical and arithmetic expressions
► none of the given options.

The truth tables are very important. These are still a tool available for analyzing
logical expressions.

Static memory allocation is also known as ____________


► Dynamic allocation
► Compile time allocation
► Run time allocation
► None of the given options
This type of memory static allocation. It is also known as compile time allocation.

Collected and Composed by Bilal Farooq ([email protected])


( 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

What is memory leak?


suppose, the heap size is decreased as we had allocated memory from it despite
the fact that it was never utilized. If this step of allocating memory and then
destroy the pointer to this memory carries on then the size of the heap will going
on to decrease. It may become of zero size. When there is no memory on heap,
the computer will stop running and there may be a system crash. This situation is
called a memory leak

Collected and Composed by Bilal Farooq ([email protected])


( 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.

Matrix :: Matrix ( const Matrix & m )


{
numRows = m.numRows ;
numCols = m.numCols ;
elements = new ( double * ) [ numRows ] ;
for ( int i = 0 ; i < numRows ; i ++ )
{
elements [ i ] = new double [ numCols ] ;
for ( int j = 0 ; j < numCols ; j ++ )
elements [ i ] [ j ] = m.elements [ i ] [ j ] ;
}
}

( Marks: 3 )
What is the keyword ‘this’ and what are the uses of ‘this’ pointer?

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.

Collected and Composed by Bilal Farooq ([email protected])


( 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 )

Overload the Binary Assignment (=) Operator.


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

Collected and Composed by Bilal Farooq ([email protected])


Come and join us at WebLyceum
For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc

Go to http://www.weblyceum.com and click Register

In Case of any Problem Contact Administrators

Rana Muhammad Safdar ([email protected])

Bilal Farooq ([email protected])

Come and join us at VU Social


For Non-Study Material Sharing, Chatting, etc,

Go to http://www.vusocial.com and click Register

(Weblyceum is not responsible for any solved content)

Collected and Composed by Bilal Farooq ([email protected])


FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming

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 ______________ .

Collected and Composed by Bilal Farooq ([email protected])


► 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;

http://www.weblyceum.com

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

Collected and Composed by Bilal Farooq ([email protected])


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
http://www.weblyceum.com

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

Collected and Composed by Bilal Farooq ([email protected])


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://www.weblyceum.com

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 , _______________

Collected and Composed by Bilal Farooq ([email protected])


► 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.
The if statement is used to select among two alternatives. It uses a boolean expression to
decide which alternative should be executed. The switch statement is used to select
among multiple alternatives. It uses an int expression to determine which alternative
should be executed.

Question No: 28 ( Marks: 2 )


How can we initialize data members of contained object at construction time?

A constructor (sometimes shortened to ctor) in a class is a special type of subroutine


called at the creation of an object. It prepares the new object for use, often accepting
parameters which the constructor uses to set any member variables required when the
object is first created.

Question No: 29 ( Marks: 2 )


How the data members of a class are initialized with meaningful values?

Sometime back we saw an odd behavior in which C++ class data members were not
getting correctly initialized due to memory corruption. It was discovered that this

Collected and Composed by Bilal Farooq ([email protected])


memory corruption was due to an unbalanced #pragma pack data alignment. In our
case, this behavior was observed right after the constructor of the class was executed. To
troubleshoot this issue, the next thing was to dump the class in WinDBG using the
command dt. This would show a layout similar to below:

Question No: 30 ( Marks: 2 )


Can we overload new and delete operators?

1) We cannot use the array size declarator with a class-specific


user-defined new function. Arrays of objects are always allocated
with the global new.

2) Overloaded new and delete operators should be provided in pairs.

3) The overloaded delete operator is invoked after the last line of


the destructor has been executed.

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?

Collected and Composed by Bilal Farooq ([email protected])


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

Collected and Composed by Bilal Farooq ([email protected])


Come and join us at WebLyceum
For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc

Go to http://www.weblyceum.com and click Register

In Case of any Problem Contact Administrators

Rana Muhammad Safdar ([email protected])

Bilal Farooq ([email protected])

Come and join us at VU Social


For Non-Study Material Sharing, Chatting, etc,

Go to http://www.vusocial.com and click Register

(Weblyceum is not responsible for any solved content)

Collected and Composed by Bilal Farooq ([email protected])


FINALTERM EXAMINATION
CS201 - Introduction to programming
Final Term Spring 2010
Operator overloading can be performed through__________________.
► Classes
► Functions
► Operators
► Reference

Question No: 2 ( Marks: 1 ) - Please choose one


When a value is referred by a normal variable then it is known as,
► Direct Reference
► Indirect Reference
► Partial Reference
► Proper Reference
When a value is referred by a normal variable is known as direct reference

Question No: 3 ( Marks: 1 ) - Please choose one


Which of the following function is used to increase the size of already allocated memory
chunk?

► malloc
► calloc
► realloc
► free

Question No: 4 ( Marks: 1 ) - Please choose one


Which of the following is NOT a preprocessor directive?
► #error
► #define
► #line

► #ndefine

list of preprocessors
• #include • #include “filename” • #define • #undef • #ifdef • #ifndef • #if • #else •
#elif • #endif • #error • #line • #pragma • #assert

Collected and Composed by Bilal Farooq ([email protected])


Question No: 5 ( Marks: 1 ) - Please choose one
The stream objects cin and cout are included in which header file?
► iostream.h
► fstream.h
► istream.h
► ostream.h

Question No: 6 ( Marks: 1 ) - Please choose one


Overloaded delete operator function takes the same parameter as an argument returned
by new operator function.
► True
► False
The same pointer that is returned by the new operator, is passed as an argument to the
delete operator. These rules apply to both, if operators (new and delete) are overloaded
as member or non-member operators (as global operators).

Question No: 7 ( Marks: 1 ) - Please choose one

When an array of object is created dynamically then there is no way to provide


parameterized constructors for array of objects.

► True
► 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.

Question No: 8 ( Marks: 1 ) - Please choose one


C is widely known as development language of _______ operating system.
► Linux
► Windows
► Unix
► Mac OS
In the start C became widely known as the development language of the UNIX
operating system, and the UNIX operating system was written by using this C
language. The C language is so powerful that the compiler of C and other various
operating systems are written in C.

Question No: 9 ( Marks: 1 ) - Please choose one


Computer can understand only machine language code.

Collected and Composed by Bilal Farooq ([email protected])


► True
► 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.

Question No: 11 ( Marks: 1 ) - Please choose one


What will be the value of ‘a’ and ‘b’ after executing the following statements?
a = 3;
b = a++;
► 3, 4
► 4, 4
► 3, 3
► 4, 3

Question No: 12 ( Marks: 1 ) - Please choose one


Consider the following code segment. What will be the output of following code?
int addValue (int *a){
int b = (*a) + 2;
return b ;
}
main () {
int x =6 ;
cout << x << “,” ;
cout << addValue(&x) << “,” ;
cout << x ;
}

► 6,8,6

► 6,6,8

► 6,8,8
► 6,6,6

Collected and Composed by Bilal Farooq ([email protected])


Question No: 13 ( Marks: 1 ) - Please choose one
_______ is used to trace the logic of the program and correct the logical errors.
► Compiler
► Editor
► Linker
► Debugger

Question No: 14 ( Marks: 1 ) - Please choose one


new and delete are _____ whereas malloc and free are _____.
► Functions, operators
► Classes, operators
► Operators, functions
► Operators, classes
Hence, we can call new and delete operators, P# 342 we have allocated a memory space
for our use by malloc function. P# 285

Question No: 15 ( Marks: 1 ) - Please choose one


Like member functions, ______ can also access the private data members of a class.
► Non-member functions
► Friend functions
► Any function outside class
► None of the given options
Question No: 16 ( Marks: 1 ) - Please choose one
Which situation would require the use of a non-member overloaded operator?
► The overloaded operator is an Assignment operator.
► The left most operand is an object of a class.
► The left operand is built-in data type.
► The operator returns a reference.

When an operator function is implemented as a non-member function, the left-most


operand may be an object of the operator’s class, an object of a different class, or a built-
in type

Question No: 17 ( Marks: 1 ) - Please choose one


The stream insertion and stream extraction operators are already overloaded for ______.
► User-defined data types
► Built-in data types
► User-defined and built-in data types
► None of the given options

Collected and Composed by Bilal Farooq ([email protected])


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 replaced
► None of the given options
► Remain constant.
► can be changed by some operation

Question No: 19 ( Marks: 1 ) - Please choose one vuzs


Assignment operator is -------------------------associative.
► right
► left
► binary
► unary
You can assign values to several variables in a single statement. For example, the
following code sets the contents of apples and oranges to the same value:
apples = oranges = 10;
The assignment operator is right associative, so this statement executes by first storing
the value 10 in oranges and then storing the value in oranges in apples, so it is
effectively
apples = (oranges = 10);

Question No: 20 ( Marks: 1 ) - Please choose one


When ever dynamic memory allocation is made in C/C++, it is freed_____________.
► Explicitly
► Implicitly
► Both explicitly and implicitly
► None of the given options
Question No: 21 ( Marks: 1 ) - Please choose one
The appropriate data type to store the number of rows and colums of the matrix
is____________.
► float
► int
► char
► none of the given options.

Question No: 22 ( Marks: 1 ) - Please choose one


Which of the following function do NOT initialize the chunk of memory to all zero?
► calloc() function
► Both malloc() and calloc()
► None of the above

Collected and Composed by Bilal Farooq ([email protected])


► malloc() function

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

Question No: 24 ( Marks: 1 ) - Please choose one


width() is member function of _____________
► cin object
► cout object
► Both cin and cout object
► None of the given option

Question No: 25 ( Marks: 1 ) - Please choose one


Templates are not type safe.
► true
► false

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.

Collected and Composed by Bilal Farooq ([email protected])


Question No: 27 ( Marks: 2 )
Give the general syntax of class template.
template
class myclass { ---} ;

Question No: 28 ( Marks: 2 )


What is a truth Table?
There are some areas where the decision structures become very complicated.
Sometimes, we find it difficult to evaluate a complicated logical expression. Sometimes
the logic becomes extremely complicated so that even writing it as a simple syntax
statement in any language. It becomes complicated to determine what will be evaluated
in what way. We know the concept of truth table. The truth tables are very important.
These are still a tool available for analyzing logical expressions. We will read logic
design in future, which is actually to do with chips and gates. How we put these things
together.

Question No: 29 ( Marks: 2 )


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.

Question No: 30 ( Marks: 2 )


What is principle of friendship in the context of functions and classes?
Class can declare a friend function and someone from outside the class cannot declare
itself friend of a class.
A friend function can access the private variables of class just like a member function

Question No: 31 ( Marks: 3 )


What are the limitations of the friendship relation between classes?
Class can declare a friend class from inside and someone from outside the class cannot
declare itself friend of a class.

Question No: 32 ( 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? a

Collected and Composed by Bilal Farooq ([email protected])


(ii) The destructor of which class will be called first?b

Question No: 33 ( Marks: 3 )


Define static variable. Also explain life time of static variable?
When you declare a static variable (native data type or object) inside a function, it is
created and initialized only once during the lifetime of the program

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.
#include
#include
main () {
double a = 12.12345;
double b = 13.123456;
double c = 14.1234567;
cout << setprecision (5) << a << endl;
cout << setprecision (2) << a << endl;
cout << setprecision (3) << a << endl;
}

Question No: 35 ( Marks: 5 )


Let we have a class,
class String
{
private:
char buf[25];
};
Write code for assignment (=) operator function which assign one String object to other
object. Your code should also avoid self assignment

Answer:
void String::operator = ( const String &other )
{ int length ;
length = other.length();
delete buf;
buf = new char [length + 1];
strcpy( buf, other.buf );

Collected and Composed by Bilal Farooq ([email protected])


Question No: 36 ( Marks: 5 )
Read the given below code and explain what task is being performed by this function
Matrix :: Matrix ( int row , int col )
{
numRows = row ;
numCols = col ;
elements = new ( double * ) [ numRows ] ;
for ( int i = 0 ; i < numRows ; i ++ )
{
elements [ i ] = new double [ numCols ] ;
for ( int j = 0 ; j < numCols ; j ++ )
elements [ i ] [ j ] = 0.0 ;
}
}
Hint : This function belong to a matrix class, having
Number of Rows = numRows
Number of Columns = numCols

Collected and Composed by Bilal Farooq ([email protected])


Come and join us at WebLyceum
For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc
Go to http://www.weblyceum.com and click Register

In Case of any Problem Contact Administrators


Rana Muhammad Safdar ([email protected])
Bilal Farooq ([email protected])

Come and join us at VU Social


For Non-Study Material Sharing, Chatting, etc,
Go to http://www.vusocial.com and click Register

(Weblyceum is not responsible for any solved content)

Collected and Composed by Bilal Farooq ([email protected])


FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming

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

Collected and Composed by Bilal Farooq ([email protected])


► #ndefine

Question No: 3 ( Marks: 1 ) - Please choose one

The return type of operator function must always be void.

► True

► False

Question No: 4 ( Marks: 1 ) - Please choose one

What does (*this) represents?

► The current function of the class

► The current pointer of the class

► The current object of the class

► A value of the data member

Question No: 5 ( Marks: 1 ) - Please choose one

The statement cin.get (); is used to,

► Read a string from keyboard

Collected and Composed by Bilal Farooq ([email protected])


► Read a character from keyboard

► Read a string from file

► Read a character from file

Question No: 6 ( 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

Question No: 7 ( Marks: 1 ) - Please choose one


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

Collected and Composed by Bilal Farooq ([email protected])


for which we are overloading these operators.

► True

► False

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 <iostream.h>

► include <iostream.h>

► #include <iostream.h>

Question No: 11 ( Marks: 1 ) - Please choose one


A template function must have only generic data types.

► True

► False

Question No: 12 ( Marks: 1 ) - Please choose one


Template class can not have static variables.

Collected and Composed by Bilal Farooq ([email protected])


► True

► False

Question No: 13 ( Marks: 1 ) - Please choose one

What will be the correct syntax to assign an array named arr of 5 elements to a
pointer ptr?

► *ptr = arr ;

► ptr = arr ;

► *ptr = arr[5] ;

► ptr = arr[5] ;

Question No: 14 ( Marks: 1 ) - Please choose one

What will be the correct syntax to access the value of fourth element of an array
using pointer ptr?

► ptr[3]

► (ptr+3)

► *(ptr+3)

► Both 1and 3

Collected and Composed by Bilal Farooq ([email protected])


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

Question No: 16 ( Marks: 1 ) - Please choose one


If there is a symbol (& sign) used with the variable name followed by data type
then it refers to _____ and if & is being used with variable name then it refers to
_____.

► Address of variable, reference variable

► Reference variable, value of variable

► Reference variable, address of variable

► Address of variable, value of variable

Question No: 17 ( Marks: 1 ) - Please choose one


We can also do conditional compilation with preprocessor directives.

► True

► False

Question No: 18 ( Marks: 1 ) - Please choose one


The default value of a parameter can be provided inside the ________________

► function prototype

Collected and Composed by Bilal Farooq ([email protected])


► function definition

► both function prototype or function definition

► none of the given options.

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 _______________.

Collected and Composed by Bilal Farooq ([email protected])


► 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

► Destructor of inner object will be called first

► Constructor and Destructor will be called simultaneously

► None of the given options

Collected and Composed by Bilal Farooq ([email protected])


Question No: 24 ( Marks: 1 ) - Please choose one
It is possible to define a class within another class.

► True

► False

Question No: 25 ( Marks: 1 ) - Please choose one


New 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 ( 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.

Collected and Composed by Bilal Farooq ([email protected])


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 << 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] ;

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;

Collected and Composed by Bilal Farooq ([email protected])


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 <class T>


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;

Collected and Composed by Bilal Farooq ([email protected])


temp.number= number * number;
return number;

}
ANS:
The errors are in the arguments of the member operation function and also in
the body of operator member function.

Correct function should be

math *operator(math *m);

math *operator (math *m)


{
math temp;
temp = m;
temp.number= number * number;
return temp.number;

Question No: 34 ( Marks: 5 )


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;
}

Collected and Composed by Bilal Farooq ([email protected])


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 ;

#include <iostream.h>
math
{
mth operator + (obj1,obj2)

Collected and Composed by Bilal Farooq ([email protected])


mth operator + (obj1,obj2)
{
mth operator + (obj1,obj2)
mth operator + (obj1,obj2)

}
}
……………………………………………………………………………

Collected and Composed by Bilal Farooq ([email protected])

You might also like