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...
-
Does the extent of labor unionism explain the difference between European and U.S. unemployment rates?
-
Solve for the predicted values of y and the residuals for the data in Problem 12.7. The data are provided hereagain: 140 25 119 29 103 46 91 70 65 88 29 112 24 128
-
A single-degree-of-freedom system has a softening spring and is subjected to a harmonic force with the equation of motion given by Find the response of the system numerically using the fourth-order...
-
In a government report in 2012,1 it was estimated that Air Force One costs the taxpayers $ 179,750 per hour. Air Force One is a custom- built Boeing 747 for the presidents use while in office. (There...
-
A pile group consists of nine friction piles in clay soil (see Figure 10-40). The diameter of each pile is 16 in., and the embedded length is 30 ft each. Center-to-center pile spacing is 4 ft. Soil...
-
A project that will provde annual cash flows of $2,800 for nine years costs $9,200 today. a. At a required return of 11 percent, what is the NPV of the project? b. At a required return of 27 percent,...
-
The walls of a cold-storage room kept at 8F are insulated with a 4- in. layer of cork. The external air is at 72F and has a dew point of 60F. Since cork is porous, air diffuses across the insulating...
-
A parallel-plate capacitor with circular plates of radius \(R=0.10 \mathrm{~m}\) and separation distance \(d=0.10 \mathrm{~mm}\) is charged by a constant current of \(1.0 \mathrm{~A}\). (a) What is...
-
Double-pane glass windows, designed to reduces heat losses, consist, as the name implies, of two glass panes separated by a thin gap filled with dry air and sealed. Lets compare the efficiency of a...
-
The average intensity \(S\) of the Sun's radiation at Earth's surface is approximately \(1.0 \mathrm{~kW} / \mathrm{m}^{2}\). Assuming sinusoidal electromagnetic waves, what are the root-mean-square...
-
Hospital visits. Geil et al. (1997) fit a negative binomial random effects model to explain the number of hospital visits using panel data on 5180 individuals drawn from 8 waves of the GSOEP from...
-
Explain the "Separate Procedure" designation as it pertains to certain CPT codes performed during the course of an operation.
-
(a) What do data breach notification laws require? (b) Why has this caused companies to think more about security?
-
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...
-
From thermodynamics, we know that the coefficient of performance of an ideal air conditioner \(\left(C O P_{\text {ideal }} ight)\) is given by \[C O P_{\text {ideal }}=\frac{T_{L}}{T_{H}-T_{L}}\]...
-
The maximum theoretical flow rate (slug/s) through a supersonic nozzle is \[\dot{m}_{\max }=2.38 \frac{A_{t} p_{0}}{\sqrt{T_{0}}}\] where \(A_{t}\left(\mathrm{ft}^{2} ight)\) is the nozzle throat...
-
The kilogram force is commonly used in Europe as a unit of force. (As in the U.S. customary system, where \(1 \mathrm{lbf}\) is the force exerted by a mass of \(1 \mathrm{lbm}\) in standard gravity,...
Study smarter with the SolutionInn App