Hello all,

I hope I find the help I need here. I am sorry I am not good enough in C++ yet. This is my first year so please be patient with me.

This is my problem:

p = 4x^5 + 7x^3 - x^2 +9

the ADT operations are:

p.degree() is 5 ( the highest power of a term with a nonzero coefficient )
p.coefficient (3) is 7 ( the coefficient of the x^3 term )
p.coefficient (4) is 0 ( the coeffient of a missing term is implicitly 0 )
p.ChangeCoefficient (-3, 7) produces the polynomial
p = -3x^7 + 4x^5 + 7x^3 - x^2 +9

so the question is : Using these ADT operations, write statements to perform the following tasks:

a. Display the coefficient of the term that has the highest power.
b. Increase the coefficient of the x^3 term by 8.
c. Compute the sum of two polynomials.

My answers so far:

a.

cout<< "The coefficient of the term that has the highest power is: " << p.degree();

b.

cout<< "The new coefficient of x^3 is: " << p.changeCoefficient(7+8, 3);

c. I couldn't get this one. I am a little bit confused.


Thanks for your help in advance

Say you have for example polynomials a and b.

Polynomial sums are calculated by summing the coefficients of the same power terms. So first you have to figure out how many terms the polynomials have and work your way down from there using a loop.

maxdegree = max(a.degree() , b.degree() )

You can store the results in a new polynomial object or a/b

result.changeCoefficient( a.coefficient(maxdegree)+b.coefficient(maxdegree) , maxdegree )

Hope this helped

thanks, but what about section a and b am I true or not?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.