// Name:  McCabe, Micheal H.
// Date:  March 18, 2009
// Project:   Simple_Calculator_V5
// Filename:  arithmetic.cpp

// File Edit History:
//
// File created as a subset of main on 03/11/2009.  When monolithic program
// was "split" on 03/18, code was moved to its own file -- arithmetic.cpp.

#include "calc_headers.h"

float adder(float V1, float V2)
{
      float sum;
      sum=V1+V2;
      return sum;
}

float subtractor(float V1, float V2)
{
      float difference;
      difference=V1-V2;
      return difference;
}

float multiplier(float V1, float V2)
{
      float product;
      product=V1*V2;
      return product;
}

float divider(float V1, float V2)
{
      float quotient;
      quotient=V1/V2;
      return quotient;
}

float exponentiator(float V1, float V2)
{
      float power;
      power=pow(V1,V2); // where V1 is the base and V2 is the exponent
      return power;
}
    
int factorial(int num)
{
    // Here's where my lack of mathematical ability is coming back to bite me!
    // I don't want to try recursion, so we'll do this by iteration...
    int result=1;
    for (int i=1; i<=num; ++i)
        result=result*=i;
    return result;
}

float sum(float data[])
{
      float total=0;
      int i;
      for (i=3; i<(3+data[0]); i++)
          total=total+data[i];
      return total;
}

float mean(float data[])
{
      float mean=0;
      mean=sum(data)/data[0];
      return mean;
}

float list_product(float data[])
{
      float big_product=1;
      int i;
      for (i=3; i<(3+data[0]); i++)
          big_product=big_product*data[i];
      return big_product;
}

float standard_deviation (float data[])
{
      float list_mean;
      float td=0;
      float sd=0;
      int i=0;
      // My understanding of statistics is a little rusty, so bear with me!
      // First we gotta find the mean...
      list_mean=mean(data);
      // Now we gotta find the difference from the mean for each element,
      // square the difference, and total the squared differences.
      for (i=3; i<=data[0]+2; i++)
           td=td+pow(fabs(data[i]-list_mean),2);
      // divide that by the number of elements in the list and take the square
      // root -- then we're done!
      sd=sqrt(td/data[0]);
      return sd;
}


      
      
      
