13.12) Exercise 22
Copy your Exercise 18 solution to a new file and edit it. Change this new program so that it uses three separate functions: read_data
, to read from a file stream into a vector; mean
, to compute and return the mean of the values in a vector; and stdev
, to compute and return the standard deviation of the values in a vector.
You will need to move your existing Exercise 18 code into these functions and then modify main
so that it calls them in the correct way. To get you started, here is what read_data
should look like before you move code into it:
void read_data(ifstream& infile, vector<double>& data) { }
Remember to use a const reference to the vector in the mean
and stdev
functions and remember that both functions will need return
statements to communicate the results of computation back to the caller.
Test your program and make sure that it generates the same output as your solution to Exercise 18.