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().
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
