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++ plus MyProgrammingLab with Pearson eText-- Access Card Package (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)
- 4. def modify_data(x, my_list): X = X + 1 my_list.append(x) print(f"Inside the function: x = {x}, my_list = {my_list}") num = 5 numbers = [1, 2, 3] modify_data(num, numbers) print(f"Outside the function: num = {num}, my_list = {numbers}") Classe Classe that lin Thus, A pro is ref inter Ever dict The The output: Inside the function:? Outside the function:?arrow_forwardpython Tasks 5 • Task 1: Building a Library Management system. Write a Book class and a function to filter books by publication year. • Task 2: Create a Person class with name and age attributes, and calculate the average age of a list of people Task 3: Building a Movie Collection system. Each movie has a title, a genre, and a rating. Write a function to filter movies based on a minimum rating. ⚫ Task 4: Find Young Animals. Create an Animal class with name, species, and age attributes, and track the animals' ages to know which ones are still young. • Task 5(homework): In a store's inventory system, you want to apply discounts to products and filter those with prices above a specified amount. 27/04/1446arrow_forwardOf the five primary components of an information system (hardware, software, data, people, process), which do you think is the most important to the success of a business organization? Part A - Define each primary component of the information system. Part B - Include your perspective on why your selection is most important. Part C - Provide an example from your personal experience to support your answer.arrow_forward
- Management Information Systemsarrow_forwardQ2/find the transfer function C/R for the system shown in the figure Re དarrow_forwardPlease original work select a topic related to architectures or infrastructures (Data Lakehouse Architecture). Discussing how you would implement your chosen topic in a data warehouse project Please cite in text references and add weblinksarrow_forward
- Please original work What topic would be related to architectures or infrastructures. How you would implement your chosen topic in a data warehouse project. Please cite in text references and add weblinksarrow_forwardWhat is cloud computing and why do we use it? Give one of your friends with your answer.arrow_forwardWhat are triggers and how do you invoke them on demand? Give one reference with your answer.arrow_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 Ptr