Note: - (I) All questions are compulsory. (II)Programming Language: C++
Questions from 1 to 8 carries of 1 mark each.
1.
Identify the errors in following code fragment: class X { int x; static int ctr; public: void init(void)
{ c=ctr=0; }
Static void prn(void)
{ cout<<ctr<<x; }
};
2.
You want to modify a private data member of a class through a non member function? Is it possible? How/why?
3.
How many times is the copy constructor called in the following code?
Sample func(Sample u)
{ Sample v(u)
Sample w=v;
Return w;
} int main()
{ Sample x;
Sample y=func(x);
Sample z=func(y);
Return 0;
}
4.
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?
5.
Which of the following statement is correct?
A.
A destructor has the same name as the class in which it is present.
B.
A destructor has a different name than the class in which it is present.
C.
A destructor always returns an integer.
D.
A destructor can be overloaded.
6.
Define base class?
7.
Is it possible a class may contain objects of another class inside it?
8.
In Base Class Private Members are inherit to the derived class or not? Justify your answer?
Questions from 9 to 14 carries of 2 mark each.
9.
What is inline function? When will you make a function inline and why?
10.
What do you mean by static members? Explain each static member by using suitable example?
11.
What do you mean by destructor in C++? In which order destructors will be called if more than one constructor is created?
12.
What is overloaded constructor? Explain with the help of example?
13.
What is hybrid inheritance? Explain.
14.
How can we call base class constructor? Explain with example?
Questions from 15 to 19 carries of 3 mark each.
15.
Write the definition for a class called complex that has floating point data members for storing real and imaginary parts. The class has the following member functions: void set(float, float) to set the specified value in object void disp() to display complex number object complex sum(complex) to sum two complex numbers & return complex number
1. Write the definitions for each of the above member functions.
2. Write main function to create three complex number objects. Set the value in two objects and call sum() to calculate sum and assign it in third object. Display all complex numbers.
16.
Answer the questions (i) and (ii) after going through the following program: class Match
{ int Time; public:
Match() //Function 1
{
Time=0; cout<<”Match commences”<<endl;
} void Details() //Function 2
{ cout<<”Inter Section Basketball Match”<<end1;
}
Match(int Duration) //Function 3
{
Time=Duration; cout<<”Another Match begins now”<<endl;
}
Match(Match &M)
{
//Function 4
Time=M.Duration; cout<<”Like Previous Match ”<<endl;
} }; i) Which category of constructor - Function 4 belongs to and what is the purpose of using it? ii) Write statements that would call the member Functions 1 and 3
17.
What is constructor? How many types of constructors are available in C++? Explain each of them with the help of suitable example.
18.
What is virtual base class in C++? What is its significance?
19.
Answer the questions (i) to (iii) based on the following code : class Drug
{ char Category[10]; char Date_of_manufacture[10]; public: char Company[20];
Drug(); void enterdrugdetails(); void showdrugdetails{);
}; class Tablet : public Drug
{ protected: char tablet_name[30]; char Volume_label[20]; public: float Price;
Tablet();
}; void entertabletdetails(); void showtabletdetails (); class PainReliever : public Tablet
{ int Dosage_units; char Side_effects[20]; public: int Use_within_days;
};
PainReliever(); void enterdetails(); void showdetails();
(i) How many bytes will be required by an object of class Drug and an object of class PainReliever respectively ?
(ii) Write names of all the data members which are accessible from the object of class
PainReliever.
(iii) Write names of all the members accessible from member functions of class Tablet.
*****************