code:

Can't Copy and Paste this?

Click here for a copy-and-paste friendly version of this code!

 

Terms of Agreement:   

By using this code, you agree to the following terms...   

1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   

2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   

3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 

4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.  

//     

#include

#include

#define PI 3.14159;

class Equation

     {

     // y = m*x + b

    

     double m; // slope

     double b; // y intercept

    

     public:

    

     Equation() {}

     ~Equation() {}

     double Givem() { return m; }

     double Giveb() { return b; }

     int SetValM(double x)

         {

         m = x;

         return 0;

         }

         int SetValB(double x)

             {

             b = x;

             return 0;

             }

             int PrintResults()

                 {

                 cout << "y = " << m <<"x + " << b << endl;

                 return 0;

                 }

                 };

                class Point

                     {

                     double x;

                     double y;

                    

                     public:

                    

                     Point () {}

                     ~Point () {}

                     double Givex() { return x; }

                     double Givey() { return y; }

                     int SetValX(double a)

                         {

                         x = a;

                         return 0;

                         }

                        

                         int SetValY(double a)

                             {

                             y = a;

                             return 0;

                             }

                             int PrintResults()

                                 {

                                 cout << "(" << x << "," << y << ")" << endl;

                                 return 0;

                                 }

                                 };

                                class Cartesia

                                     {

                                     public:

                                     double findangle(Point a, Point b);

                                     double finddistance(Point a, Point b);

                                     Point findmidpoint(Point a, Point b);

                                     int findquadrant(Point a);

                                     Equation trendline(Point a, Point b); // linear trendline

                                     Equation trendline(Point a, Point b, Point c); // quadratic trendline

                                     Equation trendline(Point a, Point b, Point c, Point d); // cubic trendline

                                     };

                                    Cartesia::Cartesia();

                                    double Cartesia::findangle(Point a, Point b)

                                         {

                                         double theta;

                                         theta = tanh((b.Givey() - a.Givey()) / (b.Givex() - a.Givex()));

                                         theta *= 180/PI;

                                         return theta;

                                         }

                                        double Cartesia::finddistance(Point a, Point b)

                                             {

                                             double distance;

                                             distance = sqrt(pow(b.Givex() - a.Givex(),2)+pow(b.Givey() - a.Givey(),2));

                                             return distance;

                                             }

                                            Point Cartesia::findmidpoint(Point a, Point b)

                                                 {

                                                 Point c;

                                                 c.SetValX((a.Givex() + b.Givex())/2);

                                                 c.SetValY((a.Givey() + b.Givey())/2);

                                                 return c;

                                                 }

                                                int Cartesia::findquadrant(Point a)

                                                     {

                                                     unsigned int quadrant;

                                                     if(a.Givex()>0 && a.Givey()>0)

                                                     quadrant = 1;

                                                     else if(a.Givex()<0 && a.Givey()>0)

                                                     quadrant = 2;

                                                     else if(a.Givex()<0 && a.Givey()<0)

                                                     quadrant = 3;

                                                     else if(a.Givex()>0 && a.Givey()<0)

                                                     quadrant = 4;

                                                     return quadrant;

                                                     }

                                                    Equation Cartesia::trendline(Point a, Point b)

                                                         {

                                                         Equation x;

                                                        

                                                         x.SetValM((b.Givey() - a.Givey()) / (b.Givex() - a.Givex()));

                                                         x.SetValB(a.Givey() - (x.Givem() * a.Givex()));

                                                         return x;

                                                         }

                                                        Equation Cartesia::trendline(Point a, Point b, Point c)

                                                             {

                                                             Equation x;

                                                             Point y;

                                                             Point z;

                                                            

                                                             y = findmidpoint(a,b);

                                                             z = findmidpoint(b,c);

                                                             x = trendline(y,z);

                                                             return x;

                                                             }

                                                            Equation Cartesia::trendline(Point a, Point b, Point c, Point d)

                                                                 {

                                                                 Equation x;

                                                                 Point y;

                                                                 Point z;

                                                                

                                                                 y = findmidpoint(a,b);

                                                                 z = findmidpoint(c,d);

                                                                 x = trendline(y,z);

                                                                 return x;

                                                                 }