```
#include<iostream>
#include "complex0.h"
using namespace std;
ostream& operator<<(ostream& osObject, const complex0& complex)
{
osObject<< "("; //output left parenthesis
osObject<< complex.realPart; //output real part
osObject<< ", "; //output comma and space
osObject<<complex.imaginaryPart; //output imaginary part
osObject<< "i)"; //output right parenthesis and i
return osObject; //return ostream object
}
istream& operator>>(istream& isObject, complex0& complex)
{
// char ch;
//isObject >> ch; //read and discard left parenthesis
cout << "real: ";
isObject >> complex.realPart; // read and store real part
cout << "imaginary: ";
isObject >> complex.imaginaryPart; //read and store imaginary part
//isObject >> ch;
return isObject; // return istream object
}
//constructor
complex0::complex0(double real, double imag)
{
realPart = real;
imaginaryPart = imag;
}
void complex0::setComplex(const double& real, const double& imag)
{
realPart = real;
imaginaryPart = imag;
}
//overload operator +
complex0 complex0::operator+ (const complex0& otherComplex) const
{
complex0 temp;
temp.realPart = realPart + otherComplex.realPart;
temp.imaginaryPart = imaginaryPart + otherComplex.imaginaryPart;
return temp;
}
//overload operator -
complex0 complex0::operator- (const complex0& otherComplex) const
{
complex0 temp;
temp.realPart = realPart - otherComplex.realPart;
temp.imaginaryPart = imaginaryPart - otherComplex.imaginaryPart;
return temp;
}
//overload operator*
complex0 complex0::operator* (const complex0& otherComplex) const
{
complex0 temp;
temp.realPart = (realPart * otherComplex.realPart) - (imaginaryPart * otherComplex.imaginaryPart);
temp.imaginaryPart = (realPart * otherComplex.imaginaryPart)
+ (imaginaryPart * otherComplex.realPart);
return temp;
}
//overload operator~
complex0 complex0::operator~ ()
{
complex0 temp;
temp.realPart = (realPart);
temp.imaginaryPart = -(imaginaryPart);
return temp;
}
```

```
#include<iostream>
using namespace std;
#include "complex0.h"
int main()
{
complex0 num1(3.0, 4.0); //INITIALIZE to (3, 4i)
complex0 real;
complex0 imaginary;
complex0 c;
cout << "Enter a complex number in form (a, b)(q to quit):\n";
cin >> real;
cout << endl;
cout << "c is " << real << " " << endl;
cout << "a is " << num1 << '\n';
cout << "Complex conjugate is " << ~real << endl;
/*{
// cout << "complex conjugate is " << ~c << '\n';
cout << "a is " << a <<'\n';
cout << "a + c is " << a + c << '\n';
cout << "a - c is " << a - c << '\n';
cout << "a * c is " << a * c << '\n';
// cout << "2 * c is " << 2 * c << '\n';
cout << "Enter a complex number (q to quit);\n";
}
cout << "Done!\n"; */
return 0;
}
```

```
#ifndef H_complexNumber
#define H_complexNumber
#include<iostream>
using namespace std;
class complex0
{
//overload the stream insertion and extraction operators
friend ostream& operator<<(ostream&, const complex0&);
friend istream& operator>>(istream&, complex0&);
public:
void setComplex(const double& real, const double& imag);
//funtion to set complex numbers according to parameters. realPart = real; imaginaryPart = imag;
void getComplex(double& real, double& imag) const;
//Function to retrieve the complex number
//post condition: real = realPart; imag = imaginaryPart;
complex0(double real = 0, double imag = 0);
//constructor; initializes according to paramneters
complex0 operator+ (const complex0& otherComplex) const; //overload operator +
complex0 operator- (const complex0& otherComplex) const; //overload operator -
complex0 operator* (const complex0& otherComplex) const; //overload operator *
private:
double realPart; //variable to store real part
double imaginaryPart; //variable to store imaginary part
};
#endif
```