Design, implement and test a class Poly for polynomials. A polynomial has the form anxn
+ an-1xn-1 + … + a1x + a0. You’ll need to use a vector to store exponents and coefficients. You should implement a constructor that takes a coefficient and an exponent as arguments so that you can write
Poly c = Poly(3,4) + Poly(2,2) + Poly(7,1) + Poly(-5,0);
to get the polynomial 3x4 + 2x2 + 7x – 5. You should overload the arithmetic operators +=, -= and +, - for addition and subtraction. You should overload *= to multiply a polynomial by a constant: 3(2x3 - 3x) = 6x3 – 9x. Finally you should include a member function at that evaluates a polynomial at a specific value for x. For example for the above polynomial:
double d = c.at(0) // d 5 = 3*04 + 2*02 + 7*0 -5
Design, implement and test a class Poly for polynomials. A polynomial has the form anxn?
All the instructions to accomplish this are in the text of your question. So start like this:
class Poly
. . .
and just fill in the details.
(now go do your homework)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment