The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
If so, I may need your help a bit in the next couple of days, it may help if you are immune to a guilty conscience!
> However, I'm not going to just blurt out the code so you
> can easily convert it, because that defeats the point of learning.
Oops!
I can't believe I just spent some of my saturday afternoon doing C++. Or more accurately I can't believe I just did that C++ instead of the C++ I should be doing.
So the maths bit is pretty easy. Declare two arrays and an index variable i (for loops):
int polynomial[11];
int derivative[10];
int i;
I don't know the ins and outs of how you're supposed to get input from the screen but you need to assign the coefficients of each successive term to the array polynomial. So if your polynomial was 4 + 3x + 3x^2 + 4X^10 then the array polynomial should be [4,3,3,0,0,0,0,0,0,0,4]
The simplest way to do this is probably:
for (i=0; i<11; i++)
{
cout << "Input coefficient for the X^" << i << " term: ";
cin >> polynomial[i];
}
Then you need to calculate the right values for the derivative and place them in the derivative array; and because the 'to the power' bit of each X value is equivalent to its position in the original polynomial array this is very simple:
for (i=1; i<11; i++) //The first item in the polynomial is discarded so you start with i=1, the second element.
{
derivative[i-1] = polynomial[i] * i;
}
You then need to output the derivative:
for (i=0; i<10; i++)
{
if (i==0)
{cout << derivative[i]<< " ";}
else
{
if (derivative[i] < 0)
{cout << derivative[i] << "X^" << i << " ";}
if (derivative[i] > 0)
{cout << "+" << derivative[i] << "X^" << i << " ";}
}
}
getchar();
If the polynomial you input is 4 + 3x + 3x^2 + 4X^10 then this gives you an output of 3 +6X^1 +40X^9, which if I remember my maths is what it should be :)
There are loads of things you could do to make the input and output more elegant, and I may have made the odd mistake, but I think is what they're looking for, so you can probably correct it if need be. I missed out the include bits that would make this a whole program but I did test and save what I'd done so if you need the whole thing or help with comments or whatever then give me a shout.
It would have helped had I been able to go to more than 2 tutorials, I dont know the first thing about programming, Im getting the feeling this is gonna be a big FAIL for me.
Guessing your lecture notes and tutorials will give an idea of the way they are wanting it done, just take each step in turn and get them working on their own before getting it all working together.
You got any code you have done yet?
C++ isn't my strongest area but I don't mind trying to give you a hand.
> Mines due on Friday and I havent even started it yet.
Gah! My brother has been hard working at it all holiday and is still not finished, or so he says.