FINALTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming
Question No: 1( M a r k s: 1 )
There are mainly -------------------- types of software
► Two
► Three
► Four
► Five
Software is categorized into two main categories
System Software
Application Software
Question No: 2( M a r k s: 1 )
When x = 7; then the expression x%= 2; will calculate the value of x as,
► 1
► 3
► 7
► 2
\Question No: 3( M a r k s: 1 )
A pointer variable can be,
► Decremented only
► Incremented only
► Multiplied only
► Both 1 and 2
Question No: 4( M a r k s: 1 )
setprecision is a parameter less manipulator.
► True
►False
Question No: 5( M a r k s: 1 )
We can change a Unary operator to Binary operator through operator overloading.
►False
► True
Question No: 6( M a r k s: 1 )
delete operator is used to return memory to free store which is allocated by the new operator
► True
►False
The objects are created with the new operator on free store, they will not be destroyed and memory will not be de-allocated unless we call delete operator to destroy the objects and de-allocate memory.
Question No: 7( M a r k s: 1 )
When we do dynamic memory allocation in the constructor of a class, then it is necessary to provide a destructor.
► True
►False
whenever we have a class in which the constructor allocates dynamic memory, it is necessary to provide a destructor that frees the memory.
Question No: 8( M a r k s: 1 )
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 vuzs
Question No: 9( M a r k s: 1 )
What is the sequence of event(s) when allocating memory using new operator?
► Only block of memory is allocated for objects
► Only constructor is called for objects
► Memory is allocated first before calling constructor
► Constructor is called first before allocating memory
·
If a single object is allocated, operator new is called to allocate memory, and then the constructor is called to initialize the object. · If an array of objects is allocated, operator new[] is called to allocate memory for the whole array, and then the constructor is called for each element of the array. · When a single object is deleted, the destructor for the object is called first, and then operator delete is called to free the memory occupied by the object. · When an array of objects is deleted, the destructor for each element of the array object is called first, and then operator delete[] is called to free the memory occupied by the array.
Question No: 10( M a r k s: 1 )
Deleting an array of objects without specifying [] brackets may lead to memory leak
► True
►False
Question No: 11( M a r k s: 1 )
Which of the following data type will be assumed if no data type is specified with constant?
► short
► float
► int
► double
Question No: 12( M a r k s: 1 )
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
Question No: 13( M a r k s: 1 )
What will be the correct syntax of the following statement?
ptr is a constant pointer to integer.
► const int *ptr ;
► const *int ptr ;
► int const *ptr ;
► int *const ptr ;
The keyword const for pointers can appear before the type, after the type, or in both places. The following are legal declarations:
const int * ptr1; /* A pointer to a constant integer:
the value pointed to cannot be changed */
int * const ptr2; /* A constant pointer to integer:
the integer can be changed, but ptr2
cannot point to anything else */
const int * const ptr3; /* A constant pointer to a constant integer:
neither the value pointed to
nor the pointer itself can be changed */
Declaring an object to be const means that the this pointer is a pointer to a const object. A const this pointer can by used only with const member functions vuzs.net
Question No: 14( M a r k s: 1 )
Overloaded member operator function is always called by _______
► Class
► Object
► Compiler
► Primitive data type
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 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 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( M a r k s: 1 )
Loader loads the executable code from hard disk to main memory.
► True
►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 function). This processor is known as loader. P# 13
Question No: 16( M a r k s: 1 )
Which of the following is the correct C++ syntax to allocate space dynamically for an array of 10 int?
► new int(10) ;
► new int[10] ;
► int new(10) ;
► int new[10];
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( M a r k s: 1 ) http://vuzs.net
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
So their definition will be always outside the class. However, the prototype of the function will be written in the class. P#346
Question No: 18( M a r k s: 1 )
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
If a data is private, it will be available only to member functions of the class. No other function outside the class (except friend functions) can access the private data. vuzs.net P# 320
Question No: 19( M a r k s: 1 )
To perform manipulation with input/output, we have to include _____ header file.
► iostream.h
► stdlib.h
► iomanip.h
► fstream.h
To do stream manipulations, we have to include a header file having the name iomanip.h. We can understand that iomanip is a short hand for input output manipulation. P# 427
Question No: 20( M a r k s: 1 )
The endl and flush are _______
► Functions
► Operators
► Manipulators
► Objects
Similarly flush was a manipulator for which we could write cout << flush that means flushing the output buffer. So it manipulates the output.
P # 435 / 436
Question No: 21( M a r k s: 1 )
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
Question No: 22( M a r k s: 1 )
The static data members of a class can be accessed by ________
► only class
► only objects (not sure ) .....
► both class and objects
► none of given options
Question No: 23( M a r k s: 1 )
Classes defined inside other classes are called ________ classes
► looped
► nested
► overloaded
► none of the given options.
we can have structures or classes defined inside classes. Classes defined within other classes are called nested classes
Question No: 24( M a r k s: 1 )
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 correctly
► Destructors do not return a value.
Destructors obey the following syntactical requirements:
-
a destructor's name is equal to its class name prefixed by a tilde;
-
a destructor has no arguments;
-
a destructor has no return value.
Question No: 25( M a r k s: 1 )
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
Question No: 26( M a r k s: 1 )
When the compiler overloads the assignment (=) operator by default then __________
► compiler does member wise assignment.
► compiler does not allow default overload of assignment (=) operator
► member of the class are not assigned properly
► None of the given options
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.
Question No: 27( M a r k s: 1 )
If text is a pointer of class String then what is meant by the following statement?
text = new String [5];
► Creates an array of 5 string objects statically
► Creates an array of 5 string objects dynamically
► Creates an array of pointers to string
► Creates a string Object
Question No: 28( M a r k s: 1 )
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
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: 29( M a r k s: 1 )
The appropriate data type to store the number of rows and is____________.
► floatcolums of the matrix
► int
► char
► none of the given options.
Int is right becuase columns and row cannot be in fractions
Question No: 30( M a r k s: 1 )
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
Copy constructor becomes necessary while dealing with dynamic memory allocation in the class
Question No: 31( M a r k s: 1 )
What is drawback of writing the definitions of all the functions before main function?
Question No: 32( M a r k s: 1 )
How do we provide the default values of function parameters?
Question No: 33( M a r k s: 2 )
What is difference between endl and \n?
Question No: 34( M a r k s: 2 )
When does an object get destroyed?
Question No: 35( M a r k s: 3 )
What is the difference between structure and class?
Question No: 36( M a r k s: 3 )
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Question No: 37( M a r k s: 3 )
Why stream insertion and stream extraction operators cannot be overloaded as member functions?
Question No: 38( M a r k s: 5 )
What is difference between Unary and binary operators and how they can be overloaded?
Question No: 39( M a r k s: 5 )
What steps we must follow to design good program?
Question No: 40( M a r k s: 10 )
Write the program that inputs an octal number from the user and then display the entered octal number into hexadecimal number using manipulators (parameter-less, parameterized) and member function of input/output streams.
Question No: 41( M a r k s: 10 )
Develop a class Vector having two data members; x and y.
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
Note:Addition of vector Let suppose there are two vectors A and B with their x, y coordinates.