| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
question for mean median mode
well im currently working on a program in school and ive run into a little bit of a road block. The project has us importing data from a text file and outputting the wanted information into another text file.
we are given data sets and we must find the mean median and mode of each data set. I got the mean up and running but the mode and median are giving me some trouble. I was curious if any of you would give me a working section of code. once i see it ill be able to analyze it and understand how it works. Thank you Things that might be important Coding in Code Warrior |
|
#2
|
||||
|
||||
|
We could write the code for you, or you could present your buggy code to use and let us point you in the right direction
There are only two places you could be making errors, in your algorithm logic, or your implementation of it in the C/++ language. If you post your code, we should be able to identify your problems.
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
|
#3
|
|||
|
|||
|
i had a general idea on how to do the median and mode but there extensive loops and im not sure how you would compare the amount of each occurance for each number to each one, then display the one with the most common occurance. I was thinking it would be a loop in which all numbers are compared to one another and when one matches another then it put an amount into a variable, at the end compare and find which variable is greatest and then trace it back and you have your mode. Its just really complicated and our teacher never told us how to do it. If someone could write it for me i would be able to see how it was done and analyze it. I will try to get my code in asap so you can look it over and give me a hand, Thanks
|
|
#4
|
|||
|
|||
|
As far as calculating 'median' is concerened, you need to arrange the data set in some order.Then depending on the number of items in dataset, you have to find the mid value, that falls exactly in the middle for no. items as odd or mean of 2 middle values for number of items as even.
For 'mode' , if the items are regular and have some pattern, you can apply formula mode = 3median - 2 mean. But data set where items are arbritrary, you need to use loops. Where on traversing the list, you create unique variable for each distinguishing element and while traversing, look for the occurance of same elements. This is similar to a sorting algorithm called "Bucket Sort". Where each bucket represents unique element and similar occurances fall in bucket.Then for each unique bucket , count the number of elemetns. This approach however has a drawback if your dataset is big.Then for example, for 50 elements you need to generate 50 buckets (worst case) or 1 (best case). Another way to compute mean is using a formula that uses standard Deviation. For this I suggest you to refer to statistics. HTH. |
|
#5
|
|||
|
|||
|
well i figured out median and it wasnt too difficult but mode is going to be the most difficult, for median i just had it run a loop where i = 0 and x = 16 and once they are i == x then it takes that number. I'll try to post the code when i go in tomorrow morning, its a zip and my pc doesnt have zip
|
|
#6
|
|||
|
|||
|
that median algorithm won't work when there are any even number of numbers...
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > question for mean median mode |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|