Become a part of the TranceAddict community!Frequently Asked Questions - Please read this if you haven'tSearch the forums
TranceAddict Forums > Main Forums > Chill Out Room > C++ Hw
Pages (2): [1] 2 »   Last Thread   Next Thread
Share
Author
Thread    Post A Reply
Trancealot
Supreme tranceaddict



Registered: Mar 2001
Location: Binghamton,ny--Roxy NYC!
C++ Hw

anyone of you a coder out there can help me..

I am good but this one is boggoling my mind???

Write a program that uses Newton's method to compute the nth root of a number x. Newton's method requires an initial "seed"- a guess at the answer to start the iterative algorithm. The user is asked to supply an initial guess at the solution. If the user enters -1 as the initial guess, the program is to provide an initial solution. The user should be repeatedly prompted to enter a positive integer n greater than or equal to 2 and a positive double value x. The user should also be asked to enter the desired accuracy of the solution as the number of decimal places that the solution is accurate to (between 0 and 15). The program should print a table showing the iteration number, current estimate of the solution, and the error (the absolute value of the difference between the last estimate and the current estimate). The table values should be left aligned in columns and the solution estimate and error should be printed in fixed-point notation using to the number of decimal places specified by the user. Make sure that your program checks for division by zero and exits gracefully.

This program computes the nth root of x using Newton's Method.
Input n: 3
Input x: 1001
Input an initial guess at the root, or -1 if unsure: -1
How many decimal places (0-15) should the solution be computed to: 7
Iteration Root Error
1 222.4474414 111.2192252
2 148.3050374 74.1424041
3 98.8851955 49.4198419
4 65.9575869 32.9276086
5 44.0484225 21.9091644
6 29.5375847 14.5108377
7 20.0741628 9.4634220
8 14.2107897 5.8633731
9 11.1261122 3.0846775
10 10.1128251 1.0132871
11 10.0045134 0.1083116
12 10.0033324 0.0011811
13 10.0033322 0.0000001
14 10.0033322 0.0000000


___________________
ATB -Let u go
Iio - Rapture(riva edit)
Dj Encore - I see right through you
Lasgo - something

The best vocal tunes on LI RIP(2001-2002)

Old Post Oct-06-2002 04:49  United States
Click Here to See the Profile for Trancealot Click here to Send Trancealot a Private Message Add Trancealot to your buddy list Report this Post Reply w/Quote Edit/Delete Message
drizzt81
Professional Lamer



Registered: Nov 2001
Location: GTA #1 - At work

so what exactly do u want? a completely written program or what?


___________________

get font

I see your 4 Crushs and raise you 3 As The Rush Comes. - Yan from PvD's first summerstage event in '03

Old Post Oct-06-2002 10:33  Germany
Click Here to See the Profile for drizzt81 Click here to Send drizzt81 a Private Message Add drizzt81 to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Trancealot
Supreme tranceaddict



Registered: Mar 2001
Location: Binghamton,ny--Roxy NYC!

I supposed so...


___________________
ATB -Let u go
Iio - Rapture(riva edit)
Dj Encore - I see right through you
Lasgo - something

The best vocal tunes on LI RIP(2001-2002)

Old Post Oct-06-2002 14:49  United States
Click Here to See the Profile for Trancealot Click here to Send Trancealot a Private Message Add Trancealot to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Mail Man
Pimp Daddy!!!



Registered: Jan 2002
Location: Glasgow

quote:
Originally posted by Trancealot
I supposed so...


u lazy bum lol

im starting C++ in December.. is it hard?

Old Post Oct-06-2002 14:55  Scotland
Click Here to See the Profile for Mail Man Click here to Send Mail Man a Private Message Add Mail Man to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Trancealot
Supreme tranceaddict



Registered: Mar 2001
Location: Binghamton,ny--Roxy NYC!

well look at this problem..the last program I messed up so its getting harder


___________________
ATB -Let u go
Iio - Rapture(riva edit)
Dj Encore - I see right through you
Lasgo - something

The best vocal tunes on LI RIP(2001-2002)

Old Post Oct-06-2002 15:10  United States
Click Here to See the Profile for Trancealot Click here to Send Trancealot a Private Message Add Trancealot to your buddy list Report this Post Reply w/Quote Edit/Delete Message
drizzt81
Professional Lamer



Registered: Nov 2001
Location: GTA #1 - At work

quote:
Originally posted by Trancealot
I supposed so...


well, while this sounds liks a cool problem, i don't have the time to write a proggy that does this stuff right now. Let me give you some pointers (har har, get the pun!!):

start out simple. Write the functions, which are going to handle your I/O first. See that you get the information correctly from the user.

Next see if you have write a function, let's call it

code:
int displayLine(int iTry, int iRoot, int iError)

which takes three ints and returns 0 if it executed sucessful. this function, uses the three integers provided to create one line of the array, which u are supposed to print.

If you are not getting many point for how teh array looks, u might just want to do a cout on this stuff and dump it to the screen before worrying about formatting.

one good thing is that there is a cout command, which let's u set the number of decimal places, which are displayed.

After you got your I/O sorted, it is time to crank out some Math book and figure out how the newton method is done. I don't know this off-hand (I remeber newton-raphson method for finding the zero's of functions).

From the problem statement, i assume that it will be an interative algorithm. You can then write a function
code:
int Newton(int iSeed, int& iRoot, int& iError)

which will do one iteration of your algorithm and put the new root into iRoot, the new error into iError and returns 0 if it is successful.

Now you should have everything u need to write a little main loop, which uses these function stubs to ask for input, compute the rows, till the error == 0 and prints out one row at a time.

I hope that this helps a bit


___________________

get font

I see your 4 Crushs and raise you 3 As The Rush Comes. - Yan from PvD's first summerstage event in '03

Old Post Oct-06-2002 15:32  Germany
Click Here to See the Profile for drizzt81 Click here to Send drizzt81 a Private Message Add drizzt81 to your buddy list Report this Post Reply w/Quote Edit/Delete Message
drizzt81
Professional Lamer



Registered: Nov 2001
Location: GTA #1 - At work

quote:
Originally posted by Mail Man


u lazy bum lol

im starting C++ in December.. is it hard?


not at all. once u know where to go to find functions that are in the libraries, you are golden.


___________________

get font

I see your 4 Crushs and raise you 3 As The Rush Comes. - Yan from PvD's first summerstage event in '03

Old Post Oct-06-2002 15:43  Germany
Click Here to See the Profile for drizzt81 Click here to Send drizzt81 a Private Message Add drizzt81 to your buddy list Report this Post Reply w/Quote Edit/Delete Message
whiskers
old skool



Registered: Sep 2001
Location: in your dreams

hehe, here's how i programmed it in basic for my TI-83+ calculator:

:ClrHome
isp "ENTER EQUATION"
isp "IN QUOTES"
:Prompts Str0
:Str0->Y1
:d(Str0, "X")->Y2 //takes a derivative of Y1 and puts it into Y2
:Lbl 0
:ClrHome
isp "ENTER A GUESS"
:Prompt G
:While (Y1(G)>0.000000001)
:G-(Y1(G)/Y2(G))->G //Newton's formula
isp G
:End
isp "ANSWER IS:", G
:Pause
:Menu("CHOOSE ACTION", "CHANGE GUESS", 0, "QUIT", 9)
:Lbl 9
:""->Y1
:""->Y2


works like a charm
hehe


___________________

Old Post Oct-06-2002 20:26  Ukraine
Click Here to See the Profile for whiskers Click here to Send whiskers a Private Message Add whiskers to your buddy list Report this Post Reply w/Quote Edit/Delete Message
ampburner
progressive trancEaddict



Registered: Oct 2000
Location: Holland

I like how

code:
:Disp
shows up as
quote:
isp



___________________
...We had that lightswitch installed so you could turn the lights on - and off. NOT SO YOU COULD HAVE LIGHTSWITCH RAVES! now let's go break open that glowstick and poor it into homestarrunner's mountain dew! I heared they have to pump your stomach when you drink that stuff...

Old Post Oct-06-2002 21:55  Netherlands
Click Here to See the Profile for ampburner Click here to Send ampburner a Private Message Add ampburner to your buddy list Report this Post Reply w/Quote Edit/Delete Message
whiskers
old skool



Registered: Sep 2001
Location: in your dreams

quote:
Originally posted by ampburner
I like how
code:
isp
shows up as



lol HEHE

someone once said Perl is cool because it uses more emoticons than all other languages combined... i wonder how that would look on here


___________________

Old Post Oct-06-2002 23:39  Ukraine
Click Here to See the Profile for whiskers Click here to Send whiskers a Private Message Add whiskers to your buddy list Report this Post Reply w/Quote Edit/Delete Message
AnotherWay83
The B00b Maintenance Guy™



Registered: Aug 2000
Location: land of d(-_-)b

quote:
Originally posted by TiestoInTheMix


lol HEHE

someone once said Perl is cool because it uses more emoticons than all other languages combined... i wonder how that would look on here


Perl...heh, gotta love that language

it's so fuckin high level, i've actually seen entire poems written in it, and they actually get parsed perfectly fine

i will post 1 if u want.

Old Post Oct-07-2002 06:44 
Click Here to See the Profile for AnotherWay83 Click here to Send AnotherWay83 a Private Message Add AnotherWay83 to your buddy list Report this Post Reply w/Quote Edit/Delete Message
PatMcGroin
lost



Registered: Sep 2001
Location: here? there?

ATLEAST YOUR NOT DOING C!!!!!!!

fucking a! i took c++ 2 years ago, and now i'm taking c....god so horrible! i fucking miss cin soooo much!

c is all harder with functions too, grrr

look at my last program i had to do:
http://www.cs.fsu.edu/~cgs3408/html/project5.htm

took me about 2 hours, but of course, with some help

Old Post Oct-07-2002 13:57  Germany
Click Here to See the Profile for PatMcGroin Click here to Send PatMcGroin a Private Message Add PatMcGroin to your buddy list Report this Post Reply w/Quote Edit/Delete Message

TranceAddict Forums > Main Forums > Chill Out Room > C++ Hw
Post New Thread    Post A Reply

Pages (2): [1] 2 »  
Last Thread   Next Thread
Click here to listen to the sample!Pause playbackBeautiful trance track played by Airwave in Progrez Episode 31 (25 July 2007) [2008] [1]

Click here to listen to the sample!Pause playbackAirwave - "When Things Go Wrong" [2003]

Show Printable Version | Subscribe to this Thread
Forum Jump:

All times are GMT. The time now is 07:55.

Forum Rules:
You may not post new threads
You may not post replies
You may not edit your posts
HTML code is ON
vB code is ON
[IMG] code is ON
 
Search this Thread:

 
Contact Us - return to tranceaddict

Powered by: Trance Music & vBulletin Forums
Copyright ©2000-2026, Jelsoft Enterprises Ltd.
Privacy Statement / DMCA
Support TA!