I was able to store the coefficients in an array based on the how many degrees there are in one of my 'set' function. Not sure if I'm on the right track or not, any tips is appreciated.
#include <iostream>
#include "Polynomial.h"
usingnamespace std;
Polynomial::Polynomial()
{
}
Polynomial::~Polynomial()
{
}
Polynomial Polynomial::operator+(Polynomial &other)
{
//...
}
ostream& operator << (ostream& out, const Polynomial &poly)
{
//...
}
int Polynomial::getCoefficient()
{
return Coefficient;
}
void Polynomial::setCoefficient()
{
int coe[9]; //First array size declared
for (int i = 1; i < getExponent()+1; i++) //Loop to ask user for coefficient base on the degree of the polynomial
{
cout << "Please enter your coefficient for the first polynomial " << i << endl;
cin >> Coefficient;
coe[i] = Coefficient;
}
cout << "Your first polynomial is ";
for (int i = 1; i < getExponent() + 1; i++)
{
cout << coe[i] << "x^" << i << " + ";
}
cout << endl;
int coe2[9]; //Second array size declared
for (int i = 1; i < getExponent() + 1; i++)
{
cout << "Please enter your coefficient for the second polynomial " << i << endl;
cin >> Coefficient;
coe2[i] = Coefficient;
}
cout << "Your second polynomial is ";
for (int i = 1; i < getExponent() + 1; i++)
{
cout << coe2[i] << "x^" << i << " + ";
}
cout << endl;
}
int Polynomial::getExponent()
{
return Exponent;
}
void Polynomial::setExponent(int exp)
{
Exponent = exp;
}
I'm confused on how to overload the addition operator to add two polynomials that was asked from setCoefficient() and how to output it by overloading the stream insertion operator.