Problem Statement
    
We are given a set of points in the x,y plane with x increasing horizontally and y increasing vertically. We want to choose a line that is as close to the points as possible. Specifically, we want to choose a line that minimizes the sum of the errors for the points, where the error for each point is defined to be the absolute value of the vertical distance between the point and the line. (If a vertical line is chosen, the error for any point not on the line is infinite.)
Create a class LinearFit that contains a method errorSum that is given vector s x and y and returns the sum of the errors for the line closest to the points. The ith element of x and the ith element of y are the coordinates of the ith point.
Definition
    
Class:
LinearFit
Method:
errorSum
Parameters:
vector , vector 
Returns:
double
Method signature:
double errorSum(vector  x, vector  y)
(be sure your method is public)
    

Notes
-
A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.
Constraints
-
x will have between 1 and 50 elements, inclusive.
-
y will have the same number of elements as x .
-
Each element of x and of y will be between -1,000,000 and 1,000,000, inclusive.
-
The points given by x and y will be distinct.
Examples
0)

    
{0,17,17,0}
{1,1,0,0}
Returns: 2.0
A horizontal line at a height of .5 will have an error of .5 at each of the four points so the sum of the errors is 4 * .5 = 2. There are other lines that achieve the same result, but no line can do better.
1)

    
{7,7,7,7,7}
{9,1,-50,12,2}
Returns: 0.0
A vertical line with x=7 will go through all the points so each error will be 0.
2)

    
{1,2,3,4}
{1,2,3,5}
Returns: 1.0
A straight line that goes through the first three points will have an error of 1 on the last point.
3)

    
{-1000000,0,1000000}
{1000000,1,-1000000}
Returns: 1.0

4)

    
{129295} 
{108108} 
Returns: 0.0