Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This should be done in c++ language, and better to be implemented in visual studio code. Thank you in advance for much needed help In

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

This should be done in c++ language, and better to be implemented in visual studio code. Thank you in advance for much needed help

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 terms. 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 coeffiecient and exponent are shown in Table 1. Table 1 Term Coeffiecient Exponent 2 5r2 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. 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) largestTerm() constant() degree() toString() Term coef exp Term (...) jset (...) coefficient() exponent() Jevaluate (x) toString() Figure 1 Table 2 Description Class Members (attributes / methods) class Term coef and exp The attributes for the terms's coefficient and exponent, respectively. Tips:The declaration for these attributes have been provided in the template program Term() 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. set (c, e) coefficient () and exponent() return the terms attributes, coef and exp respectively. 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. toString() Returns a string representing the term. For example, if the term is 3.x* (i.e. coef=3 and exp=4), this method will return 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. class Polynomial Attributes Determine the attributes for this class on your own. Polynomial() The constructor (s) such as overloaded, default constructor, etc. read() evaluate (x) 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 522 - 2x + 7 will evaluate to 20-4+ 7 = 23. Tips: this method should make use of the Term's evaluate () method. term(e) returns 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. largestTerm() returns the term whose the largest exponent. For example, the largest term in the polynomial 5x - 2x + 7 is 5x2, 5 + x is r, x2 - 4x + x is - 4x and so on. constant () returns the constant value of a polynomial. For example, the constant of the degree() polynomial 5r2 - 2x + 7 is 7, X - 5 is -5, 9x is 0 and so on. Tips: this method should make use of the method term(). returns the degree of a polynomial by taking the largest exponent. For example, the degree of the polynomial 5x - 2x + 7 is 2, x3 - 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 5x2 - 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() 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 Output: Expected result from the program is as shown in Figure 2. Bold text indicates keyboard inputs. Run 1 - user enters the polynomial 5x2 - 2x + 7 Enter a polynomial: How many terms? => 3 Enter term #1 (coef and exp) => 5 2 Enter term #2 (coef and exp] => -2 1 Enter term #3 (coef and exp) => 7 0 Polynomial Information : 5x^2-2x+7 Equation Degree : Constant : Largest Term : f (x) 2 7 5x^2 Polynomial Evaluation Enter how many x values => 3 Enter the x values => 5 0 1 f (x) 5 0 122 7 10

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

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions

Question

1. A definition of control

Answered: 1 week ago

Question

plan how to achieve impact in practice from your research;

Answered: 1 week ago