Program to create complex number with following member,real,imaginary, also define three type of constructor(default,paramatrised,copy) & destructor in C++
#include<iostream.h>
#include<conio.h>
class Complex
{
private:
float real,imaj;
public:
Complex()
{
real=1;
imaj=1;
cout<<"\nDefault constructor called";
}
Complex(float r,float i)
{
real=r;
imaj=i;
cout<<"\nParameterized constructor called";
}
Complex(Complex &x)
{
real=x.real;
imaj=x.imaj;
cout<<"\nCopy constructor called";
}
~Complex()
{
cout<<"\nDestructor called";
}
void display()
{
cout<<"\n"<<real<<"+i"<<imaj;
}
};
main()
{
clrscr();
Complex X,Y(10,20);
X.display();
Y.display();
Complex Z=X;
Z.display();
getch();
}
OUTPUT
Default constructor called
Parameterized constructor called
1+i1
10+i20
Copy constructor called
1+i1
Destructor called
Destructor called
Destructor called