NOTE: There are 9 Questions in all.
· Question 1 is compulsory and carries 20 marks. Answer to Q. 1. must be written in the space provided for it in the answer book supplied and nowhere else.
· Out of the remaining EIGHT Questions answer any FIVE Questions. Each question carries 16 marks.
· Any required data not explicitly given, may be suitably assumed and stated.
Q.1 Choose the correct or best alternative in the following: (2x10)
a. A constructor can be declared _______.
(A) private (B) static
(C) virtual (D) abstract
b. Composition depicts _______ relationship.
(A) FOR-A (B) IS-A.
(C) HAS-A. (D) friend.
c. An assignment operator takes _____ argument(s).
(A) no (B) one
(C) two (D) arbitrary no. of
d. In C++, a new operator call allocates memory from ____ area.
(A) heap (B) stack
(C) global area (D) dynamic stack
e. Which of the following declarations are illegal?
(A) void *ptr; (B) char *str = “hello”;
(C) char str = “hello”; (D) int * const P1;
f. In C++, binary operator + has _____ associativity.
(A) left to right (B) right to left
(C) arbitrary (D) depends on usage
g. In C++ struct, all members are _____ by default.
(A) public (B) protected
(C) private (D) friend
h. What will be the result of the expression 14 & 23?
(A) 37 (B) 25
(C) 6 (D) 12
i. Which of the following is NOT the valid class declaration header for the derived class D with base classes B1 and B2?
(A) class D : public B1, public B2
(B) class D : class B1, class B2
(C) class D : protected B1, B2
(D) class D : B1, B2
j. In C++, a class may have ________ copy constructor(s).
(A) no or zero (B) atmost one
(C) one or more than one (D) more than one
Answer any FIVE Questions out of EIGHT Questions.
Each question carries 16 marks.
Q.2 a. Explain the role of constructor and destructor in a class. What restrictions
apply for constructors and destructors of a class? (8)
b. Can a destructor be virtual? Can a constructor be virtual? Explain. (4 + 4 = 8)
Q.3 a. The overloaded assignment operator = should return by reference. What implications will be there if it returns void? Comment and justify. (8)
b. Define a base class person having name as a member. Use this class to define another class student having roll no., class and marks as members. Define appropriate constructors to read the data. Write a global function to create an instance of class student and then display its area. (8)
Q.4 a. Explain and illustrate the use of private inheritance through suitable example(s). (8)
b. What are the advantages of new operator over malloc function? (2 + 2 = 4)
c. What is the implication of passing a constant reference to a function? (4)
Q.5 a. A 'main' program is given as follows:
#include <iostream>
using namespace std;
int main() {
float a = 4.0;
COMPLEX b(3,4) ;
COMPLEX c = a + b;
a = c – b;
cout << a << b << c;
return 0;
}
Design and implement suitable classes to support the given main program. You need to provide the suitable class declarations and also implement required member functions as well as member or non-member operators as applicable. Don't depend on the compiler provided functions/operators. (12)
b. What is this pointer? (4)
Q.6 a. Write a program to display only those lines of a file that start with “/*”. (12)
b. What do you understand by condition states of streams? Explain. (4)
Q.7 a. What is a virtual class? Illustrate through suitable example. (8)
b. Define a template for a sort function. (8)
Q.8 a. What is the role of user-defined cast operator? Explain through suitable example(s). (8)
b. The overloaded index [ ] operator returns by reference. What implications will be there if it returns by value? Comment and justify. (8)
Q.9 Write short notes on the following: (16)
(i) Aggregation and composition.
(ii) Union.
(iii) Ellipsis in catch block.
(iv) Array and pointer.