Question: need the c++ code of this excercise. Implementation Your implementation will consist of adding C++ code to implement two modules: polyterm.cpp and polynomial.cpp. Module: polyterm.cpp
need the c++ code of this excercise.
Implementation
Your implementation will consist of adding C++ code to implement two modules: polyterm.cpp and polynomial.cpp.
Module: polyterm.cpp This module contains the implementation of the interface for the class used to represent the terms in a polynomial. Public methods to be implemented:
polyterm(double coefficient, unsigned int exponent) - constructor for the polynomial term based on a coefficient and an exponent.
double get_coefficient() - Returns the coefficient of this term.
unsigned int get_exponent() - Returns the exponent of this term
void set_coefficient(double coefficient) - Sets the value of the coefficient for this
term.
void set_exponent(unsigned int exponent) - Sets the value of the exponent for this
term.
bool operator==(const polyterm& T) - Equality operator. Returns true if both terms
have the same exponents and coefficients, or false otherwise.
bool operator!=(const polyterm& T) - Inequality operator. Returns true if the terms
are not equal, or false otherwise.
polyterm operator~() - Oposite operator. Returns a new term that has a coefficient
with the opposite sign of the coefficient in this term.
double operator()(double b) - Evaluation operator. Returns the value of the term
when the value b is used as the value of the variable x in the term.
polyterm derivative() computes the derivative of this term.
polyterm indefinite_integral() computes the indefinite integral (anti-derivative).
Module: polynomial.cpp This module contains the implementation of the interface for the polynomial class. Methods to be implemented:
polynomial() Creates a new polynomial with one term set to 0.
polynomial(const polyterm& new_term) - Creates a new polynomial with one term.
const polynomial& operator+=(const polynomial& P) - Self-addition operator. Adds
the contents of the argument polynomial to the contents of this polynomial.
Equivalent expression: P0 = P0 + P1;
const polynomial& operator-=(const polynomial& P) - Self-substraction operator.
Substracts the contents of the argument polynomial from the contents of this
polynomial. Equivalent expression: P0 = P0 - P1, where P0 is this polynomial.
void multiply_term(const polynomial& P, const polyterm& T, polynomial& res)
multiplies a polynomial P by a term T, and stores the results in variable res.
const polynomial& operator*=(const polynomial& P) Self-multiplication operator. Multiplies the contents of the argument polynomial with the contents of this
polynomial. Equivalent expression: P0 = P0 * P1, where P0 is this polynomial.
bool operator==(const polynomial& P) - Determines if two polynomial are equal,
based on wether or not they have the same terms.
unsigned int degree() - Returns the degree of the polynomial, which is the largest
exponent of the any term
const polyterm& operator[](int index) - This operator allows access to a term in the polynomial, whose position is given by the argument index. This method must assert whether or not the index is within the bound of the array of terms in the polynomial.
double operator()(double x) - Evaluates the value of a polynomial, given the value of the variable x. This method evaluates the expression y = P(a), where a is some constant number.
polynomial derivative() - This method computes and returns the derivative of a polynomial. You must ensure that the method returns 0 if the polynomial is merely a term with a constant value (e.g. P(x) = 2).
polynomial indefinite_integral() - This method computes the indefinite integral of this polynomial. The method uses the convention that the constant C, used in the expression F(x) + C, will be set to 1.
double definite_integral(double a, double b) - This method computes the definite integral of this polynomial, on the interval [a,b].
polynomial operator+(const polynomial& P1, const polynomial& P2) - This method adds two polynomials P1 and P2, and returns the result. Equivalent expression: P3 = P1 + P2.
polynomial operator-(const polynomial& P1, const polynomial& P2) - This method substracts two polynomials P1 and P2, and returns the result. Equivalent expression: P3 = P1 - P2.
polynomial operator*(const polynomial& P1, const polynomial& P2) - This method multiplies two polynomials P1 and P2, and returns the result. Equivalent expression: P3 = P1 * P2.
All operations must ensure that there is enough room to add terms into the resulting polynomials. If not, an assertion should be thrown.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
