Question
Summary: compute population standard deviation. Given a set of values representing a complete population, the population standard deviation is found by taking the square root
Summary: compute population standard deviation.
Given a set of values representing a complete population, the population standard deviation is found by taking the square root of the average of the squared deviations of the values from their average value. Huh? In other words, given a sequence of real numbers, you do the following:
compute the average
for each real number R, compute (R - avg)^2 --- call these our temp values
compute the variance --- the average of the temp values
compute the square root of the variance --- this is the population standard deviation
For a concrete example, see the following Wikipedia page.
The goal is to develop a complete C++ program to input a complete population of real numbers, compute the population standard deviation, and output this value. For simplicity of testing, the input comes from the keyboard (cin), and ends with a -1. Assume at most 1,000 numbers. For example, if the program is given the following input sequence:
2.0 4.0 4.0 4.0 5.0 5.0 7.0 9.0 -1
then the population standard deviation is
2
The main() function, which inputs the values and stores them into an array, is written for you. Your assignment is to write the StandardDev()function, which is called by main() to compute the population standard deviation.
BEFORE YOU START
We need to avoid a bug in some browsers. Above the editor pane you'll see the text "Current file: main.cpp", with a little drop-down arrow to the right. Click the drop-down and select "functions.cpp". Then click the link "Load default template..." --- this will ensure the file is properly loaded for you to edit; you only need to do this once.
FUNCTION TO IMPLEMENT
Here's the function you have to write:
// // StandardDev() // // Given an array A containing N real numbers, computes and returns // the population standard deviation. The function should not change // the contents of the array. // double StandardDev(double A[], int N) { double result = -1.0; // // NOTE: you don't want to change the contents of array A. So if you // need to store some local, intermediate results, create an additional // local array like this: // // double temp[1000]; // at most 1,000 reals: // // // TODO: // return result; }
The function should implement the 4 steps outlined early, in that order. Note that you'll need to compute N temp values; declare a local array of size 1000 in which to store these temp values (do not change the contents of A).
PROGRAMMING INSTRUCTIONS
Recall that zyante has 2 modes, Develop mode and Submit mode. In Develop mode you must supply the program input. For this assignment, supply 1 or more real numbers to test against (ending with -1), e.g.
2.0 4.0 4.0 4.0 5.0 5.0 7.0 9.0 -11 functions.cpp/ 3 #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started