Concept explainers
Write a function 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: (Si –a)2, where a is average of the four scores S1, S2, S3, and S4. The function will have six parameters and will call two other functions. Embed the function in a driver
Creation of program to compute average and standard deviation
Program Plan:
- Define the method “clc()” to calculate value of standard deviation.
- The variables are been declared initially.
- The difference of value with average is been computed.
- The square of resultant value is been computed.
- The final value is been returned.
- Define the method “stdMean()” to compute value of standard deviation as well as mean of values.
- The variables are been declared initially.
- The value of average is been calculated by summing values and dividing it by count of elements.
- Compute deviations for each value by calling “clc()” method.
- Compute overall value of deviation and return square root of resultant value.
- Define main method.
- Declare variables values of scores.
- Get each value from user.
- Store values in different variables.
- Call “stdMean()”to compute standard deviation as well as mean of values.
- Display standard deviation and mean of values.
Program Description:
The following C++ program describes about creation of program to compute mean as well as standard deviation of values entered by user.
Explanation of Solution
Program:
//Include libraries
#include <iostream>
#include <math.h>
//Define function prototypes
double stdMean(double,double,double,double,int, double&);
double clc(double, double);
//Use namespace
using namespace std;
//Define main method
int main()
{
//Declare variables
double s1,s2,s3,s4,avg,sd;
//Get value from user
cout<<"Enter 1st value ";
//Store value
cin>>s1;
//Get value from user
cout<<"Enter 2nd value ";
//Store value
cin>>s2;
//Get value from user
cout<<"Enter 3rd value ";
//Store value
cin>>s3;
//Get value from user
cout<<"Enter 4th value ";
//Store value
cin>>s4;
//Call method
sd=stdMean(s1,s2,s3,s4,4,avg);
//Display message
cout<<"The average is "<<avg<<"\n";
//Display message
cout<<"The standard deviation is "<<sd<<"\n";
//Pause console window
system("pause");
//Return
return 0;
}
//Define method clc()
double clc(double x,double avg)
{
//Declare variable
double tmp;
//Compute value
tmp=x-avg;
//Return value
return tmp*tmp;
}
//Define method stdMean()
double stdMean(double lX1, double lX2,double lX3, double lX4,
int n, double &avg)
{
//Declare variables
double d1,d2,d3,d4,dev;
//Compute value
avg=(lX1+lX2+lX3+lX4)/n;
//Call method
d1=clc(lX1,avg);
//Call method
d2=clc(lX2,avg);
//Call method
d3=clc(lX3,avg);
//Call method
d4=clc(lX4,avg);
//Compute value
dev=(d1+d2+d3+d4)/n;
//Return value
return sqrt(dev);
}
Enter 1st value 8
Enter 2nd value 3
Enter 3rd value 5
Enter 4th value 4
The average is 5
The standard deviation is 1.87083
Press any key to continue . . .
Want to see more full solutions like this?
Chapter 5 Solutions
Problem Solving with C++ (9th Edition)
Additional Engineering Textbook Solutions
Mechanics of Materials (10th Edition)
Modern Database Management
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- Find the error: daily_sales = [0.0, 0,0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] for i in range(7): daily_sales[i] = float(input('Enter the sales for ' \ + days_of_week[i] + ': ')arrow_forwardFind the error: daily_sales = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] for i in range(6): daily_sales[i] = float(input('Enter the sales for ' \ + days_of_week[i] + ': '))arrow_forwardWhat are the steps you will follow in order to check the database and fix any problems with it and normalize it? Give two references with your answer.arrow_forward
- What are the steps you will follow in order to check the database and fix any problems with it? Have in mind that you SHOULD normalize it as well. Consider that the database offline is not allowed since people are connected to it and personal data might be bridged and not secured. Provide three refernces with you answer.arrow_forwardShould software manufacturers should be tolerant of the practice of software piracy in third-world countries to allow these countries an opportunity to move more quickly into the information age? Why or why not?arrow_forwardI would like to know about the features of Advanced Threat Protection (ATP), AMD-V, and domain name space (DNS).arrow_forward
- I need help to resolve the following activityarrow_forwardModern life has been impacted immensely by computers. Computers have penetrated every aspect of oursociety, either for better or for worse. From supermarket scanners calculating our shopping transactionswhile keeping store inventory; robots that handle highly specialized tasks or even simple human tasks,computers do much more than just computing. But where did all this technology come from and whereis it heading? Does the future look promising or should we worry about computers taking over theworld? Or are they just a necessary evil? Provide three references with your answer.arrow_forwardWhat are the steps you will follow in order to check the database and fix any problems with it? Have in mind that you SHOULD normalize it as well. Describe in full, consider the following:• Taking the database offline is not allowed since people are connected to it.• Personal data might be bridged and not secured. Provide three refernces with you answerarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrCOMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE L
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,