Objectives To create a linked-chain data structure To understand how to apply mathematical algorithms...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Objectives • To create a linked-chain data structure • To understand how to apply mathematical algorithms Instructions For this program, you will implement two classes, one representing a single term, and one representing a polynomial. The Polynomial class must support the following: . 2 constructors . . o A constructor that takes two parameters: exponent and coefficient A copy constructor A print method Recall that if we have, for example, the term 3x², then 3 is the coefficient, and 2 is the exponent Operations 0 o The method should print the polynomial This constructor will take, as its argument, a reference to the Polynomial which it is supposed to copy . clone method This method is inherited from Object You must override it to work correctly It copies and returns a new Polynomial object, which is a (deep) copy of the original that it is cloning . . o A Term node reference to point to the next node in the chain of linked nodes o Methods to get and set the exponent, coefficient, and next node The Polynomial class must keep track of the first node in the polynomial. Therefore one of its fields should be a Term reference Although the two-parameter constructor only allows a Polynomial to contain a single term to start off with, the add method allows for terms and larger polynomials to be combined, and the copy constructor and clone methods allow for creation and copying of larger polynomials When the add method is called, the polynomial that is passed in is added to whatever exists in the current polynomial For example: If polyA contains the polynomial 3x²+2x+5 and poly8 contains 3x+2, then the polyA will become: 3x² + 5x+7 Each of the terms, 3x², 5x, and 7 have their own Term object associated with them. They are in a linked chain. You can assume that all Polynomials will maintain and be passed in by standard form. For example, the polynomial inputs to add, or that will be copied, etc. - will always keep the form 3x² + 2x + 5, not something else like 2x+5+ 3x². The highest term always comes first, then second highest, etc. Some polynomials might have "missing" terms. Not all will be given with all the intermediate terms. For example, 5x² + 2x would be a perfectly acceptable polynomial, even though there is no x² term or constant o Note that a constant would be represented in a Term object by having an exponent of 0, because 2x⁰ = 2, since anything to the nower 0 is 1 we would have ?*1=2 Note that a constant would be represented in a Term object by having an exponent of 0, because 2x = 2, since anything to the power 0 is 1, we would have 2*1 = 2. • A visual of a polynomial chain would look like this: . To represent the polynomial 3x² + 2x + 3, we would have polyRef→[3x²] → [2x] → [3]→null For 4x³ - 2x you would have: polyRef →[4x³] → [-2x]→null Notice that the "minus" is represented by having the coefficient of the second term in the polynomial set to a -2. Major Hints / Design considerations: While coming up with a solution might seem daunting, especially when you must copy, add, or clone an entire arbitrary-length polynomial, keep some things in mind: o Like-terms are combined when add is called E.g., if you have the two polynomials polyA and polyB, and they each have respective x² terms, you add the coefficients If you are traversing a polynomial, you know you're finished when you reach null Objectives • To create a linked-chain data structure • To understand how to apply mathematical algorithms Instructions For this program, you will implement two classes, one representing a single term, and one representing a polynomial. The Polynomial class must support the following: . 2 constructors . . o A constructor that takes two parameters: exponent and coefficient A copy constructor A print method Recall that if we have, for example, the term 3x², then 3 is the coefficient, and 2 is the exponent Operations 0 o The method should print the polynomial This constructor will take, as its argument, a reference to the Polynomial which it is supposed to copy . clone method This method is inherited from Object You must override it to work correctly It copies and returns a new Polynomial object, which is a (deep) copy of the original that it is cloning . . o A Term node reference to point to the next node in the chain of linked nodes o Methods to get and set the exponent, coefficient, and next node The Polynomial class must keep track of the first node in the polynomial. Therefore one of its fields should be a Term reference Although the two-parameter constructor only allows a Polynomial to contain a single term to start off with, the add method allows for terms and larger polynomials to be combined, and the copy constructor and clone methods allow for creation and copying of larger polynomials When the add method is called, the polynomial that is passed in is added to whatever exists in the current polynomial For example: If polyA contains the polynomial 3x²+2x+5 and poly8 contains 3x+2, then the polyA will become: 3x² + 5x+7 Each of the terms, 3x², 5x, and 7 have their own Term object associated with them. They are in a linked chain. You can assume that all Polynomials will maintain and be passed in by standard form. For example, the polynomial inputs to add, or that will be copied, etc. - will always keep the form 3x² + 2x + 5, not something else like 2x+5+ 3x². The highest term always comes first, then second highest, etc. Some polynomials might have "missing" terms. Not all will be given with all the intermediate terms. For example, 5x² + 2x would be a perfectly acceptable polynomial, even though there is no x² term or constant o Note that a constant would be represented in a Term object by having an exponent of 0, because 2x⁰ = 2, since anything to the nower 0 is 1 we would have ?*1=2 Note that a constant would be represented in a Term object by having an exponent of 0, because 2x = 2, since anything to the power 0 is 1, we would have 2*1 = 2. • A visual of a polynomial chain would look like this: . To represent the polynomial 3x² + 2x + 3, we would have polyRef→[3x²] → [2x] → [3]→null For 4x³ - 2x you would have: polyRef →[4x³] → [-2x]→null Notice that the "minus" is represented by having the coefficient of the second term in the polynomial set to a -2. Major Hints / Design considerations: While coming up with a solution might seem daunting, especially when you must copy, add, or clone an entire arbitrary-length polynomial, keep some things in mind: o Like-terms are combined when add is called E.g., if you have the two polynomials polyA and polyB, and they each have respective x² terms, you add the coefficients If you are traversing a polynomial, you know you're finished when you reach null
Expert Answer:
Related Book For
Research Methods For Business Students
ISBN: 9781292208787
8th Edition
Authors: Mark Saunders, Philip Lewis, Adrian Thornhill
Posted Date:
Students also viewed these databases questions
-
You are considering the decision of whether or not to crash your project. After asking your operations manager to conduct an analysis, you have determined the "precrash" and "postcrash" activity...
-
What costs are irrelevant for the decision of whether to sell a joint product or process it further?
-
What issues affect the decision of whether to standardize or adapt international advertising?
-
Lang Enterprises was started when it acquired $4,000 cash from creditors and $6,000 from owners. The company immediately purchased land that cost $9,000. Required a. Record the events under an...
-
State the conclusions of the experiment in words. Gain of a Semiconductor Factor. Temaure Partial Relattve Aging Location of pressure humldity time assembly 15 Level 1 68F 10 Level 2 74F 10-30% 144...
-
In Exercises complete the table for the radioactive isotope. Half-life Initial Isotope (in years) Quantity 14C 5715 Amount After 1000 Years 1.6 g Amount After 10,000 Years
-
Eduardo and Ana recently bought a new dining room table that they saw advertised on a furniture manufacturers Web site. When the table arrived and they opened the box, they discovered long, deep...
-
Cameron Company has two production departments and a maintenance department. In addition, the company keeps other costs for the general plant in a separate account. The estimated cost data for Year 1...
-
*****PLS NEW EXPLANATIONS 1. Four friends plan to form a corporation for purposes of constructing a shopping center. Charlie will be contributing the land for the project and wants more security th...
-
Develop an MRP record, similar to the one in Figure 4-17, for wheat germ for the five weeks of January. Wheat germ must be ordered in bulk-container quantities, so the planned orders must be in...
-
What are the nuances of incorporating data visualization and infographics into business reports for enhanced comprehension ?
-
17. The function can be approximated by the series 1 f(x) = 1 = 7 f(x) 1 + x + x + x + x +...+xn as long as x < 1. We would like to explore how many terms are needed to make the difference between...
-
What are a few of the main benefits of utilizing process technology to increase operational effectiveness?
-
2. Darrell spoke with a financial advisor and learns he can afford to make monthly payments of $1000 for the next 5 years in order to start a business. At this point in time, he is able to borrow an...
-
Solve the absolute value inequality. Write the solution in interval notation. 3x+4+36
-
1. Consider the following Java program, which consists of the class Spends. Notice this defines getSpend, is Amount and tostring methods. Remember that Integer.parseInt applied to a string...
-
Data Privacy Day is globally held annually on Question 2 options: January 28th. December 12th. March 10th. June 15th
-
As water moves through the hydrologic cycle, water quality changes are common because of natural phenomena or anthropogenic pollution. Using Figure 11.1, describe how water-quality changes occur...
-
Briefly describe when you would use regression analysis and correlation analysis, using examples to illustrate your answer.
-
Visit an online database or your university library and obtain a copy of a research-based refereed journal article that you think will be of use to an assignment you are currently working on. Read...
-
Revisit Table 1.2 and look at the differences in management researcher and practitioner orientations for foci of interest, methodological imperatives, key outcomes and how each views the other. For...
-
At the end of the accounting period, a journal entry is made to close variance accounts to_or________________________,and________________________,.
-
How does Porters competitive forces model help companies develop competitive strategies using information systems? Define Porters competitive forces model and explain how it works. Describe what...
-
True or false? Standard cost variances provide definitive evidence that costs are out of control and managers are not performing effectively.
Study smarter with the SolutionInn App