There is not much to this implementation. The constructors and the grab and print methods are by now fairly standard.
#include "complexpoly.h"
//=================================================================//
// Complex_POLY_CELL Functions //
//=================================================================//
// ***************************************************** //
// Default constructor for Complex_POLY_CELL class //
// ***************************************************** //
Complex_POLY_CELL::Complex_POLY_CELL()
{
element = 0;
power = 0;
next = NULL;
}
// ***************************************************** //
// Explicit constructor for Complex_POLY_CELL class //
// ***************************************************** //
Complex_POLY_CELL::Complex_POLY_CELL(Complex x_in,unsigned int power_in)
{
element = x_in;
power = power_in;
next = NULL;
}
// ********************************************** //
// destructor for Complex_POLY_CELL class //
// ********************************************** //
Complex_POLY_CELL::~Complex_POLY_CELL()
{
if(next!=NULL) //destroy next Complex_POLY_CELL pointer
delete next;
}
// ********************************************************* //
// const print function for Complex_POLY_CELL //
// ********************************************************* //
ostream& Complex_POLY_CELL::print(ostream& output) const
{
if(this!=NULL){
output << "(" << element << ")";
if(power == 0)
output << " ";
else if (power == 1)
output << " x";
else
output << " x^" << power;
if(next!=NULL)
output << "+";
else
output << ".";
return(output);
}
else{
cout << "CELL is NULL " << endl;
return(output);
}
}
// ********************************************************* //
// grab function for Complex_POLY_CELL //
// ********************************************************* //
istream& Complex_POLY_CELL::grab(istream& in)
{
in >> element;
in >> power;
return(in);
}
end{verbatim}
\normalsize
\subsection{Implementation: The Complex\_POLY Class:}
\subsubsection{Iterators:}
\small
\begin{verbatim}
void ComplexPOLYIter::operator++()
{
if(p!=NULL){
if(p->next!=NULL)
p = p->next;
else
p = NULL;
}
}
Complex_POLY_CELL* ComplexPOLYIter::operator()() const
{
if(p!=NULL)
return(p);
}
ComplexPOLYIter::operator const void*() const
{
if(p==NULL) return (const void *)0;
else return (const void*)1;
}