PDA

View Full Version : Advanced class program


Jasoni22
03-31-2002, 01:08 PM
OK, I've almost finished the program for the Advanced WebDev class. However, I've got one problem with it. It finds all the fractions and properly reduces them, put I'm having trouble putting them in ascending order. Right now, if you entered 6, you'd get:

1/6 1/3 1/2 2/3 5/6 1/5 2/5 3/5 4/5 1/4 1/2 3/4 1/3 2/3 1/2

I've gotten it to compare two consecutive fractions using ad<bc but when that returns false, I don't know how to keep that fraction for later use. So using this flawed subroutine, I get, with 5:
(strikethrough=not printed, just there to show what happens)
1/5 2/5 3/5 <s>4/5</s> 1/4 1/2 <s>3/4</s> 1/3 <s>2/3</s> 1/2

Or, it basically prints all the fractions except for (x-1)/x which is obviously not less than the next fraction of 1/(x+1)

http://campcaen.engin.umich.edu/iB_html/non-cgi/emoticons/mad.gif

I hope my explanations were clear and not confusing (I doubt it, though). I'm writing the program in C++. If anyone out here knows how to do this or can give me some hints, I'd greatly appreciate it. All my contact info should be filled in.

Thanks,
Jason

*note*
When you CHECK LENGTH on your Edit Profile screen, it tells you the maximumm length. I always thought it had only one m at the end. http://campcaen.engin.umich.edu/iB_html/non-cgi/emoticons/wink.gif

Stanley
03-31-2002, 07:53 PM
Jason,
What you have to do is find some way to keep the order of the fractions. One thing you could try is a link list and insert them. Right now, that seems like the best way to do it. Although there are other ways.

Stan

EvilPlushToy
04-11-2002, 10:21 PM
Sounds pretty complicated. Mine was a lot simpler and got the job done. Try this: Calculate fractions by doing a two for loops. Reduce. Delete duplicates. Bubble sort or something...

GPeszek
04-12-2002, 03:41 AM
Its almost been two weeks since you posted, I hope you've got everything figured out...classes are filling up fast http://campcaen.engin.umich.edu/iB_html/non-cgi/emoticons/smile.gif

In case you haven't, a linked list (like Stan mentioned) would most certainly work, but in this case I think it'd be overkill. Â*It sounds like you're trying to loop through and sort them. Â*Try this: when your ad&lt;bc returns false, just switch the two fractions and go back one. Â*So if your list is:

1/6 1/3 1/2 2/3 5/6 1/5 2/5 3/5 4/5 1/4 1/2 3/4 1/3 2/3 1/2

Your program will find that 1/5 is the first one that is less than its previous one, so it switches 1/5 with 5/6:

1/6 1/3 1/2 2/3 1/5 5/6 2/5 3/5 4/5 1/4 1/2 3/4 1/3 2/3 1/2

Now it goes back a position and checks 2/3 against 1/5, find s that 1/5 is smaller and switches those:

1/6 1/3 1/2 1/5 2/3 5/6 2/5 3/5 4/5 1/4 1/2 3/4 1/3 2/3 1/2

Just have it keep going until it finds where 1/5 should be, then continue on your merry way.

Hope that helps,
Greg

Stanley
04-12-2002, 04:29 PM
yeah, what greg says about Link Lists is pretty true (although I program mainly in c and it seems like most solutions to me are easier done with link lists [or binary trees]). You can also just put everything into an array reduced and then run sort() (i think that's the function in c++ i know there is a qsort function in either c or c++ that would also work. Just a few suggestions.

simonsj
04-16-2002, 12:31 PM
for those with a sick sense of humor... try red-black trees! for those sane or not taking college level classes... don't!

simonsj
04-16-2002, 12:33 PM
another note: for the advanced class program, it would help those checking over it if you made it command line based. Also, you only need to submit the source code, so try not to use any specific stuff that cannot be reproduced with common compiliers such as MSVC, G++, JCC, etc. Thank you.

05-15-2002, 02:31 AM
I wrote mine in php... http://campcaen.engin.umich.edu/iB_html/non-cgi/emoticons/smile.gif

It's purdyyyyy I was wondering if we had to write the program for the Developing Web Applications class?

-Justin

Stanley
05-15-2002, 03:01 AM
you have to write the program to get into any advanced class. and as long as we can get it to work, you should be fine.