GetDotted Domains

Viewing Thread:
"Good at C++ ? In here please!"

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.

Sat 24/04/04 at 12:01
Regular
"Sure.Fine.Whatever."
Posts: 9,629
Anyone here good at C++ ?

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!
Sat 24/04/04 at 17:59
Regular
Posts: 2,849
Tsk, let's just hope the uni doesn't scan this as part of the plaigiarism detector software, they can be quite tough on that.
Sat 24/04/04 at 17:40
Regular
"Sure.Fine.Whatever."
Posts: 9,629
Thanks kernel. That really is a great help! Cheers, much appreciated!
Sat 24/04/04 at 16:59
Regular
"relocated"
Posts: 2,833
Icaruss wrote:
> 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.
Sat 24/04/04 at 16:55
Regular
"relocated"
Posts: 2,833
I had a look and you don't need to be able to do the maths to do the question. Basically, if you have an expression of the form a*x^b (when ^ means 'to the power of') then its derivative is (ab)*x^(b-1). So the derivative of 3x^2 is just 6x.

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.
Sat 24/04/04 at 13:56
Regular
"Picking a winner!"
Posts: 8,502
The site you gave a link too has all your notes and tutorials and the solutions to the tutorials, these look as if they could have similar problems in them that you just need to piece together and change a bit to solve this assignment.
Sat 24/04/04 at 13:40
Regular
"Sure.Fine.Whatever."
Posts: 9,629
I couldn't even do the maths by hand, no chance of making it into a working programme!

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.
Sat 24/04/04 at 12:59
Regular
Posts: 2,849
The method I find which works is to solve the problem as you'd normally do by hand; then divide into smaller and more specific steps, convert it into pseudocode and then finally into C++. You should find you only have to make minor adjustments afterwards for it to work, especially if it's a (relatively) simples maths problem.
Sat 24/04/04 at 12:56
Regular
Posts: 2,849
We're doing something very similar for out first year team project, but in Java. However, I'm not going to just blurt out the code so you can easily convert it, because that defeats the point of learning.
Sat 24/04/04 at 12:47
Regular
"Picking a winner!"
Posts: 8,502
Sounds like fun... :-P

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.
Sat 24/04/04 at 12:41
Regular
"bei-jing-jing-jing"
Posts: 7,403
Lindgren wrote:
> 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.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Thank you very much for your help!
Top service for free - excellent - thank you very much for your help.
My website looks tremendous!
Fantastic site, easy to follow, simple guides... impressed with whole package. My website looks tremendous. You don't need to be a rocket scientist to set this up, Freeola helps you step-by-step.
Susan

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.