Question
A single variable polynomial is represented as an arithmetic expression shown below: A0 + A1 * x + A2 * x 2 + + Ak
A single variable polynomial is represented as an arithmetic expression shown below: A0 + A1 * x + A2 * x 2 + + Ak * x k
The highest exponent, k, is called the degree of the polynomial, and the constants A0, A1, , Ak are the coefficients. For example, here are two polynomials with degree 3:
2.1 + 4.8x + 0.1x2 + (-7.1)x3
2.9 + 0.8x + + 1.7x3
Design, and implement a class for polynomials. The class may contain a static member constant, MAX, which indicates the maximum degree of any polynomial (this allows you to store the coefficients in an array with a fixed size).
The default constructor will be one which will initialize the polynomial with all coefficients set to zero. In addition, you must have another constructor that takes two parameters: degree, and coefficient_array which are used to initialize the polynomial appropriately. In addition you should have a member function that gets and sets the value of an appropriate coefficient. For example, get(k) returns the coefficient of xk , and set(k, 24.5) sets the coefficient of xk to 24.5. You should provide a member function for comparing two polynomials (whether they have same coefficients), and evaluating a polynomial value for specific value of x, say x = 5.7.
Please implement poly.cpp in (In C++ please) given the following poly.h header file:
#ifndef POLY_H
#define POLY_H
class poly
{
public:
static const int MAX = 10;
// CONSTRUCTORS
poly( );// a polynomial with degree 0
poly(const int k );// a polynomial with degree k
poly(const int k, const double initial_coeff[] );
// MEMBER FUNCTIONS
void set(const int k, const double coeff);// sets the kth coefficient
// CONSTANT MEMBER FUNCTIONS
int get(const int k ) const;// gets the kth coefficient
int degree() const;
double evaluate (const double xval) const;//evaluates the polynomial
private:
double data[MAX];
int degree;
};
}
#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