Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ please Implement a class Polynomial that modcls a polynomial function. You can assume that your Polynomial object has degree at most 50 . The

c++ please
image text in transcribed
Implement a class Polynomial that modcls a polynomial function. You can assume that your Polynomial object has degree at most 50 . The declanation 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 cocfficients of the polynomial. (This is not a dynamic array.) If that member variable is called cocffs. then cocffs.[1] should be the cocfficient of the term of degree i. An object in the class. Polynomial should have a private member variable that is an int to store tbe degree of the polynomial. The only constructor should be a constructor with no arguments that creates the polynomial with degree 0 and all cocfficients 0 . Overload the insertion operator cs to output a polynomial to an output stream, including cout, in a form similar so 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 fricnd of the class. Look at the Rational class definition from Chapler 9 for examples of overloading the input and output opcrators. 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 eorrect 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 programs will work if you put it and Polynomial.h. Polynomial cpp, and Examples txt in the same project. That can be done in onlinegdb. Submit your complete class definition and the results of running the test program by the end of the day on November 23, 2022

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

International Baccalaureate Computer Science HL And SL Option A Databases Part I Basic Concepts

Authors: H Sarah Shakibi PhD

1st Edition

1542457084, 978-1542457088

More Books

Students also viewed these Databases questions

Question

7-16 Compare Web 2.0 and Web 3.0.

Answered: 1 week ago