Page 68 - C++
P. 68
2 (a) What is a copy constructor? Illustrate with a suitable C++ example. (2)
3
Ans. A copy constructor is an overloaded constructor in which an object of the
same class is passed as reference parameter.
class X
{
int a;
public:
X()
{
a=0;
}
X(X &ob) //copy constructor
{
a=ob.a;
}
};
(Full 2 Marks to be awarded if the copy constructor is explained with an
appropriate example)
OR
(1 Mark for correct explanation of copy constructor only without an
example)
(b) Write the output of the following C++ code. Also, write the name of (2)
feature of Object Oriented Programming used in the following program
jointly illustrated by the Function 1 to Function 4.
void My_fun ( ) // Function 1
{
for (int I=1 ; I<=50 ; I++) cout<< "-" ;
cout<<end1 ;
}
void My_fun (int N) // Function 2
{
for (int I=1 ; I<=N ; I++) cout<<"*" ;
cout<<end1 ;
}
void My_fun (int A, int B) // Function 3
{
for (int I=1. ;I<=B ;I++) cout <<A*I ;
cout<<end1 ;
}
void My_fun (char T, int N) // Function 4
{
for (int I=1 ; I<=N ; I++) cout<<T ;
cout<<end1;
4