My C++ teacher for my past 2 classes has been horrible. She doesn't help when we need it and the tutors at my school don't either. I just need help getting started on this first project. I"ll seriously take any help I can get.
Problem: You will create the implementation of a Polynomial data type.
Specifics: I will provide the Polynomial class specification and a driver program to test your Polynomial
class. It is your job to fill in the methods/functions I have specified.
Data Representation:
Your Polynomial will be represented as a 21-term integer array. The index to the array
represents the degree. The value at a given index is the coefficient for that degree. Since there
are only 21 terms, your highest index will be 20 and your lowest 0. Therefore, your highest
exponent will be 20 and your lowest 0. Let’s assume we wanted to store the following
polynomial: x20 + 3x16 + 15x4 + 2x3 + 16x2 + 5. In the instance of such a Poly, our terms array
would look like the following:
examplePoly.terms
This seems pretty straight forward.
You just have to fill in the functions in class Poly.
What do you have so far?
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
welcome!
please learn about code tags, the <> on the side editor, or code and /code in [] brackets to block it off.
Also, asking a specific question will get you much farther than 'help me'.
a poly is easier to represent in reverse: in math you put the high exponent first, x^2+3x+5 but in code, array[0] = 5; array[1] = 3; array[2] = 1 ... and it may not be obvious but the array index is the power of x (anything to 0 is 1, so the first term there is 5*x^0 which is 5).
note that missing terms just get a zero. so x^2 is p[0] = 0, p[1] = 0], and p[2] = 1 right?
a pointer would near give you the derivative. not exactly, but..
int poly[20];
int *deriv = &poly[1]; //deriv is now shifted the above power scheme.. poly[1] is now deriv[0] so all your exponents dropped a power, so you just need a simple multiply loop to finish it up. This is destructive, so if you need to keep the original poly as well, you can't get as much freebie from this approach. If you discard the poly or work with a copy, its useful, just remember its size is -1 too so don't go out of bounds.
other advice... knock out the simple ones first.
using the scheme to store it that I gave you, addition should be very simple, for example!
Did it ASK for integers? Can you not have 3.14R^2 in this world?