In: Computer Science
Make one program in c++
Implement the Point class composed of an ordered pair (?, ?). Redefine the operators in your Point class Calculate the coefficients of a Linear Regression ? = ?? + ? with next data for x and y. x y 46 4.7 72 12.3 59 6.5 56 5.9 54 6.6 70 10.3 68 8.4 48 4
HERE IS YOUR CODE,
#include "TwoDPoint.h"
#include <iostream>
using namespace std;
 
int main()
{
   int a,b;
   TwoDPoint ptsArray1[2];  
   cout << "Enter ordered pairs : " << endl;
   for(int i=0; i<2; i++ )
   {
       cin >> a;
       cin >> b;
       ptsArray1[i].setX(a);
       ptsArray1[i].setY(b);
   }
   int sumx=0, sumy=0 ,txy,tx2,ty2;
   double xy[2],x2[2],y2[2];
    for(int i=0; i<2; i++ )
   {
        xy[i] = ptsArray1[i].getX() * ptsArray1[i].getY();
        x2[i] = ptsArray1[i].getX() * ptsArray1[i].getX();
        y2[i] = ptsArray1[i].getY() * ptsArray1[i].getY();
   }
    for(int i=0; i<2; i++ )
   {
       sumx = sumx + ptsArray1[i].getX();
       sumy = sumy + ptsArray1[i].getY();
       txy  = txy + xy[i];
       tx2  = tx2 + x2[i];
       ty2  = ty2 + y2[i];
   }
   
   int A,B;
   A = (sumx*tx2)-(sumx*txy) / 2*(tx2) - (tx2)^2;
   B = 2*(txy) - (sumx)*(sumy) / 2*(tx2) - (tx2)^2;
   
   cout << "Y =" << A << " + " << B <<" x" << endl;
   
    return 0;
}
"TwoDPoint.h" and "TwoDPoint.cpp" are given below,
#ifndef TWODPOINT_H_
#define TWODPOINT_H_
namespace std {
class TwoDPoint {
protected:
        double x;
        double y;
public:
        TwoDPoint();
        TwoDPoint(double a, double b);
        virtual ~TwoDPoint();
        double getX() const;
        void setX(double x);
        double getY() const;
        void setY(double y);
        void print();
};
} /* namespace std */
#endif /* TWODPOINT_H_ */
#include "TwoDPoint.h"
#include <iostream>
namespace std {
TwoDPoint::TwoDPoint() {
        // TODO Auto-generated constructor stub
        x = 0.0;
        y = 0.0;
}
TwoDPoint::TwoDPoint(double a, double b) {
        // TODO Auto-generated constructor stub
        x = a;
        y = b;
}
double TwoDPoint::getX() const {
        return x;
}
void TwoDPoint::setX(double x) {
        this->x = x;
}
double TwoDPoint::getY() const {
        return y;
}
void TwoDPoint::setY(double y) {
        this->y = y;
}
void TwoDPoint::print() {
   cout << "Point @ (" << x << "," << y << ")";
}
TwoDPoint::~TwoDPoint() {
        // TODO Auto-generated destructor stub
}
} /* namespace std */
The output of the code is;