Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 -1 

image text in transcribedimage text in transcribed

1 functions.cpp/ 3 #include 4 #include 5 #include 7 using namespace std; 8 10 11 11 // StandardDev) 12 11 13 /I Given an array A containing N real numbers, computes and returns 14 // the population standard deviation. The function should not change 15 // the contents of the array. 16 11 17 double StandardDev(double A[], int N) 18 19 20 II 21 / NOTE: you don't want to change the contents of array A. So if you 22 / need to store some local, intermediate results, create an additional 23 / local array like this: 24 I1 25 double temp[1000]; I/ at most 1,000 reals: 26 1I 27 28 double result= -1.0; 30 /I TODO: 31 II 32 return result; 34 35 36

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

4.09 Over 25 79

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago