Hello, I'm having trouble with multiple stuff in my polynomial program. First of all, I can't seem to find a way to access the mySize variable from the Polynomial class, also, I'm not quite sure how to combine the liketerms, and finally if you could give me some tips for the multiplication function in Polynomial class. Any help would be appreciated.
#include <iostream>
#ifndef PNOM
#define PNOM
constint CAPACITY = 1024;
class Monomial {
protected:
int coef;
int exp;
// int size;
public:
Monomial(){};
/*----------------------------------------------------------------------
Construct a Monomial object.
Precondition: None
Postcondition: An empty Monomial object has been constructed..
-----------------------------------------------------------------------*/
Monomial(int c,int p) { coef = c; exp = p;};
friend Monomial operator+ (Monomial&, Monomial&);
friend Monomial operator- (Monomial&, Monomial&);
friend Monomial operator* (Monomial&, Monomial&);
friendclass Polynomial;
int getExponent() {return exp;}
int getCoefficient() {return coef;}
/*----------------------------------------------------------------------
Construct a Monomial object with specified coeffient and exponent.
Precondition: None
Postcondition: A Monomial object has been constructed with the
specified coeffient and exponent.
-----------------------------------------------------------------------*/
friend ostream & operator<< (ostream & out, const Monomial & mono);
/*----------------------------------------------------------------------
Overloading the OUTPUT operator for Monomials.
Precondition: None.
Postcondition: The coefficient and exponent (if != 0) of the monomial are
displayed in the default output device.
-----------------------------------------------------------------------*/
};
typedef Monomial ElementType;
class Polynomial
{
public:
friendclass Monomial;
Polynomial();
/*----------------------------------------------------------------------
Construct a List object.
Precondition: None
Postcondition: An empty List object has been constructed; mySize is 0.
-----------------------------------------------------------------------*/
/***** empty operation *****/
bool empty() const;
/*----------------------------------------------------------------------
Check if a list is empty.
Precondition: None
Postcondition: true is returned if the list is empty, false if not.
-----------------------------------------------------------------------*/
/***** insert and erase *****/
void insert(ElementType item, int pos);
/*----------------------------------------------------------------------
Insert a value into the list at a given position.
Precondition: item is the value to be inserted; there is room in
the array (mySize < CAPACITY); and the position satisfies
0 <= pos <= mySize.
Postcondition: item has been inserted into the list at the position
determined by pos (provided there is room and pos is a legal
position).
-----------------------------------------------------------------------*/
void erase(int pos);
/*----------------------------------------------------------------------
Remove a value from the list at a given position.
Precondition: The list is not empty and the position satisfies
0 <= pos < mySize.
Postcondition: element at the position determined by pos has been
removed (provided pos is a legal position).
----------------------------------------------------------------------*/
friend Polynomial operator+(Polynomial &, Polynomial &);
friend Polynomial operator*(Polynomial &, Polynomial &);
/***** output *****/
void display(ostream & out) const;
protected:
int mySize; // current size of list stored in myArray
ElementType myArray[CAPACITY]; // array to store the Monomials
}; //--- end of List class
//------ Prototype of output operator
ostream & operator<< (ostream & out, const Polynomial & p);
#endif