Question: Programming Assignment: Stats Write a C++ program that asks the user to enter five real numbers and then calculates and displays the following statistics: sum,

Programming Assignment: Stats

Write a C++ program that asks the user to enter five real numbers and then calculates and displays the following statistics: sum, sample mean, and sample standard deviation.

Input

Your program should ask the user to enter five real numbers. The numbers can be negative, positive, or zero. Declare each of the five variables that will store the numbers as double. Prompt the user to enter the five numbers on separate lines. That is, the user should enter the first number and press enter, the second number and press enter, etc.

NOTE: If the user enters nonnumeric characters your program will generate an error. For this assignment, however, you do not have to test for valid user input.

Formulas

The formulas for the sample mean, sample variance, and the sample standard deviation for a sample of five numbers are as follows:

Statistic

Formula

sample mean ()

(n1 + n2 + n3 + n4 + n5) / 5

sample standard deviation

?sample variance

sample variance

((n1-)2 + (n2-)2 + (n3-)2 + (n4-)2 + (n5-)2 ) / 5

Functions

Your program should contain a total of eight functions including the main function. All functions except the main function are described in the following table:

Function Name

Description

Returns

getNumbers

Gets the five numbers from the user. The variables that store the five numbers must be passed as reference variables.

void

sum

Calculates the sum of the five numbers. The variables that store the five numbers should be passed by value.

double

mean

Calculates the sample mean of the five numbers. The variables that store the five numbers should be passed by value.

double

standard_deviation

Calculates the sample standard_deviation of the five numbers. The variables that store the five numbers should be passed by value.

double

variance

Calculates the sample variance of the five numbers. The variables that store the five numbers should be passed by value.

double

square

Accepts one double variable as a parameter and returns the square of the variables value. The variable should be passed by value.

double

displayStats

Displays the resulting statistics for the five numbers. All variables should be passed by value.

void

A structure chart of the eight functions is shown below. Notice that the main function calls five functions and the standard_deviation function calls two functions. Notice also that the variance function calls the mean function. Design your program by following the structure shown in this chart.

The main Function

The screenshot below shows how the main function should appear. Notice that there is one global constant in this program, but there are no global variables. Do not define any global variables in your program. All variables should be passed from one function to another by value or by reference as needed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!