|
-
April 8th, 2010, 10:35 PM
#1
Help!
I need to write a program to calculate the mean and standard deviation of a set of data. Need to use functions ReadData, PrintData,CalcMean,CalcStanDev.....I have no idea what I'm doing. I'm barely beginning to grasp loops. CodeGuru's been good to me in the past, please help me out?
-
April 8th, 2010, 10:37 PM
#2
Re: Help!
Write ReadData and PrintData first. After that, it's just equations.
-
April 8th, 2010, 10:42 PM
#3
Re: Help!
The equations are whats killing me, I never learned standard deviation
-
April 8th, 2010, 10:47 PM
#4
Re: Help!
Well, standard deviation is just the square root of the variance, and the variance isn't any more difficult to compute than the mean:
http://en.wikipedia.org/wiki/Computa...r_the_variance
-
April 8th, 2010, 10:52 PM
#5
Re: Help!
aye, im looking at the equation now. I have no idea what it means, maybe my brother can get through to me
-
April 8th, 2010, 10:54 PM
#6
Re: Help!
This might be a more useful link:
http://en.wikipedia.org/wiki/Algorit...ating_variance
While all the caveats and alternatives are interesting, for your purposes the naive algorithm should be good enough. Note the relationship to the equation at the top of the previous link.
-
April 8th, 2010, 10:58 PM
#7
Re: Help!
Thanks I'm gonna run with this for a little and see where I can, I'll probably be back to check my coding
-
April 9th, 2010, 01:13 AM
#8
Re: Help!
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
ReadData
PrintData
int calc (float a, float b, float c, float d, float e, float sum, float mean,float sd);
float a, b, c, d, e, mean=0.0, avg=0.0;
float sd=0.0;
calc (a, b, c, d, e, &sum,&avg, &sd);
print("Mean=", mean);
print("Standard Deviation=", sd);
getchar();
return 0;
}
calc (float a, float b, float c, float d, float e, float sum float mean, float sd)
{
float Calc=0.0;
*sum = a+b+c+d+e;
*avg = *sum / 5.0;
Calc += ( a - avg) * ( a - avg);
Calc += ( b - avg) * ( b - avg);
Calc += ( c - avg) * ( c - avg);
Calc += ( d - avg) * ( d - avg);
Calc += ( e - avg) * ( e - avg);
sd = sqrt((double)Calc/5.0);
}
system("PAUSE");
return EXIT_SUCCESS;
}
Last edited by Kogo; April 9th, 2010 at 01:21 AM.
-
April 9th, 2010, 01:22 AM
#9
Re: Help!
this is what I got but it isn't compiling
-
April 9th, 2010, 02:14 AM
#10
Re: Help!
Code:
int calc (float a, float b, float c, float d, float e, float sum, float mean,float sd);
This is inside your main function, it should be outside.
What is this doing there ?
Code:
system("PAUSE");
return EXIT_SUCCESS;
this code belongs in your main , not outside it..
sum is not a pointer.
Also, for posting code use code tags
Last edited by Skizmo; April 9th, 2010 at 02:17 AM.
-
April 9th, 2010, 03:10 AM
#11
Re: Help!
Thank you, as dumb as I feel thats the kind of help I need. I never should have taken Honors Computer Programming as a freshman but my teacher has been horribly nice to me considering and I'm just trying to make it through at least one of these 2 assignments that are due. Thanks. This is what I've got, still working though but any more advice in the mean time is greatly appreciated.
Code:
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
int calc (float a, float b, float c, float d, float e, float sum, float mean,float sd);
int main(int argc, char *argv[])
{
float a, b, c, d, e, mean=0.0, avg=0.0;
float sd=0.0;
CalcMean ((a+b+c+d+e)/5) ;
print("Mean=", mean);
print("Standard Deviation=", sd);
getchar();
return 0;
}
calc (float a, float b, float c, float d, float e, float sum float mean, float sd)
{
float Calc=0.0;
*sum = a+b+c+d+e;
*avg = *sum / 5.0;
Calc += ( a - avg) * ( a - avg);
Calc += ( b - avg) * ( b - avg);
Calc += ( c - avg) * ( c - avg);
Calc += ( d - avg) * ( d - avg);
Calc += ( e - avg) * ( e - avg);
sd = sqrt((double)Calc/5.0);
system("PAUSE");
return EXIT_SUCCESS;
}
-
April 9th, 2010, 03:19 AM
#12
Re: Help!
Idk if this code is salvageable. I have put together working programs before,its just been a while and I missed some chapters that obviously would have been helpful. I tried taking a shortcut on this one since I procrastinated for so long, hopefully I'll get it worked out, thanks anyway.
-
April 9th, 2010, 09:03 AM
#13
Re: Help!
Well, you were told to use functions called CalcMean and CalcStanDev rather than a single calc() function, so that's one change you can make immediately.
The first thing you need to figure out is how you're going to handle the data set. Right now, you have 5 float variables, which means you can't handle more than 5 values. Are you guaranteed you'll only get 5 values, or are you supposed to handle an arbitrary number? Will input be terminated after a specific count, or after a delimiting number is observed? Are you going to store all the inputs in memory, or process them "on the fly" with no storage? These are important details to worry about before you ever concern yourself with the equations.
Last edited by Lindley; April 9th, 2010 at 09:07 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|