C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 7th, 2005, 02:41 PM
LinuxPoser LinuxPoser is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 3 LinuxPoser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 52 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old June 7th, 2005, 05:10 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
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.



Reply With Quote
  #3  
Old June 7th, 2005, 05:31 PM
LinuxPoser LinuxPoser is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 3 LinuxPoser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 52 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old June 8th, 2005, 10:11 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 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.

Reply With Quote
  #5  
Old June 8th, 2005, 03:49 PM
LinuxPoser LinuxPoser is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 3 LinuxPoser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 52 sec
Reputation Power: 0
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

Reply With Quote
  #6  
Old June 9th, 2005, 04:21 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
that median algorithm won't work when there are any even number of numbers...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > question for mean median mode


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT