Directions
Classify the time efficiency of this program by placing the order of magnitude, in Big-O notation, of each statement in the blank next to the statement. Then place the order of each function to the side and state the program's time efficiency. ________
// statpkg.cpp #include <iostream.h> //cin and cout #include <iomanip.h> //format output #include <math.h> //sqrt( ) #include "apvector.h" //array object //function prototypes void readArray(apvector<double> &list); double mean(const apvector<double> &list); double stDev(const apvector<double> &list); void print(const apvector<double> &list); const int MAX = 10000; //_____
int main( ) //_____ main( ) _____
{
cout << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(2);
apvector<double> list(MAX); //_____
readArray(list); //_____
cout << "Mean = " << mean(list) << endl; //_____
cout << "Standard deviation = "
<< stDev(list) << endl; //_____
print(list); //_____
return(0); //_____
}
void readArray(apvector<double> &list) //_____ readArray( ) _____
{
int n = 0; //_____
double height = 0; //_____
cout << "Enter heights (<ctrl>Z to stop)"; //_____
while(cin>>height) //_____ //_____
{
if ( n>= list.length( ) )
list.resize( 2*list.length( ) ); //_____
list[n] = height; //_____ //_____
n++; //_____
}
list.resize(n); //_____
}
void print(const apvector<double> &list) //_____ print( ) _____
{
int N = list.length(); //_____
for(int i=0; i<N; i++) //_____ //_____
cout << '[' << i << ']'
<< setw(6) << list[i]
<< setw(6)
<< list[i] - mean(list)/stDev(list)
<< endl; //_____
}
double mean(const apvector<double> &list) //_____ mean( ) _____
{
double sum = 0; //_____
int N = list.length( ); //_____
for(int i=0; i<N; i++) //_____ //_____
sum += list[i]; //_____
return (double(sum)/N); //_____
}
double stDev(const apvector<double> &list) //_____ stDev( ) _____
{
double diff, sum = 0; //_____
int N = list.length(); //_____
for(int i=0; i<N; i++) //_____ //_____
{
diff = list[i]-mean(list); //_____ //_____
sum = sum + diff*diff; //_____
}
return sqrt(sum/(N-1)); //_____
}