EBK PROBLEM SOLVING WITH C++
EBK PROBLEM SOLVING WITH C++
9th Edition
ISBN: 9780133834505
Author: SAVITCH
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 5, Problem 1P

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: (Sia)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 program that allows you to test the function again and again until you teil the program you are finished.

Expert Solution & Answer
Check Mark
Program Plan Intro

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 Answer

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);

}

Sample Output

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?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Write a function max_magnitude() with two integer input parameters that returns the largest magnitude value. Use the function in a program that takes two integer inputs, and outputs the largest magnitude value. Ex: If the inputs are: 5 7 the function returns: 7 Ex: If the inputs are: -8 -2 the function returns: -8 Note: The function does not just return the largest value, which for -8 -2 would be -2. Though not necessary, you may use the built-in absolute value function to determine the max magnitude, but you must still output the input number (Ex: Output -8, not 8). Your program must define and call the following function:def max_magnitude(user_val1, user_val2) python import math # Define your function here. if __name__ == '__main__':    # Type your code here.
c++. 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: (s i − a) 2 where a is average of the four scores s 1 , s 2 , s 3 , and s 4 . The function will have six parameters and will call two other functions. Embed the function in a driver program that allows you to test the function again and again until you tell the program you are finished.
Write a function max_magnitude() with two integer input parameters that returns the largest magnitude value. Use the function in a program that takes two integer inputs, and outputs the largest magnitude value. Ex: If the inputs are: 5 7 the function returns: 7 Ex: If the inputs are: -8 -2 the function returns: -8 Note: The function does not just return the largest value, which for -8 -2 would be -2. Though not necessary, you may use the built-in absolute value function. Your program must define and call the following function:def max_magnitude(user_val1, user_val2)

Chapter 5 Solutions

EBK PROBLEM SOLVING WITH C++

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
functions in c programming | categories of function |; Author: Education 4U;https://www.youtube.com/watch?v=puIK6kHcuqA;License: Standard YouTube License, CC-BY