SOURCE FILE: statsShell.cpp



/*

 The purpose of this program is to work with a file containing (only) 0 or
 more integers, separated by white space.  We assume the integers are suitable
 to be represented using the int data type.

 The name of the input file is the value of the global constant: fileName.

 There is another global constant int called: sizeLimit.

 If the input file cannot be opened, is empty, or contains more than sizeLimit
 integers the output of the program is an error message.

 If the number of integers in the input file is more than zero but not more
 than the value of sizeLimit, then, after copying the numbers into an array,
 the program outputs:
 
    * the contents of the input file,
    * the minimum value found in the input file,
      along with the index of the first array element equal to the minimum,
    * the maximum value found in the input file,
      along with the index of the first array element equal to the maximum,
    * the average (mean) of the numbers in the input file, expressed as a
      double, and
    * the population standard deviation of the numbers in the input file, also
      expressed as a double.

  See the file terminalSession.html for an example illustrating the way that
  the output must be formatted.

 One may check one's values for averages and population standard deviations
 here:

 http://www.mathsisfun.com/data/standard-deviation-calculator.html

*/

#include <iostream>
#include<fstream>
#include<cmath>
#include<iomanip>
using namespace std ;

const int sizeLimit = 100 ;
const char fileName[] = "numbers.txt" ;

void getData (int data[], const char fname[],
                 int arraySize, int & numSlotsUsed);
void showData (int data[], int numSlotsUsed) ;
double average (int data[], int numSlotsUsed ) ;
double stndrdDev (double average, int data[], int numSlotsUsed ) ;
void findMin (int data[], int & minValue, int & minPos, int numSlotsUsed ) ;
void findMax (int data[], int & maxValue, int & maxPos, int numSlotsUsed ) ;
void showResults (int min, int minIndex, int max, int maxIndex,
                    double average, double stdDev) ;

int main (void)
{
   int theData[sizeLimit], dataSize, min, max, minIndex, maxIndex ;
   double theAve, theStdDev ;

   getData(theData, fileName, sizeLimit, dataSize) ;
   showData (theData, dataSize) ;
   findMin (theData, min, minIndex, dataSize) ;
   findMax (theData, max, maxIndex, dataSize) ;
   theAve = average(theData, dataSize) ;
   theStdDev = stndrdDev(theAve, theData, dataSize) ;
   showResults (min, minIndex, max, maxIndex,theAve, theStdDev) ;

   return 0;
}
  /* ******************************************** */
  /*                     GETDATA                  */
  /* ******************************************** */
  /*
       The purpose of function getData is to
           + read from the input file whose name is stored in: fname,
           + copy the values in the file into the array called: data, and
           + set the parameter numSlotsUsed equal to the number of
             items copied into the array.
         
       (Function getData copies the first item in the file, if one
       exists, into data[0], copies the second item into data[1], and
       so on.)

       Function getData handles the following exceptional situations:
           + input file cannot be opened,
           + input file is empty, and
           + input file contains more elements than the value of arraySize.

       In those situations, function getData prints an error message and
       terminates execution of the program (exits). 
  */
void getData (int data[], const char fname[],
                 int arraySize, int & numSlotsUsed)
{
}
  /* ******************************************** */
  /*                    SHOWDATA                  */
  /* ******************************************** */
  /*
       The purpose of function showData is to print some text to the
       screen, followed by the values of array items data[0] through
       data[numSlotUsed-1].  Function showData prints array values in
       a field width of 3.  It prints ten values to a line, except it
       may print fewer values on the last line.  Function showData
       prints the values as a comma-separated list.  In particular,
       function showData prints a comma right after each value, except
       the last one.  It prints a period right after the last value.
       Between every pair of successive items on a line, it prints a
       blank space right after the comma.

       See the file terminalSession.html for examples illustrating the
       remaining rules for formatting the output of function
       showData.
  */
void showData (int data[], int numSlotsUsed)
{
}
  /* ******************************************** */
  /*                     FINDMIN                  */
  /* ******************************************** */
  /*
       The purpose of function findMin is to set parameter minValue
       equal to the minimum of the values in the data array between
       index positions 0 and numSlotsUsed-1 (inclusive), and also to
       set parameter minPos equal to the smallest array index between
       0 and numSlotsUsed-1 such that data[minPos] is equal to the
       minimum value.
  */
void findMin (int data[], int & minValue, int & minPos, int numSlotsUsed ) 
{
}
  /* ******************************************** */
  /*                     FINDMAX                  */
  /* ******************************************** */
  /*
       The purpose of function findMax is to set parameter maxValue
       equal to the maximum of the values in the data array between
       index positions 0 and numSlotsUsed-1 (inclusive), and also to
       set parameter maxPos equal to the smallest array index between
       0 and numSlotsUsed-1 such that data[maxPos] is equal to the
       maximum value.
  */
void findMax (int data[], int & maxValue, int & maxPos, int numSlotsUsed )
{
}
  /* ******************************************** */
  /*                     AVERAGE                  */
  /* ******************************************** */
  /*
       The purpose of function average is return the average of the values
       data[0] through data[numSlotsUsed-1].  The average is the sum of
       data[0] through data[numSlotsUsed-1], divided by numSlotsUsed.
  */
double average (int data[], int numSlotsUsed )
{
}
  /* ******************************************** */
  /*                  STNDRDDEV                   */
  /* ******************************************** */
  /*
       The purpose of function stndrdDev is to return the population
       standard deviation of the values data[0] through
       data[numSlotsUsed-1].  To see how to calculate the population
       standard deviation, consider terms of this form:

       ( data[k] - average ).

       The parameter called average is assumed to be the average of the
       values data[0] through data[numSlotsUsed-1].  If we sum the
       squares of each of the terms shown above, then divide the
       result by numSlotsUsed, and finally take the square root of the
       result, that final value is the population standard deviation.
       See this web page for a formula written out in mathematical
       notation and then explained one small step at a time:

       http://www.mathsisfun.com/data/standard-deviation-formulas.html

       (However of course you must adjust for the fact that N items in
       a C++ array are numbered starting at 0 and ending with N-1,
       whereas in the explanation on the web page the authors assumed
       that there are N items numbered starting with item 1 and ending
       with item N.)
  */
double stndrdDev (double average, int data[], int numSlotsUsed )
{
}
  /* ******************************************** */
  /*                 SHOWRESULTS                  */
  /* ******************************************** */
  /*
       The purpose of function showResults is to print to the screen
       the values of min, minIndex, max, maxIndex, average, and
       stdDev.  These are values calculated, respectively, with
       functions findMin, findMax, average, and stndrdDev.  The double
       quantities average and stdDev are to be printed in fixed-point
       notation, showing the decimal point, and with exactly five
       digits displayed after the decimal point.

       See the file terminalSession.html for examples illustrating the
       remaining rules for formatting the output of function
       showResults.
  */
void showResults (int min, int minIndex, int max, int maxIndex,
                    double average, double stdDev) 
{
}
  /* ******************************************** */
  /*                      END                     */
  /* ******************************************** */