Question

Write a program that computes the average and standard deviation of four scores. The standard deviation...

Write a program that computes the average and standard deviation of four scores. The standard deviation is defined to be the square root of the average of the four values. Use two functions. One function to calculate the average, this function should be with Return Type "double". Second Function should be to calculate standard deviation, this function should be with Return Type "void". Allow the program to continue until the user tells the program he/she is finished.

This is for C++

The program must use at least 2 programmer defined functions

The program must match the Return Type constraints

The program must continue calculations as long as user wishes (ie: use a do while loop) "Enter y to run the program again or n for no"

average = (s1 + s2 + s3 + s4) / 4

The standard deviation is computed as

standard_deviation = sqrt( ( (s1 -average)2 + (s2 - average)2 + ( s3 - average)2 + (s4 - average)2  )/4 ).

SAMPLE OUTPUT

Enter four decimal numbers =>12.3 13.4 10.5 9.0
The average = 11.3
The standard deviation of these numbers = 1.68375
Please enter y to continue =>y


Enter four decimal numbers =>1 2 3 4
The average = 2.5
The standard deviation of these numbers = 1.11803
Please enter y to continue =>n

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

Following is the answer:

#include <iostream>
#include <cmath>
using namespace std;
  
// Function that return average
double average(double array[])
{
double sum = 0;
for (int i=0; i<4; i++) {
sum += array[i];
}
return sum/4;
}

// Function that return deviation.
double deviation(double array[])
{
double standardDeviation = 0.0;

for (int i=0; i<4; i++) {
standardDeviation += pow(array[i]- average(array),2);
}
cout<<"The standard deviation of these numbers = "<<sqrt(standardDeviation/4)<<endl;
}
  
// Driver code
int main()
{
int n = 4;
double array[4];
  
char ch;
do{
cout<<"Enter four decimal numbers => ";
for(int i = 0 ; i < n ; i++){
cin>>array[i];
}
  
cout << "The average = "<<average(array) << endl;
deviation(array);
  
cout<<"Please enter y to continue =>";
cin>>ch;
cout<<endl;
}while(ch != 'n');
return 0;
}

Output:

Enter four decimal numbers => 12.3 13.4 10.5 9.0 The average = 11.3 The standard deviation of these numbers = 1.68375 Please

Add a comment
Know the answer?
Add Answer to:
Write a program that computes the average and standard deviation of four scores. The standard deviation...
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
  • Write a program in C++ to calculate the average (mean) and the standard deviation of a...

    Write a program in C++ to calculate the average (mean) and the standard deviation of a list of numbers using vectors. Your program should... Prompt for the number of values the user wishes to enter Prompt the user to enter the values one at a time for the number of requested values into a vector Calculate and display the Mean and Standard Deviation The flow of your code should be similar to: int main() { /** Prompt the user and...

  • Write a C program that takes two sets of characters entered by the user and merge...

    Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...

  • Write a program that takes as input five numbers and outputs the mean (average) and standard...

    Write a program that takes as input five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are X_1, X_2, . X_3, X_4, X_5 then the mean is equal to X = (X_1 + X_2 + X_3+ X_4 + X_5)/5 and the standard deviation is: squareroot (Xl - X)^2 + (X2 - X)^2 + (X3 - X)^2 + (X4 - X)^2 + (X5 - X)^2 Your program must contain at least the following functions:...

  • write a program code that asks the user how many numbers they wish to find the...

    write a program code that asks the user how many numbers they wish to find the statistics of and then asks the user to enter those numbers. The program must then calculate and display the average variance and standard deviation of the numbers entered by the user. the program code must -ask three user how many numbers they wish to find the statistics of -ask the user to enter those numbers and store them in an array - use a...

  • Average and Standard Deviation of 4 numbers **c++** Write an input function to input 4 doubles....

    Average and Standard Deviation of 4 numbers **c++** Write an input function to input 4 doubles. then write a function that computes the average of 4 doubles and returns the average and the standard deviation. Write a output routine that shows the 6 numbers. Please feel free to use sub-functions to break up your code.    you can name the four variables a1, a2, a3, a4, or something equally simple as long as you are consistent. Average (or mean) is...

  • Write a program that calculates the average of a stream of non-negative numbers. The user can...

    Write a program that calculates the average of a stream of non-negative numbers. The user can enter as many non-negative numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, zero counts as a number that goes into the average. Of course, the negative number should not be part of the average (and, for this program, the average of 0 numbers is 0). You must use a method to read...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • VBA on Excel 2. Complete this problem on Sheet2. a) Write a user-defined function AreaOfTriangle that...

    VBA on Excel 2. Complete this problem on Sheet2. a) Write a user-defined function AreaOfTriangle that computes and returns the area of a triangle with sides s1, s2, s3. b)Test your function AreaOfTriangle by writing a main procedure, which has the user to input the sides , calls the function to find the area , and displays the result with a message box. Test your program with s1=6.5, s2=4.2, s3=5.1.

  • Have Corporate Sales for 6 divisions and their quarterly sales figures. The issue is the error...

    Have Corporate Sales for 6 divisions and their quarterly sales figures. The issue is the error function where I am unable to have user reinput the same quarterly amount without going to the next quarter input. This has affected the total sales for the company. /***************************************** This program gathers sales information for six divisions and displays the total sales for each division and total company. *****************************************/ #include<iostream> using namespace std; // Classs division sales class DivSales { private: // Variables...

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