Question: by answered by C++ CODING Question In this exercise you will be implementing the concept of composition to model polynomials. In mathematics, a polynomial is

 by answered by C++ CODING Question In this exercise you willbe implementing the concept of composition to model polynomials. In mathematics, apolynomial is a function composed of unit expressions called teruns. A polynomial

by answered by C++

CODING

Question In this exercise you will be implementing the concept of composition to model polynomials. In mathematics, a polynomial is a function composed of unit expressions called teruns. A polynomial can have one or more variables. However, the scope for this exercise is limited only to one or single variable polynomials. The following is an example of a single-variable polynomial. 5x2 - 2x + 7 Each term of a polynomial contains a coefficient and an exponent. The polynomial from the above example has three terms and their coefficient and exponent are shown in Table 1. Table 1 Terin Coeffiecient Exponent 2 5x2 5 -2x -2 1 7 7 0 Then, a single-variable polynomial can be modeled with two classes as shown in Figure 1 and their descriptions are given in Table 2. Polynomial -1..* Polynomial (...) read() evaluate (x) term(e) largest Term () constanto) degree() toString() Term coef exp Term (...) set (...) coefficient Jexponent() Jevaluate (X) toString() Figure 1 Table 2 Description Class Members (attributes / methods) class Term coef and exp Term The attributes for the terms's coefficient and exponent, respectively. Tips: The declaration for these attributes have been provided in the template program The constructor (s) such as overloaded, default constructor, etc. Tips:The code for the constructor has been provided in the template program sets the terms attributes, coef and exp respectively. retun the term 's attributes, coef and exp respectively. set (c,e) coefficient and exponent() evaluate (x) evaluates the term with the value of x. For example, if x=2, then the term 5x2 will evaluate to 5(22) = 20, and the term -2x will evaluate to -2(2)=-4. Tips: Use the math function, pow () to implement this method. Returns a string representing the term. For example, if the term is 3x+ (1.e. coef=3 and exp=4), this method will retun a string of "3x*4". Notes: the character represents to the power of Tips:The code for this method has been provided in the template program. toString() class Polynomial Attributes Polynomial read evaluate (x) Determine the attributes for this class on your own. The constructor (s) such as overloaded, default constructor, etc. sets the terms of a polynomial from user input. The user needs to enter the coefficient and exponent for each term. evaluates the polynomial by summing up all the terms based on the value of x. For example, if x=2, then the polynomial 5r2 - 2x + 7 will evaluate to 20-4 + 7 = 23. Tips: this method should make use of the Term's evaluate () method. retuns the term whose exponent e. If the polynomial does not have a term with the exponent e, then this method returns a zero term, i.e., a term with the coefficient and exponent set to 0. Notes: A zero term can be created by the default constructor of the class Term. retuns the term whose the largest exponent. For example, the largest term in the polynomial 5x2 - 2x + 7 is 5x?, 5+risx, x2 - 4x2 + x is - 4x' and term(e) largest Term) so on constant retuns the constant value of a polynomial. For example, the constant of the degree() polynomial 5x- 2x + 7 is 7, x-5 is-5, 9x is 0 and so on. Tips: this method should make use of the method term(). retuns the degree of a polynomial by taking the largest exponent. For example, the degree of the polynomial 5x2 - 2x + 7 is 2, x-5 is 3, 9x is 1 and so on. Tips: this method should make use of the method largestTerm(). Returns a string representing the polynomial. For example, if the polynomial is 5x7 - 2x + 7, then this method will return a string of "5x^2-2x+7". Tips: this method should make use of the Term's toString() method. toString() Based on the classes above, complete the program exercise..cpp: Notes: Use only a single source code file for this exercise. However, the class declaration and definition must be separated. 1. Implement the class Term. Do not add any additional members for this class. 2. Implement the class Polynomial. Add all required attributes. Do not add additional members. 3. In the main function, write the code to a. create a Polynomial object and add terms to the polynomial using user inputs. b. print the information about the polynomial including: o the equation o the degree o constant term o the largest term c. evaluate the polynomial with several values of x entered by the user and print the results onto the screen See Figure 2 for example runs of the program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!