Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with this. Please help! #ifndef POLYNOMIAL _ H #define POLYNOMIAL _ H #include #include #include #include term.h class Polynomial { public:
I need help with this. Please help!
#ifndef POLYNOMIALH
#define POLYNOMIALH
#include
#include
#include
#include "term.h
class Polynomial
public:
Create a badinvalid polynomial of degree
Arithmetic operations are not permitted on this bad value
and may cause a program to crash. Nonetheless, this value
is useful as a way of signalling invalid results.
Polynomial;
Create a polynomial representing a linear or constant formula ax b
Polynomial int b int a ;
Create a polynomial containing a collections of terms.
@param terms a set of terms
Polynomial std::initializerlist terms;
Create a polynomial with the given coefficients.
Eg
double c;
Polynomial p c;
creates a polynomial p representing: x x
@param nCoeff number of coefficients in the input array
@param coeff the coefficients of the new polynomial, starting
with power
Polynomial int nCoeff, int coeff;
Get the coefficient of the term with the indicated power.
@param power the power of a term
@return the corresponding coefficient, or zero if power or if
power getDegree
int getCoeffint power const;
The degree of a polynomial is the largest exponent of x with a
nonzero coefficient. Eg
xx has degree
has degree x
is a special case and is regarded as degree
@return the degree of this polynomial
int getDegree const;
Add a polynomial to this one, returning their sum.
@param p another polynomial
@return the sum of the two polynomials
Polynomial operatorconst Polynomial& p const;
Multiply this polynomial by a scalar.
@param scale the value by which to multiply each term in this polynomial
@return the polynomial resulting from this multiplication
Polynomial operatorint scale const;
Multiply this polynomial by a Term.
@param Term the value by which to multiply each term in this polynomial
@return the polynomial resulting from this multiplication
Polynomial operatorTerm term const;
Multiply this polynomial by a scalar, altering this polynomial.
@param scale the value by which to multiply each term in this polynomial
void operatorint scale;
Divide one polynomial by another, if possible.
@param p the demoninator, the polynomial being divided into this one
@return the polynomial resulting from this division or the bad
value Polynomial if p cannot be divided into this polynomial
to get a quotient polynomial with integer coefficients and no remainder.
Polynomial operatorconst Polynomial& p const;
Compare this polynomial for equality against another.
@param p another polynomial
@return true iff the polynomials have the same degree and their corresponding
coefficients are equal.
bool operatorconst Polynomial& p const;
private:
@brief The degree of the polynomial.
This is the largest power of x having a nonzero coefficient, or
zero if the polynomial has all zero coefficients. Note that
adding polynomials together or scaling polynomials multiplying by
a constant could reduce the degree of the result.
int degree;
ddd
List of terms, in ascending order of power.
Terms with zero coefficients are dropped.
An empty list of degree is the polynomial:
std::list terms;
For example, the polynomial xx would have:
degree:
terms: Term Term Term
The polynomial x would have:
degree:
terms: Term Term
The polynomial would have:
degree:
terms: Term
The polynomial would have:
degree:
terms:
A special "bad" value used to signal an unsuccessful operations is
degree:
terms:
A utility function to scan the current polynomial, putting it into
"normal form". In this case, the normal form will drop all terms with
zero coefficients, adjusting the degree as necessary.
Polynomials should be kept in normal form at all times outside of the
actual member function bodies of this class.
void normalize;
A "friend" declaration means that the following function or class will
have access to this class's private data members, just as if it were a
member function of this class.
friend std::ostream& operatorstd::ostream& const Polynomial&;
Note: a member function of the Polynomial class must have a polynomial
as the first argument eg poly.operatorx polyx These
function simply allows for the multiplication to be written with the polynomial on the right.
@param the value to multiply the polynomial by
@param p a polynomial
@return the product of scale and p
inline
Polynomial operatorint by const Polynomial& p
return p by;
inline
bool operator!const Polynomial& p const Polynomial& q
return pq;
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started