/*
Jui-Chen Ma
PS 7 part 1
*/

#include "ps7a.h"
#include <math.h>
#include <iostream.h>

void Layers::volume(void)
{
  int i=0;
  int j=0;
  double x, y, z;
  double a, b=0;
  double T[3], W[3];

  T[0]=-0.77459667;
  T[1]=0;
  T[2]=0.77459667;

  W[0]=0.55555555;
  W[1]=0.88888889;
  W[2]=W[0];

  for ( ; i<3; i++)
    {
      a=0;
      y=((le*(1+T[i]))/2);
      for ( ; j<3; j++)
	{
	  x=(wi*(1+T[j]))/2;
	  z=height(x, y);
	  a=a+(W[j]*z);
	}
      a=a;
      b=b+W[i]*a;
    }
  b=b*wi*l/4;
  vol=b;
}

class Fill:public Layers
{
public:
  Fill (double w, double l):Layers(w, l){};
  double height(double x, double y)
  {
    return (surface(x, y)-fclay(x, y));
  }
};

class Clay:public Layers
{
public:
  Clay(double w, double l):Layers(w, l){};
  double height(double x, double y)
  {
    return ( fclay(x, y)-csand(x, y));
  }
};

class Sand: public Layers
{
public:
  Sand(double w, double l):Layers(w, l){};
  double height(double x, double y)
  {
    return (csand(x, y)-limit(x, y));
  }
};

double surface(double x, double y)
{
  return (pow(sin(0.01*x), 3.))-(pow(cos(0.005*y), 3.))+30;
}

double fclay(double x, double y)
{
  return (4 * pow (cos (0.002*x), 3.))-(1.4 * pow(cos(0.01 * pow (x, 5) * y ), 3.))+10;
}

double csand(double x, double y)
{
  return (5 * pow (sin (x*y*y/2500), 3));
}

double limit (double x, double y)
{
  return (-20);
}


main()
{
  Fill a (500.0, 950.0);
  Clay b (500.0, 950.0);
  Sand c (500.0, 950.0);

  a.volume();
  b.volume();
  c.volume();

  cout<<"Fill Volume = " <<a.volume<<endl;
  cout<<"Clay Volume = " <<b.volume<<endl;
  cout<<"Sand Volume = " <<c.volume<<endl;
}


