Question

The following code below must be able to run using linked list instead of using arrays...

The following code below must be able to run using linked list instead of using arrays

-------------------------------------------------------------------------------------------------------

#include

#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 }\nY series={ 6, 13, 15, 16, 20 }\n";

       cout << "\nCorrelation " << calc.Calculate_Correlation() << "\n\n";

       system("pause");

}

/*

       Output

X series ={ 0, 2, 4, 6, 8 }

Y series={ 6, 13, 15, 16, 20 }

Correlation 0.952157

Press any key to continue . . .

*/

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream.h>
#include<conio.h>
#include<math.h>
//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()
{
clrscr();
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 }\nY series={ 6, 13, 15, 16, 20 }\n";
cout << "\nCorrelation " << calc.Calculate_Correlation() << "\n\n";
cout<<("Press any key to continueDOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, Program: TC- X series 0, 2, 4, 6, 8 series- 6, 13, 15, 16, 20 1 orrelat");
getch();
}

Add a comment
Know the answer?
Add Answer to:
The following code below must be able to run using linked list instead of using arrays...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads...

    import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads numbers from a file, calculates the mean and standard deviation, and writes the results to a file. */ public class StatsDemo { // TASK #1 Add the throws clause public static void main(String[] args) { double sum = 0; // The sum of the numbers int count = 0; // The number of numbers added double mean = 0; // The average of the...

  • Fix the following program (C++). #include <iostream> #include <cmath> #include <vector> #include <limits> using namespace std;...

    Fix the following program (C++). #include <iostream> #include <cmath> #include <vector> #include <limits> using namespace std; /* * Calculate the square of a number */ float square (float x) { return x*x; } /* * Calculate the average from a list of floating point numbers */ float average(vector<float>& values) { float sum = 0.0f; float average; for (float x : values) sum += x; average = sum / values.size(); return average; } /** Calculate the standard deviation from a vector...

  • Please program in C++ and document the code as you go so I can understand what...

    Please program in C++ and document the code as you go so I can understand what you did for example ///This code does~ Your help is super appreciated. Ill make sure to like and review to however the best answer needs. Overview You will revisit the program that you wrote for Assignment 2 and add functionality that you developed in Assignment 3. Some additional functionality will be added to better the reporting of the students’ scores. There will be 11...

  • pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the...

    pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the last assignment by providing the following additional features: (The additional features are listed in bold below) Class Statistics In the class Statistics, create the following static methods (in addition to the instance methods already provided). • A public static method for computing sorted data. • A public static method for computing min value. • A public static method for computing max value. • A...

  • The following class StatCalc defines a series of methods for computing statistics for a group of...

    The following class StatCalc defines a series of methods for computing statistics for a group of numbers. /* * An object of class StatCalc can be used to compute several simple statistics * for a set of numbers. Numbers are entered into the dataset using * the enter(double) method. Methods are provided to return the following * statistics for the set of numbers that have been entered: The number * of items, the sum of the items, the average, and...

  • The following class StatCalc defines a series of methods for computing statistics for a group of...

    The following class StatCalc defines a series of methods for computing statistics for a group of numbers. /* * An object of class StatCalc can be used to compute several simple statistics * for a set of numbers. Numbers are entered into the dataset using * the enter(double) method. Methods are provided to return the following * statistics for the set of numbers that have been entered: The number * of items, the sum of the items, the average, and...

  • I am having trouble understanding how this code is able to use the contents of the...

    I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide comments in the main code to describe what is happening? (especially on the bool isNumber) THE MAIN CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) {    if(!isdigit (s[0]))    {        if(s[0] != '-')        return false;               else if(s.length() == 1)        return false;...

  • I am having trouble understanding how this code is able to use the contents of the...

    I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide brief comments in the top code to show what is happening? THE CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) {    if(!isdigit (s[0]))    {        if(s[0] != '-')        return false;               else if(s.length() == 1)        return false;    }       for...

  • Can someone explain me parts of this code I do not fully understand what its doing...

    Can someone explain me parts of this code I do not fully understand what its doing or what its purpose is. I have highlighted the parts I'm confused over. Please explain thoroughly. import java.util.Scanner; class A1Stats { public static void main(String args[]) { double min, max, sum, mean; int n; Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); String[] numbers = input.split(" "); double value[] = new double[numbers.length]; if(numbers.length > 0){ for (int i = 0; i < numbers.length;...

  • How can I write this code (posted below) using vectors instead of arrays? This is the...

    How can I write this code (posted below) using vectors instead of arrays? This is the task I have and the code below is for Task 1.3: Generate twenty random permutations of the number 0, 1, 2, ..., 9 using of the algorithms you designed for Task 1.3. Store these permutations into a vector and print them to the screen with the additional information of unchanged positions and number of calls torand(). Calculate the total numbers of unchanged positions. Compare...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT