#include <iostream>
#include "LinkedPolynomial.h"
usingnamespace std;
LinkedPolynomial <double> CreatePolynomialFromInput()
{
double input_coef;
double input_exp;
LinkedPolynomial<double> poly;
cout << "Enter pairs of numbers for coefficients and the exponent." << endl
<< "Press Enter after each entry, or separate each entry by a space." << endl
<< "Entering a coefficient without an exponent will result in the coefficient being discarded." << endl
<< "Enter any English alphabet to finish. " << endl;
while((cin >> input_coef) && (cin >> input_exp))
{
poly.Add(input_coef, input_exp);
}
return poly;
}
void TestPolynomial()
{
double exponent;
double new_coefficient;
cout << "Testing LinkedPolymial class. " << endl;
LinkedPolynomial<double> poly = CreatePolynomialFromInput();
cout << "The polynomials are: " << endl;
poly.DisplayPolynomial();
cout << "\nThe degree of the polynomial is: " << poly.Degree() << endl;
cout << "Enter a value of exponent. The program will determine whether it exists. " << endl;
cin >> exponent; // This cin statement is skipped!
cout << "The coefficient exists(1= exists, 0= doesn't exist): " << poly.Coefficient(exponent) << endl;
cout << "Enter a value of coefficient." << endl;
cout << "The program will change the value of coefficient corresponding to exponent: " << exponent
<< "To your input coefficient: " << new_coefficient << endl;
cout << "The coefficient has changed(1= exists, 0= doesn't exist): " << poly.ChangeCoefficient(new_coefficient, exponent) << endl;
cout << "The new polynomial is: " << endl;
poly.DisplayPolynomial();
}
int main()
{
TestPolynomial();
return 0;
};