title: Overload addition operator to add two polynomials
body: <p>I am trying to overload the addition operator to add two polynomials. My idea is that make the polynomial as two arrays, one for coefficients and one for exponents. Adding two polynomials is just combining two arrays into a longer array. I just learned pointers and ampersand yet not know how to use them efficiently. I got the errors saying "expression must be a modifiable lvalue".</p>
  
  <p>The getter and setter functions will be used to combine the terms of same exponents and I haven't write it yet.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Polynomial.h"
  using namespace std;
  
  Polynomial::Polynomial(){
  
  };
  
  Polynomial Polynomial::operator + (const Polynomial &amp;right) const
  {
      Polynomial Sum;
      Sum.numberOfTerms = numberOfTerms + right.numberOfTerms;
      int i = static_cast&lt;int&gt;(numberOfTerms);
      int j = static_cast&lt;int&gt;(right.numberOfTerms);
      for (int n = 0; n &gt; i &amp;&amp; n &lt;= n + j; n++) {
          coefficients[n] = right.coefficients[n]; //error saying expression must be a modifiable lvalue
          exponents[n] = right.exponents[n];
      }
      return Sum;
  }
  
      void Polynomial::enterTerms() {
      int coefficient=0;
      int exponent=0;
  
      cout &lt;&lt; "Enter number of terms for the polynomial:";
      cin &gt;&gt; numberOfTerms;
  
      for (int i = 0; i &lt; numberOfTerms; i++) {
          cout &lt;&lt; "Enter coefficient:\n";
          cin &gt;&gt;coefficient;
          coefficients[i] = coefficient;
  
          cout &lt;&lt; "Enter exponent:\n";
          cin &gt;&gt; exponent;
          exponents[i] = exponent;
      }
  }
  
  void Polynomial::printPolynomial() const {
      //Print the first term out, if exponent is 0, just print out the     constant
      if (exponents[0] == 0) {
          cout &lt;&lt; coefficients[0];
      }
      else{
          cout &lt;&lt; coefficients[0] &lt;&lt; "x^" &lt;&lt; exponents[0];
      }
  
      //Print from the second term to the last term, including a "+" in front of each term
      for (int i = 1; i &lt;= numberOfTerms; i++) {
          if (exponents[i] == 0) {
              cout &lt;&lt;"+"&lt;&lt; coefficients[i];
          }
          else {
              cout &lt;&lt; "+"&lt;&lt;coefficients[i] &lt;&lt; "x^" &lt;&lt; exponents[i];
          }
  
      }
  }
  
  int Polynomial::getNumberOfTerms() const {
      return numberOfTerms;
  }
  
  int Polynomial::getTermCoefficient(int i) const {
      return coefficients[i];
  }
  
  int Polynomial::getTermExponent(int i) const {
      return exponents[i];
  }
  </code></pre>
  
  <p>This is the header file</p>
  
  <pre><code>#ifndef POLYNOMIAL_H
  #define POLYNOMIAL_H
  #include &lt;array&gt;
  using namespace std;
  
  class Polynomial {
  public:
      static const int maxTerms = 100;
  
      Polynomial();
  
      Polynomial operator+(const Polynomial &amp;)const;
  
  void enterTerms();
      void printPolynomial() const;
      int getNumberOfTerms() const;
      int getTermExponent(int) const;
      int getTermCoefficient(int) const;
  
  void setCoefficient(int, int);
  //~Polynomial();
  
  
  private:
      size_t numberOfTerms;
      array&lt;int, maxTerms&gt; exponents;
      array&lt;int, maxTerms&gt; coefficients;
      static void polynomialCombine(Polynomial &amp;);
  };
  #endif
  </code></pre>