Professional Documents
Culture Documents
ASS1
ASS1
Implement
the following
1. Constructor (including a default constructor which creates the complex number 0+0i).
2. Overload operator+ to add two complex numbers.
3. Overload operator* to multiply two complex numbers.
Overload operators << and >> to print and read Complex Numbers.
int main()
{
complex a,b,c,d;
cout<<"Enter first complex number"<<endl;
cout<<"Enter real and imaginary: "<<endl;
cin>>a;
cout<<"Enter second complex number";
cout<<"\nEnter real and imaginary: "<<endl;
cin>>b;
cout<<"\n\tArithmetic operations"<<endl;
c=a+b;
cout<<"\n\tAddition = ";
cout<<c;
d=a*b;
cout<<"\n\tMultiplication= ";
cout<<d;
cout<<endl;
return 0;
}
Output:
Enter first complex number
Enter real and imaginary:
23
Enter second complex number
Enter real and imaginary:
34
Arithmetic operations
Addition = 5+7i
Multiplication= 6+12i