Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python Implement a class Polynomial that models a polynomial function. You can assume that your Polynomial object has degree at most 50 . The

in python
image text in transcribed
Implement a class Polynomial that models a polynomial function. You can assume that your Polynomial object has degree at most 50 . The declaration of the class is in the file Polynomial.h. An object in the class Polynomial should have a private member variable that is an array of doubles to store the coefficients of the polynomial. (This is not a dynamic array.) If that member variable is called coeffs, then coeffs_[i] should be the coefficient of the term of degree i. An object in the class Polynomial should have a private member variable that is an int to store the degree of the polynomial. The only constructor should be a constructor with no arguments that creates the polynomial with degree 0 and all coefficients 0 . Overload the insertion operator to output a polynomial to an output stream, including cout, in a form similar to 1.0+2.0x+3.0x24.0x3. Make this operator a friend of the class. Overload the extraction operator to allow for input of a polynomial from an input stream, including cin. The input should be first a non-negative integer k for the degree of the polynomial followed by k+1 doubles for the coefficients of the terms. For instance, the polynomial above would be input as 31.02.03.04.0 Since the only constructor creates a zero polynomial, this extraction operator will be the way to actually get a non-zero polynomial. Make this operator a friend of the class. Look at the Rational class definition from Chapter 9 for examples of overloading the input and output operators. The class should have overloaded + for addition of polynomials and overloaded - for subtraction of polynomials. Both operators must create the correct array of coefficients and the correct degree. Creating the correct degree requires some thinking. The degree of a sum can be smaller than the degrees of the polynomials begin added because terms may cancel. Write a method eval that evaluates the polynomial at a specific value x that will be a parameter of the method. The method should return the value. A test program that uses these methods is posted, along with file Examples.txt that is to be used to read values into polynomials. The test program will work if you put it and Polynomial.h, Polynomial.cpp, and Examples.txt in the same project. That can be done in onlinegdb

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Which of the following are features of the maxillae

Answered: 1 week ago