Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I keep getting error squiggles In this programming assignment, you will use the Standard Template Library to program a polynomial. A polynomial has terms each

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

I keep getting error squiggles

In this programming assignment, you will use the Standard Template Library to program a polynomial. A polynomial has terms each of which has a coefficient that multiplies into an unknown raised to a power. For example, 2x5 - 5x4+x3+3x2+ 9x - 4 is a polynomial. 1. First write a Term class. Here is the specification of the member functions of Term class in the public section: Term(int coef, int expon) Constructor for objects of class Term. Represents coef * x expon Parameters: coef - the coefficient value expon - the exponent value Term(const Term &term) This is a constructor for objects of class Term whose objects represents coef * x expon Parameter: term an object of class Term int getCoefficient() Fetch coefficient value. Returns: the coefficient value int getExponent() Fetch exponent value. Returns: the exponent value void setCoefficient(int coef) Replace coefficient value with new one. Postcondition: getCoefficient) coef Parameters: coef - the new coefficient vstlue. w WWW void setExponent(int expon) Replace exponentt value with new one. Postcondition: getExponent() expon Parameters: expon - the new coefficient value. bool operator (Term &term) Imposes "natural ordering" on Term objects. This permits arrays and STL lists of Term objects to be sorted and arranged by STL algorithms and member functions. Ordering is based primarily on exponent value and secondarily on coefficient value (e.g. if exponents are equal, decision is based on coefficients). bool operator>Term &term) Imposes "natural ordering" on Term objects. This permits arrays and STL lists of Term objects to be sorted and arranged by STL algorithms and member functions. Ordering is based primarily on exponent value and secondarily on coefficient value (e.g. if exponents are equal, decision is based on coefficients). Parameters: term - The Term against which "this" Term is compared Returns: Returns true if this" Term object is equal to term and false otherwise. bool operator (Term &term) Imposes "natural ordering" on Term objects. This permits arrays and STL lists of Term objects to be sorted and arranged by STL algorithms and member functions. Ordering is based primarily on exponent value and secondarily on coefficient value (e.g. if exponents are equal, decision is based on coefficients). Parameters: term - The Term against which "this" Term is compared Returns: Returns true if this Term object is less than term and false otherwise. void combine(Term term) Combines "this" term and the argument term back into "this" term. Terms are combined by adding their coefficients. Parameters: term - the term to be folded into "this" term. Term &product(Term &a, Term &b) Returns a Term formed by the profluct of two Terms. The product (multiplication) is a term formed by multiplying the coefficients and adding the exponents. For example, the product of 3x2 and 4x is 12x3. Parameters: a - first term in the product. b - second term in the product. Returns: a new Term containing the product of the two argument terms. string toString/ Returns a string representing of this term, with fully signed coefficient and using nothing for multiplication and for exponentiation. Returns: a string equivalent of this term. Second write a Polynomial class. The polynomial class will have an instance variable in the private section with this declaration: list poly: 1 In the public section will be member functions whose specification is below: Polynomial Constructor for objects of class Polynomial Polynomial(string init) Constructor with initial polynomial as String. Format is very restricted. Parameters: init - the initial polynomial. This format MUST be followed: each term consists of two integers separated by one or more spaces: an integer coefficient and an integer exponent. Likewise, each term must be separated by one or more spaces. The terms can be given in any order. For example "3 0 5 -2 -11" represents 3 + 5x-2 - X void addTerm(Term term) Add a term to the polynomial. If "this" polynomial already has a term with the same exponent as the argument, the argument term will be combined with the existing one. Parameters: term - a term to add into "this" polynomial. double evaluate(int x) Evaluates the polynomial for given value of variable x. Parameters: x- the x-value at which to evaluate. Returns: value of the expression for that X. Polynomial &sum(Polynomial &a, Polynomial &b) Produces new polynomial which is umont polynomials The sum is a polynomial consisting of all Polynomial &sum(Polynomial & Polynomial &b) Produces new polynomial which is the sum of the two argument polynomials. The sum is a polynomial consisting of all terms from both polynomials, with terms having same exponent combined. For example, the sum of x 2 + 2x - 1 and 2x3 + 3x is 2x3 + x2 + 3x + 2x 1 = 2x3 + x 2 + 5x - 1. Parameters: a - a polynomial b - a polynomial Returns: a polynomial representing the sum of a and b. Polynomial &product(Polynomial &a,Polynomial &b) Produces new polynomial which is the product of the two argument polynomials. Product is a polynomial whose terms are formed from the product of each term in the first polynomial with all the terms of the second, combining terms with the same exponent. For example, the product of 2x+3 and 4x-1 is (2x*4x) + (2x*-1) + (3*4x) + (3*-1)= 8x2 - 2x + 12x - 3 = 8x2 + 10x - 3. Parameters: a - a polynomial b - a polynomial Returns: a polynomial representing the product of a and b. string to String() Produce string representation of a Polynomial Returns: String representing the polynomial. Terms are listed in decreasing order by exponent. Write a main() function and any supporting functions in a driver program that declares an array of Polynomial objects and provides code for a menu to input a polynomial, evaluate a polynomial, multiply polynomials, add polynomials, or display a string version of a polynomial. Give a user the option to list the contents of the array of polynomials. a

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