Question: Question 1: [40 points] in mathematics, a Polynomial is a collection of terms, connected together by the addition or the subtraction operators. Each term contains
Question 1: [40 points] in mathematics, a Polynomial is a collection of terms, connected together by the addition or the subtraction operators. Each term contains a coefficient and an exponent. The Polynomial "2.2 x4 + 3.5 x2 - 5.3", for example, consists of three terms, namely, "2.2 x4" which has the coefficient 2.2 and the exponent is 4, "3.5x2" which has the coefficient 3.5 and the exponent 2 and "-5.3" which has the coefficient -5.3 and the exponent 0. For the benefit of this problem, we will assume the exponent for all terms to be positive integers (0, 1, 2etc).
A Polynomial can be represented using a one dimensional array, where the array cells are indexed using the terms exponents and the corresponding coefficients are stored within these cells. The array, below represents the Polynomial 2.2 x4 + 3.5 x2 - 5.3.
The C++ class representing a Polynomial is outlined below. It stores the maximum number of terms within a given polynomial as well as a pointer to a dynamically allocated array of floats that stores the polynomial coefficients. For example, an object for the above polynomial will look as follows:
The skeleton for the Polynomial class would look like:
class Polynomial{
friend ostream & operator << (_______________________________);
/* overloading the standard insertion (output) operator. If the polynomial is
empty, the insertion operator would print out This Polynomial is empty. */
friend Polynomial operator+ (_________________________________);
/* overload the + operator that add two equal sized polynomials together and
generate a new one. An example is the addition of 5 x2 + x + 1and 3x2 +
2 will result in the Polynomial 8x2 + x + 3 */
public:
Polynomial (_____________________________);
/* the parameterized and default constructor which creates an empty Polynomial with maxTerms equal to n, n is defaulted to 5.
Polynomial (______________________________) // The copy constructor
~ Polynomial ( ); // The class destructor
Polynomial & operator= (_______________________ );
// Overload the assignment operator (=) to assign one Polynomial to another.
Polynomial addTerm (int coefVal, int expoVal);
//add a new term to the polynomial
double evaluate ( float x); // Evaluate the polynomial for a given x value
private:
int maxTerm // the max number of terms that the Polynomial can have.
float * ttable; // array that stores the coefficients of a polynomial indexed by
// the exponents of that polynomial
};
For the Polynomial class, defined above, implement its member and friend functions below. Hint: you are allowed to use the math library.
Complete the declaration of the Polynomial class.
Implement the parameterized and default constructor
Implement the copy constructor
Implement the class destructor
Overload the assignment operator (=)
Implement the polynomial evaluate function.
Overload the binary addition operator ( + ) as a friend function
Overloading the standard insertion (<< ) operator such that the polynomial is printed out as follows:
Number of terms: 3
Term-0: -5.3
Term-2: 3.5
Term-4: 2.2
Implement the Polynomial member function addTerm ( ) that add a new term to an already existing polynomial object. In this implementation, make sure to check for possible errors.
Test all developed member and friend functions of the polynomial class using a comprehensive main ( ) program. Show your screen shots with a white background and a readable font.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
