Question
Some Statistics This assignment should utilize the vector container of the STL. All functions should use either iterators or the range-based for when accessing or
Some Statistics
This assignment should utilize the vector container of the STL. All functions should use either iterators or the range-based for when accessing or traversing vectors.
Create a new plain text document, vectorTestData.txt, containing several integers, one number per line. Example data follows. |
10 12 23 18 10 15 13 25 19 16
Create a new program, spVectorHWstatistics.cpp. Include definitions for the following function prototypes you may also create additional "helper" functions if you wish, but you are required to include the functions described below: |
double calcMean (const vector
The mean or average of a group of N numbers x1, x2, ... xn is the sum of the numbers divided by how many there are; it is represented by x(bar).
mean = x(bar) = 1/N sum(i=1 to N) xi
double calcStandardDeviation (const vector
The standard deviation of the same group of N numbers is given by the following formula.
standardDeviation = sqrt(1/N-1) sum(i=1 to N) (xi - x(bar))2
Note that function standardDeviation should in turn call function mean in order to implement its formula above.
void displayValues(const vector
Display the contents of the vector to the screen 16 numbers per line with all numbers shown in columns of width 5.
int findMaximum(const vector
Find Maximum Number in an Vector
establish a variable max to hold the value of the first element of the vector setup a loop to traverse the vector - the body of the loop should contain code to do the following determine if max is smaller than the vector value at the current location in the vector reset max to the new largest value return max to the calling function
int findMinimum(const vector
Similar to the findMaximum function except it finds the smallest value in the vector.
int findSecondMaximum(const vector
Similar to the findMaximum function except it finds the second largest value in the vector.
int findSecondMinimum(const vector
Similar to the findMinimum function except it finds the second smallest value in the vector.
void writeData(string, const vector
The data contained in the vector is stored in the filename specified in the string. If a file with that filename already exists, it should be overwritten. The data should be stored in the file one number per line.
vector
Data contained in the file indicated by the filename specified in the string should be read into a vector. The function should return this vector to the calling function.
bool findMostExtremeOutlier(const vector
In statistics, an outlier is an observation point that is distant from other observations. An outlier may be due to variability in the measurement or it may indicate experimental error; the latter are sometimes excluded from the data set. (from Wikipedia.org)
The function determines the most extreme outlier, if one exists. If an outlier is found, the function should store the value of the most extreme outlier in the supplied reference parameter and return true to the calling function. If an outlier is not found, the function should simply return false to the calling function.
Use the following to determine if a data value is an outlier:
| x - x(bar) | > 3*sigma
where sigma is the standard deviation.
The most extreme outlier, if any outliers exist, will be the outlier with the most extreme distance from the mean.
vector
The function should create a new vector with the most extreme outlier removed from the data. The function should return the resulting vector to the calling function.
int main()
Arrange function main so that it immediately reads a set of values from the file vectorTestData.txt using the readValues function; it should then present the user repeatedly with the following options:
find maximum
find 2nd maximum
find minimum
find mean
find standard deviation
display most extreme outlier
remove most extreme outlier and recalculate standard deviation
display values
read a new set of values
exit program
When the user chooses to
read a new set of values
s/he should be prompted for the name of the file containing the values to be read
remove most extreme outlier and recalculate standard deviation
the following actions should be taken
call removeMostExtremeOutlier to remove the most extreme outlier
alter the filename by adding sansOutlier- to the beginning of the existing filename (so data.txt would become sansOutlier-data.txt)
write the new data set to a file using the new filename
call calcStandardDeviation to calculate the standard deviation using the new data and display it to the user
Please give answer in C++ language
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