The correlation coefficient of two input sequences is given by r = n sigma x_i y_i - sigma x_i sigma y_i/Squareroot [n sigma x_i^2 - (sigma x_i)^2][n sigma y_i^2 - (sigma y_i)^2] Adapt Example 4.11 to compute the correlation coefficient from a sequence of pairs of input values from an input file. Solution #include using namespace std; //Class for standard deviation class stdDev { private: int max; double value[100]; double mean; public: double CalMean() { double sum = 0; for(int i = 0; i < max; i++) sum += value[i]; return (sum / max); } double CalVariane() { mean = CalMean(); double temp = 0; for(int i = 0; i < max; i++) { temp += (value[i] - mean) * (value[i] - mean) ; } return temp / max; } double CalSampleVar() { mean = CalMean(); //get mean double temp = 0; for(int i = 0; i < max; i++) { temp += (value[i] - mean) * (value[i] - mean) ; //apply formula } return temp / (max - 1); //returns sample variance } int SetValues(double *p, int count) { if(count > 100) return -1; max = count; for(int i = 0; i < count; i++) value[i] = p[i]; return 0; } double CalStdDev()//returns Standard deviation { return sqrt(CalVariane()); } double SampleStdDev()//returns sample deviation { return sqrt(CalSampleVar()); } }; class Calculate { private: double XTerms[100]; double YTerms[100]; int max; stdDev x; // Standard deviation for x stdDev y;// Standard deviation for y public: //set x and y series values to class members void SetValues(double *xval, double *yval, int count) { for(int i = 0; i < count; i++) { XTerms[i] = xval[i]; YTerms[i] = yval[i]; } x.SetValues(xval, count); y.SetValues(yval, count); max = count; } double Calculate_Covariance() { double xmean = x.CalMean();//Get X meam double ymean = y.CalMean();//get y mean double total = 0; for(int i = 0; i < max; i++) { total += (XTerms[i] - xmean) * (YTerms[i] - ymean); } return total / max;//return Covariance } double Calculate_Correlation()//Find correlation { double cov = Calculate_Covariance(); double correlation = cov / (x.CalStdDev() * y.CalStdDev()); return correlation; } }; int main() { Calculate calc; //create object of class double xarr[] = { 0, 2, 4, 6, 8 }; // x series double yarr[] = { 6, 13, 15, 16, 20 };// y series calc.SetValues(xarr,yarr,sizeof(xarr) / sizeof(xarr[0]));//set series values cout<<\"X series ={ 0, 2, 4, 6, 8 }\ Y series={ 6, 13, 15, 16, 20 }\ \"; cout<<\"Correlation \"<< calc.Calculate_Correlation(); } ===================================================================== ======== Output: akshay@akshay-Inspiron-3537:~/Chegg$ g++ coeffici.cpp akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out X series ={ 0, 2, 4, 6, 8 } Y series={ 6, 13, 15, 16, 20 } Correlation 0.952157.