Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have compelted this frist part of this and attached my code, but do not know how to comeplte part 2. Could someone please attach

I have compelted this frist part of this and attached my code, but do not know how to comeplte part 2. Could someone please attach the parts needed for it to work and please explain. My first is my .cpp file and the second is the header file for reference.

image text in transcribedimage text in transcribedimage text in transcribed

#include"lab6.h"

//To calculate and return mean double mean(int x1, int x2, int x3, int x4) { //To store the result double sum = 0; //Calculates the sum sum += double(x1) + double (x2) + double (x3) + double (x4); //Calculate average and returns it return (sum / 4); }//End of function

//To calculate and return variance double variance(int x1, int x2, int x3, int x4) { //To store the variance result double res = 0; //Calculates the number minus mean of the numbers double d1 = double(x1) - mean(x1, x2, x3, x4); double d2 = double (x2) - mean(x1, x2, x3, x4); double d3 = double (x3) - mean(x1, x2, x3, x4); double d4 = double (x4) - mean(x1, x2, x3, x4); //Calls the sumOfSquare res += sumOfSquares(d1, d2, d3, d4); //Returns the result after calculating the average return res/4; }//End of function

//To calculate and return sum of the square double sumOfSquares(double d1, double d2, double d3, double d4) { //To store the sum double sum = 0; //Calculates the sum of the square of the numbers sum = (d1 * d1) + (d2 * d2) + (d3 * d3) + (d4 * d4); //Returns the result return sum; }//End of function

//To calculate and return standard deviation double stdDev(int x1, int x2, int x3, int x4) { //To store the result double res = 0; //Calls the variance function to calculate variance and find it square root res = sqrt(variance(x1, x2, x3, x4)); //Returns the result return res; }

#include #include #include #include

using std::string; using std::ifstream; using std::ofstream; using std::endl; using std::cout;

//To calculate and return standard deviation double stdDev(int x1, int x2, int x3, int x4); //To calculate and return mean double mean(int x1, int x2, int x3, int x4); //To calculate and return variance double variance(int x1, int x2, int x3, int x4); //To calculate and return sum of the square double sumOfSquares(double d1, double d2, double d3, double d4);

For part 2, well be using the functions you wrote in part 1, to get part 2 to do what we want This will use the same command structure as we did in the last lab and weve been working on in the projects. So you'll need a while loop and an if statement within to determine which command we are doing. Then you'll call the function to do what is asked. Commands 1. mean - this will compute the mean of the 4 given numbers 2. standard-deviation - this will compute the standard deviation of the 4 given numbers. 3. variance - this will compute the variance of the 4 given numbers. 4. sum-of-squares - this will compute the sum of the squares of the 4 given numbers. Each of the commands and the 4 given numbers will be echoed back out. We do this so that you can see what the input was and if you were using this to do this work you could make sure that the input was read in correctly and its a useful debugging technique to make sure you code is reading the data correctly. Input Here is what a sample input command file might look like: mean 1 2 3 4 sum-of-squares 1 2 3 4 variance 1 2 3 4 standard-deviation 1 2 3 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions

Question

5. Who should facilitate the focus group?

Answered: 1 week ago