Question

In: Computer Science

Write a program that calculates mean and standard deviation for four user entered values. The most...

Write a program that calculates mean and standard deviation for four user entered values. The most common measures of a sample are the mean and the standard deviation. the mean is the sum of the values divided by the number of elements in the data set. The dispersion - or spread in the values - is measured by the standard deviation The equation for the mean is x¯ = x1 + x2 + · · · + xn The equation for the standard deviation is sx = √ (x1 − x¯) 2 + (x2 − x¯) 2 + · · · + (xn − x¯) 2 n − 1 Your program will have the user enter four values (all doubles), You might call them x1, x2,x3,and x4. The program will then pass these four values to a function called mean that will calculate and return the mean of the four values. The mean and the four values will then be passed to a second function called stdev which will calculate and return the standard deviation of the four values. You program should be using functions. There will be a function printHeader that prints the splash screen, a function mean that calculates the mean, a function stdev that calculates the standard deviation, and a function printResults that prints the four values, their mean, and their standard deviation Your program must also include comments with your name, the date, and a short description of the project. It must also print this information as a splash screen at the beginning of the program run. It should print like:

X: 4.00, 7.00, 1.00, 10.00

Mean: 5.50

Std Dev: 3.87

This needs to be done in C++. This is what I have so far.

//   Pound includes - will need the string and cmath libraries
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>

using namespace std;

//   Function Prototypes - Need to add three more. One for mean, one for standard deviation, and one for the printResults
void printHeader(string, string);
double mean(double, double, double, double);
double stdev(double, double, double, double, double);

int main(void) {

   // Splash Screen
   printHeader("20 October 2020", "Calculating Statistics");
  
   //   Declare and Initialize all of the variables. Will need doubles for the four data points, as well as a double for the mean // and one for the standard deviation
double x1, x2, x3, x4;
double mean;
double std;
  
   //   Prompt for entering data - you must enter four values
   cout << "Enter the first value: ";
   cin >> x1;
  
   cout << "Enter the second value: ";
   cin >> x2;
  
   cout << "Enter the third value: ";
   cin >> x3;
  
   cout << "Enter the fourth value: ";
   cin >> x4;

   // Pass the four data variables to a function that returns the mean
double m = mean (x1,x2,x3,x4);
  
   //   Pass the four data variables and the mean to a function that returns the standard deviation
   double std = stdev(m, x1, x2, x3, x4);
  

   //   Print the results
   //   Include the original values and the mean and the standard
// DO NOT PRINT IT HERE - pass the variables to a printResults function

return 0;
}  
void printResults(double m, double s, double x1, double x2, double x3, double x4){
cout << setprecision(2) << fixed << showpoint;
   cout << "Values: " << setw (10) << x1 << ", " << x2 << ", " << x3 << ", " << x4 << endl;
   cout << "Mean: " << setw (10) << m << endl;
   cout << "Standard Deviation: " << setw(10) << s << endl;

}

// Name:
// Date: 20 October 2020
// Function Definitions
void printHeader(string dueDate, string description) {
   //   Print the splash screen
   cout << endl;
   cout << "Name" << endl;
   cout << "Class" << endl;
   cout << dueDate << endl;
   cout << description << endl;
   cout << endl;

   return;
}

// Function definition for mean
double mean (double x1, double x2, double x3, double x4) {
return (x1 + x2 + x3 + x4) / 4;
}

// Function definition for standard deviation
double stdev(double m, double x1, double x2, double x3, double x4){
std = (m-x1)*(m-x1);
std + = (m-x2)*(m-x2);
std + = (m-x3)*(m-x3);
std + = (m-x4)*(m-x4);
std = std/3;
std = sqrt(std);
return std;
}

Solutions

Expert Solution

CODE -

//   Pound includes - will need the string and cmath libraries

#include<iostream>

#include<iomanip>

#include<cmath>

#include<string>

using namespace std;

//   Function Prototypes - Need to add three more. One for mean, one for standard deviation, and one for the printResults

void printHeader(string, string);

double mean(double, double, double, double);

double stdev(double, double, double, double, double);

void printResults(double, double, double, double, double, double);

int main(void) {

    // Call function to print Splash Screen

    printHeader("20 October 2020", "Calculating Statistics");

    

    //   Declare and Initialize all of the variables. Will need doubles for the four data points,

    //   as well as a double for the mean and one for the standard deviation.

    double x1, x2, x3, x4;

    double mean_value;

    double std_dev;

    

    //   Prompt for entering data - you must enter four values

    cout << "Enter the first value: ";

    cin >> x1;

    cout << "Enter the second value: ";

    cin >> x2;

    cout << "Enter the third value: ";

    cin >> x3;

    cout << "Enter the fourth value: ";

    cin >> x4;

    // Pass the four data variables to a function that returns the mean

    mean_value = mean(x1,x2,x3,x4);

    

    // Pass the four data variables and the mean to a function that returns the standard deviation

    std_dev = stdev(mean_value, x1, x2, x3, x4);

    // Pass the four data variables, the mean, and the standard deviation that prints the results.

    printResults(mean_value, std_dev, x1, x2, x3, x4);

    return 0;

}


// Name:

// Date: 20 October 2020

// Function Definitions

// Function definition for printing the splash screen

void printHeader(string dueDate, string description)

{

   //   Print the splash screen

   cout << endl;

   cout << "Name: " << endl;

   cout << "Class: " << endl;

   cout << dueDate << endl;

   cout << description << endl;

   cout << endl;

}

// Function definition for mean

double mean (double x1, double x2, double x3, double x4)

{

    return (x1 + x2 + x3 + x4) / 4;

}

// Function definition for standard deviation

double stdev(double m, double x1, double x2, double x3, double x4)

{

    return sqrt( ( (m-x1)*(m-x1) + (m-x2)*(m-x2) + (m-x3)*(m-x3) + (m-x4)*(m-x4) ) / 3);

}

// Function definition for printing results.

void printResults(double m, double s, double x1, double x2, double x3, double x4)

{

    cout << setprecision(2) << fixed << showpoint;

    cout << "X: " << setw (10) << x1 << ", " << x2 << ", " << x3 << ", " << x4 << endl;

    cout << "Mean:  " << setw (25) << m << endl;

    cout << "Standard Deviation:   " << setw(10) << s << endl;

}

SCREENSHOTS -

CODE -

OUTPUT -

If you have any doubt regarding the solution, then do comment.
Do upvote.


Related Solutions

Write a program that calculates mean and standard deviation for four user entered values. The most...
Write a program that calculates mean and standard deviation for four user entered values. The most common measures of a sample are the mean and the standard deviation. the mean is the sum of the values divided by the number of elements in the data set. The dispersion - or spread in the values - is measured by the standard deviation The equation for the mean is x¯ = x1 + x2 + · · · + xn The equation...
Write a program that calculates mean and standard deviation for four user entered values. The most...
Write a program that calculates mean and standard deviation for four user entered values. The most common measures of a sample are the mean and the standard deviation. the mean is the sum of the values divided by the number of elements in the data set. The dispersion - or spread in the values - is measured by the standard deviation The equation for the mean is x¯ = x1 + x2 + · · · + xn The equation...
Playing with encryption: Write a program that will read a four-digit integer entered by the user...
Playing with encryption: Write a program that will read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the second digit with the fourth. Finally, print the original number and its encrypted one. Now reverse the process. Read an encrypted integer and decrypt it by reversing the algorithm to obtain the original...
JAVA I need to write a code that calculates mean and standard deviation using arrays and...
JAVA I need to write a code that calculates mean and standard deviation using arrays and OOP. This is what I have so far. I'm close but my deviation calculator method is throwing errors. Thanks so much :) import java.util.Scanner; import java.util.Arrays; public class STDMeanArray { private double[] tenUserNums = new double[10];//Initialize an array with ten index' private double mean; private double deviation; Scanner input = new Scanner(System.in);//create new scanner object /*//constructor public STDMeanArray(double tenUserNum [], double mean, double deviation){...
Write a program that calculates the salary of employees. The program should prompt the user to...
Write a program that calculates the salary of employees. The program should prompt the user to enter hourly rate and number of hours of work a day. Then, the program should display the salary daily, bi-weekly (5 days a week), and monthly. Sample program: Enter your hourly rate: >>> 20 Enter how many hours you work a day: >>> 8 Your daily salary is: $160 Your bi-weekly salary is: $1600 Your monthly: $3200
write a program to calculate and print payslips write program that calculates and prints payslips. User...
write a program to calculate and print payslips write program that calculates and prints payslips. User inputs are the name of employee, numbers of hours worked and hourly rate c++ language
Write a program named MakeChange that calculates and displays the conversion of an entered number of...
Write a program named MakeChange that calculates and displays the conversion of an entered number of dollars into currency denominations—twenties, tens, fives, and ones. For example, if 113 dollars is entered, the output would be twenties: 5 tens: 1 fives: 0 ones: 3. Answer in C# (P.S i'm posting the incomplete code that i have so far below.) using System; using static System.Console; class MakeChange { static void Main() { int twenties, tens, fives, ones; WriteLine("Enter the number of dollars:");...
Write a C++ program that finds the minimum number entered by the user .The user is...
Write a C++ program that finds the minimum number entered by the user .The user is allowed to enter negative numbers 0, or positive numbers. The program should be controlled with a loop statement. Break statements is not allowed to break from loop. After each number inputted by the user, The program will prompt user if they need to enter another number. User should enter either Y for yes or N for no. Make Sure the user enters either Y...
Write a program that checks whether or not a date entered in by the user is...
Write a program that checks whether or not a date entered in by the user is valid. Display the date and say if it is valid. If it is not valid explain why. The input may be in the format mm/dd/yyyy, m/d/yyyy, mm/d/yyyy, or m/dd/yyyy. A valid month (mm) must be from 1 to 12 A valid day (dd) must be from 1 to the appropriate number of days in the month April, June, September, and November have 30 days...
Write a program that asks the user for an angle, entered in radians. The program should...
Write a program that asks the user for an angle, entered in radians. The program should then display the sine, cosine, and tangent of the angle. (Use the sin, cos, and tan library functions to determine these values.) The output should be displayed in fixed-point notation, rounded to four decimal places of precision Take your previous Angle Calculator program and modify it to do a table of trig values. The columns will be: Degrees, Sine, Cosine, Tangent,. And the rows...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT