![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#12 |
|
Newbie
Join Date: Nov 2005
Posts: 14
Rep Power: 0
![]() |
14 hours to go...I'm pulling an all-nighter, can someone please help?
|
|
|
|
|
|
#13 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
|
|
#14 |
|
Newbie
Join Date: Nov 2005
Posts: 14
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#15 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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 |
|
|
|
|
|
#16 |
|
Programmer
Join Date: Nov 2004
Posts: 84
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#17 |
|
Newbie
Join Date: Nov 2005
Posts: 14
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#18 | |||
|
Programmer
Join Date: Nov 2004
Posts: 84
Rep Power: 5
![]() |
Not that it probably matters now..
Quote:
Quote:
Quote:
__________________
HijackThis Team-SFDC |
|||
|
|
|
|
|
#19 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#20 | |
|
Programmer
Join Date: Nov 2004
Posts: 84
Rep Power: 5
![]() |
Quote:
![]() When was the last time you heard someone ask for urgent help for an assignment that was due in one week?
__________________
HijackThis Team-SFDC |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|