Describe the concept of constructor with default argument with suitable example.
Definition: The constructor where we can assign default values for one or more parameters at the time of function declaration is called as constructor with default argument
Example:
class complex
{
float real, img ;
public:
complex (float r,floati=0.0 )
{
real=r;
img=I;
}
void display()
{
cout<< real<<”+”<<img<<”i”<<endl;
}
}
void main()
{
complex c1(5.0);
complex c2(2.0,3.0);
cout<<”complex c1:\n”;
c1.display();
cout<<”complex c2:\n”;
c2.display();
getch();
}