Question: storedPolynomial is a 2D array that carries coefficients and exponents. A storedPolynomial[0][X] indicates that it's a coefficient, and storedPolynomial[1][X] indicates an exponent. p.setCoefficient(newCoefficient, coefficient) sets

storedPolynomial is a 2D array that carries coefficients and exponents. A "storedPolynomial[0][X]" indicates that it's a coefficient, and "storedPolynomial[1][X]" indicates an exponent. p.setCoefficient(newCoefficient, coefficient) sets a new term in the polynomial, and is called from a class. p.display() is called from a class, which displays the polynomial. For example:

storedPolynomial[0][0] = 4; // A coefficient of 4

storedPolynomial[1][0] = 5; // An exponent, 5, that assigned to 4 from the function above. (Because the [0] at the end of both "storedPolynomial"s matches with it).

p.setCoefficient(storedPolynomial[0][0], storedPolynomial[1][0]); // Sets the coefficient and exponent in the polynomial.

p.display(); returns "+ 4x^5"

storedPolynomial[0][1] = -6; // A coefficient of 6

storedPolynomial[1][1] = 7; // An exponent, 7, that assigned to -6 from the function above. (Because the [1] at the end of both "storedPolynomial"s matches with it).

p.setCoefficient(storedPolynomial[0][1], storedPolynomial[1][1]); // Sets the coefficient and exponent in the polynomial.

p.display() returns "- 6x^7 + 4x^5"

storedPolynomial[0][2] = 4; // A coefficient of 4

storedPolynomial[1][2] = 7; // An exponent, 7, that assigned to 4 from the function above. (Because the [1] at the end of both "storedPolynomial"s matches with it).

p.setCoefficient(storedPolynomial[0][2], storedPolynomial[1][2]); // Sets the coefficient and exponent in the polynomial.

p.display() returns "+ 4x^7 + 4x^5" (Note that it replaced "-6x^7").

-------

Assume that 8 total coefficients and 8 total exponents are given and already assigned.

"storedPolynomial[0][0]" through "storedPolynomial[0][3]" are the 4 coefficients for polynomial one, and "storedPolynomial[1][0]" through "storedPolynomial[1][4]" are the 4 exponents for polynomial one.

"storedPolynomial[0][4]" through "storedPolynomial[0][7]" are the 4 coefficients for polynomial two, and "storedPolynomial[1][4]" through "storedPolynomial[1][7]" are the 4 exponents for polynomial two.

Write a function that takes "storedPolynomial[0][0]" through "storedPolynomial[0][7]" (8 total coefficients) and "storedPolynomial[1][0]" through "storedPolynomial[1][7]" (8 total exponents) that combines like-terms and displays the full polynomial using p.display().

Programming language is in C++.
Sample Output (two coefficients/exponents instead of four from each polynomial will be used to save space):
Polynomial 1:
storedPolynomial[0][0] = 4 (Coefficient 1)
storedPolynomial[0][1] = 5 (Coefficient 2)
storedPolynomial[1][0] = 3 (Exponent 1)
storedPolynomial[1][1] = 2 (Exponent 2)
(4x^3+5x+2)
Polynomial 2:
storedPolynomial[0][4] = 5 (Coefficient 5)
storedPolynomial[0][5] = -3 (Coefficient 6)
storedPolynomial[1][4] = 3 (Exponent 5)
storedPolynomial[1][5] = 1 (Exponent 6)
(5x^3-3x^1)
(Answer goes here. p.setCoefficient(exponent, power) will need to be used to change the polynomial, as seen from above).
(Example of p.SetCoefficient being used when two exponents are the same):
p.setCoefficient(storedPolynomial[0][0] + storedPolynomial[0][4], storedPolynomial[1][0]);
(Instead of storedPolynomial[1][0], storedPolynomial[1][4] may be used, too, since its the same exponent).
Write a loop that checks to see if any exponents (while "storedPolynomial[1][X]" indicates an exponent) are equal to each other. If there are, then add the coefficients of both of them together. (A coefficient/exponent matches with one another if the second number in the 2D array are the same. So storedPolynomial[0][0] is a coefficient and storedPolynomial[1][0] is the exponent that belongs to that coefficient).
Outpuf: 9x^3+5x^2-3x

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!