Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 27th, 2005, 7:52 PM   #11
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Ahhhhhhh, well, don't depend on me, then. Good luck.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 27th, 2005, 10:41 PM   #12
Java|Tera
Newbie
 
Join Date: Nov 2005
Posts: 14
Rep Power: 0 Java|Tera is on a distinguished road
14 hours to go...I'm pulling an all-nighter, can someone please help?
Java|Tera is offline   Reply With Quote
Old Nov 27th, 2005, 10:58 PM   #13
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
The mode is just the one that pops up the most. Sort the data, and then loop through and find out which one(s) occur most often.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 27th, 2005, 11:17 PM   #14
Java|Tera
Newbie
 
Join Date: Nov 2005
Posts: 14
Rep Power: 0 Java|Tera is on a distinguished road
Do I need a multi-dimensional array to do that? Or can I just use a regular array?

And how do I loop through it and find the stuff?
Java|Tera is offline   Reply With Quote
Old Nov 27th, 2005, 11:35 PM   #15
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
You could easily do that with a single dimension array.

Loop through it with a for loop -- then use a sorting algorithm to sort out the numbers from greatest to least, or however you plan on going about finding the mode.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Nov 27th, 2005, 11:38 PM   #16
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 5 groovicus is on a distinguished road
MODE:
To find the mode, all you need is a simple array (filled with zeroes) that is the same size as the largest possible random number that can be generated . Then you loop through your array of 1000 randomly generated numbers. If the first number is a one, then you put the number one in index one in your counting array. If your second number is a one, then you increment the count at one again, so then you have two. Whatever the random number is, increment the count in your array by one. Once you are done, then go through your counting array, see which cell has the largest number, and that is your mode.

So, assume your aray of random numbers is called rand, and your counting array is called count:

get rand[i] //get random number
count[rand]++; // increment count in cell rand


Now loop to check for biggest:

int most = 0;
if rand[i]> most
then most = rand[1]

Once you are done, most will hold the index of the most frequently generated number.


MEDIAN:
Sort your array using the built in sort, then divide by two to get the index of the median.

SHOW ALL NUMBERS:
I'm not sure why you would have a problem with that, If you know how to loop through your array, then that should be pretty simple.
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Old Nov 27th, 2005, 11:58 PM   #17
Java|Tera
Newbie
 
Join Date: Nov 2005
Posts: 14
Rep Power: 0 Java|Tera is on a distinguished road
I don't know what's wrong with showing all the numbers..

When I print them in the same method as they are generated in (main method) it works fine, but when I pass them to the menu method and print them, they print all of the same number...

As for median, what if the length is odd?

And for mode, do I need 2 arrays then?
Java|Tera is offline   Reply With Quote
Old Nov 28th, 2005, 8:23 AM   #18
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 5 groovicus is on a distinguished road
Not that it probably matters now..

Quote:
When I print them in the same method as they are generated in (main method) it works fine, but when I pass them to the menu method and print them, they print all of the same number...
You need to re-examine your code. Apparently your array is not being passed properly.

Quote:
As for median, what if the length is odd?
As long as it is sorted, you will get at least almost the middle. When the array is odd length, you won't ever get the exact median, because the median will always be between two numbers.. If you divide by two for your index, then it will work for both cases (even and odd lengthed arrays)

Quote:
And for mode, do I need 2 arrays then?
That's how I would do it, but I don't think you understand the concept, so you might want to try something else. Unfortunately, I can't think of any other good way to do it.
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Old Nov 28th, 2005, 8:39 AM   #19
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I suspect you're right -- it probably doesn't matter now. I must confess that I presume (possibly erroneously, probably not) that a 16-hour deadline was the result of procrastination. There is perhaps something to be learned by that, for the future.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 28th, 2005, 10:09 AM   #20
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 5 groovicus is on a distinguished road
Quote:
I must confess that I presume (possibly erroneously, probably not) that a 16-hour deadline was the result of procrastination.


When was the last time you heard someone ask for urgent help for an assignment that was due in one week?
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:28 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC