My teacher gave me a quiz that was an old test she has used in the past. Now I've done the previous homework and have some understanding of operator overloading, but this one really throws me off. We are not supposed to change the header file, but from what I've been working on, I find myself wanting to change it. Maybe I'm over thinking it but I can barely even get started on this. This is the header file; I am to create an implementation and test file. Side note: shouldn't the arithmetic operators be implemented as nonmember functions?
#ifndef H_polyClass
#define H_polyClass
#include <iostream>
usingnamespace std;
class polyClass
{
friend ostream& operator << (ostream&, const polyClass &polyclass);
//Overload the extraction operator
//Output format example: 5x^2 - 3x + 6
public:
void setPoly ( int myArray [], int myterms);
//Function to set the polynomial according to the parameter.
//Postcondition: polyArray = myArray; terms = myterms;
polyClass ( int myArray [], int myterms);
//Constructor
//Initializes the polynomial according to the parameter.
//Postcondition: polyArray = myArray; terms = myterms;
polyClass ();
//Default Constructor
//Initializes the polynomial.
//Postcondition: polyArray = NULL; terms = 0;
polyClass operator + (const polyClass& otherPoly) const;
//overload the operator +
booloperator == (const polyClass& otherPoly) const;
//overload the operator ==
private:
int *polyArray; //pointer to an array that holds the term coefficients.
int terms; //the number of terms in the polynomial
};
#endif
The test file is to check equality of two polynomials(the first two objects - there are to be the same, so they will be equal) then add those two polynomials together. After adding, get a third polynomial and check if polynomial one is equal to polynomial 3(which it won't be). Any help would be greatly appreciated. Thank You!