Note that the print agent is a bit messy because we are trying to print out the complex number in a pretty format.
//====================================================//
// //
// grab agent //
// //
//====================================================//
istream& MYCOMPLEX::grab(istream& in)
{
in >> real;
in >> imaginary;
return(in);
}
//====================================================//
// //
// print agent //
// //
//====================================================//
ostream& MYCOMPLEX::print(ostream& output) const
{
if(fabs(real)> 1.0e-14)
output << real;
else
output << 0.0;
if(fabs(imaginary)> 1.0e-14){
if(imaginary > 1.0e-14)
output << " +" << imaginary << "I ";
if(imaginary< -1.0e-14)
output << imaginary << "I ";
}
else
output << "+" << 0.0 << "I ";
return output;
}