/* plotter19.cpp can be used to graph an arbitrary function(s) 
   using class CartesianSystem.

   Output: prompts for input
   Input:  values for the endpoints of the x and y axes
   Output: the graphs of f(x) and g(x)

   Note:  In this example, two functions f(x) and g(x) are plotted.
------------------------------------------------------------------*/

#include <iostream>                 // cin, cout, >>, <<
#include <cmath>                    // cos()

#include "CartSys.h"                // declaration of CartesianSystem


double f(double x)                  // a function to be plotted
{
    return x * cos(x);
}

double g(double x)                  // another function to be plotted
{
    return x;
}

int main()
{
    cout << "\nThis program plots some functions..."
            "\n(currently y = x*cos(x) and y = x.)\n";

    double xMin, xMax,              // endpoints of the axes
           yMin, yMax;
    char returnChar;                 // the newline
        
    do                              // get the x bounds
    {
        cout << "\nPlease enter the minimum and maximum x values: ";
        cin >> xMin >> xMax;
    }
    while (xMin >= xMax);

    do                              // get the y bounds
    {
        cout << "\nPlease enter the minimum and maximum y values: ";
        cin >> yMin >> yMax;
    }
    while (yMin >= yMax);

    cin.get(returnChar);            // clean out the newline
                                    // construct a Cartesian system
    CartesianSystem CoordinateSys(xMin, xMax, yMin, yMax);

    CoordinateSys.DrawAxes();       // draw the axes

    CoordinateSys.Graph(f);         // graph f

    CoordinateSys.Graph(g, CYAN);   // graph g in a different color
}

