CS201 FinalTerm Papers With Reference 3
CS201 FinalTerm Papers With Reference 3
Spring 2009
CS201- Introduction to Programming
Solved by vuZs Solution Team
Fast Flyer < [email protected]>
Farhat Qudsia < [email protected]>
Zubair Hussain < [email protected]>
www.vuzs.net/
et
Question No: 1( Marks: 1 ) - Please choose one
There are mainly -------------------- types of software
► Two
n
► Three
► Four
► Five
s.
Software is categorized into two main categories
System Software
Application Software
► Incremented only
► Multiplied only
► Both 1 and 2
Question No: 4( Marks: 1 ) - Please choose one
w
et
is necessary to provide a destructor that frees the memory.
Question No: 8( Marks: 1 ) - Please choose one
What is the functionality of the following statement?
String str[5] = {String(“Programming”), String(“CS201”)};
n
► 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
s.
constructor for remaining objects
► Default constructor will call for first 3 objects and Parameterized constructor
for remaining objects vuzs
www.vuzs.net/
uz
Question No: 9( Marks: 1 ) - Please choose one
What is the sequence of event(s) when allocating memory using new operator?
.v
► 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
w
·
If a single object is allocated, operator new is called to allocate memory, and
then the constructor is called to initialize the object.
· If an array of objects is allocated, operator new[] is called to
w
allocate memory for the whole array, and then the constructor is called for each
element of the array.
· When a single object is deleted, the destructor for the object is
w
called first, and then operator delete is called to free the memory occupied by
the object.
· When an array of objects is deleted, the destructor for each
element of the array object is called first, and then operator delete[] is called to
free the memory occupied by the array.
et
Question No: 12( Marks: 1 ) - Please choose one
n
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’};
s.
ii.course[] = ‘programming’ ;
iii. course[12] = “programming” ;
iv. course = “programming” ;
Choose the correct options.
uz
► (i) and (ii) only
► (i) and (iv) only
► (i) and (iii) only
► (ii) and (iii) only
.v
Question No: 13( Marks: 1 ) - Please choose one
w
et
Overloaded member operator function is always called by _______
► Class
► Object
► Compiler
► Primitive data type
n
As discussed in the example of overloaded functions, the automatic part is also
there. But we wrote all those functions separately. Here the automatic part is
even deeper. In other words, we write one template function without specifying
s.
a data type. If it is to be called for int data type, the compiler will itself write
an int version of that function. If it is to be called for double, the compiler will
itself write it. This does not happen at run time, but at compile time. The
compiler will analyze the program and see for which data type, the template
uz
function has been called. According to this, it will get the template and write a
function for that data type. P# 498
Question No: 15( Marks: 1 ) - Please choose one
Loader loads the executable code from hard disk to main memory.
► True
.v
►False
Loader fter a executable program is linked and saved on the disk and it is ready
for execution. We need another process which loads the program into memory
and then instruct the processor to start the execution of the program from the
first instruction (the starting point of every C program is from the main
w
► new int(10) ;
► new int[10] ;
w
► int new(10) ;
► int new[10];
For example, we want to allocate an array of 10 ints dynamically. Then the
statement will be like this: int *iptr; iptr = new int[10]; P# 332
Question No: 17( Marks: 1 ) - Please choose one
The prototype of friend functions must be written ____ the class and its
definition must be written ____
et
► Friend functions
► Any function outside class
► None of the given options
If a data is private, it will be available only to member functions of the class. No
n
other function outside the class (except friend functions) can access the private
data. vuzs.net P# 320
s.
Question No: 19( Marks: 1 ) - Please choose one
To perform manipulation with input/output, we have to include _____ header
file.
► iostream.h
uz
► stdlib.h
► iomanip.h
► fstream.h
To do stream manipulations, we have to include a header file having the
name iomanip.h. We can understand that iomanip is a short hand for input
.v
output manipulation. P# 427
Question No: 20( Marks: 1 ) - Please choose one
The endl and flush are _______
www.vuzs.net/
w
► Functions
► Operators
► Manipulators
► Objects
w
Similarly flush was a manipulator for which we could write cout << flush that
means flushing the output buffer. So it manipulates the output.
P # 435 / 436
Question No: 21( Marks: 1 ) - Please choose one
w
If we want to use stream insertion and extraction operators with _______ then
we have to overload these operators.
► int, float, double
► objects of class
► int, float, object
► int, char, float
stream extraction operator is used with different data types of int, double and float. The three
lines given above can be written in one cascading line: cin >> i >> d >> f;
In order to use these insertion ( << ) and extraction ( >> ) operators with
classes, we have to overload these operators. www.vuzs.net
et
The static data members of a class can be accessed by ________
► only class
► only objects (not sure ) .....
► both class and objects
n
► none of given options
s.
uz
Question No: 23( Marks: 1 ) - Please choose one
.v
Classes defined inside other classes are called ________ classes
► looped
► nested
► overloaded
► none of the given options.
w
we can have structures or classes defined inside classes. Classes defined within
other classes are called nested classes
w
et
Consider the following code segment
class M {
friend int operator!(const M &);
n
...
};
!s // code of line implies that operator!(s)
s.
...
Let assume if s is an object of the class then function is implemented as
___________
► Member function
uz
► Non-member function
► Binary operator function
► None of the given options
None of the given options
.v
Question No: 26( Marks: 1 ) - Please choose one
w
When the compiler overloads the assignment (=) operator by default then
__________
w
Assignment Operator
At first, we ascertain whether there is need of an assignment operator or not? It
is
needed when we are going to assign one object to the other, that means when
we want
to have expression like a = b. C++ provides a default assignment operator. This
operator does a member-wise assignment.
www.vuzs.net/
et
If text is a pointer of class String then what is meant by the following
statement?
n
text = new String [5];
► Creates an array of 5 string objects statically
► Creates an array of 5 string objects dynamically
s.
► Creates an array of pointers to string
► Creates a string Object
uz
Question No: 28( Marks: 1 ) - Please choose one
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
w
The appropriate data type to store the number of rows and is____________.
► floatcolums of the matrix
► int
► char
► none of the given options.
et
Question No: 31( Marks: 1 )
n
What is drawback of writing the definitions of all the functions before main
function?
s.
Question No: 32( Marks: 1 )
How do we provide the default values of function parameters?
Question No: 33( Marks: 2 )
What is difference between endl and \n?
uz
Question No: 34( Marks: 2 )
When does an object get destroyed?
Question No: 35( Marks: 3 )
What is the difference between structure and class?
Question No: 36( Marks: 3 )
What will be the output of following functions if we call these functions three
.v
times?
1)
void func1(){
int x = 0;
w
x++;
cout << x << endl;
}
2)
w
void func2(){
static int x = 0 ;
x++;
w
et
The class should also provide the following Overloaded operator capabilities.
a) Overload the addition operator(+) to add two Vectors
b) Overload the assignment operator(=) to assign Resultant Vector
c) Write function Display() to display x, y coordinates
n
Note:Addition of vector Let suppose there are two vectors A and B with their x,
y coordinates.
s.
uz
.v
w
w
w