Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
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

Problem Solving with C++ (10th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
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
  • Write a program that takes as input five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x1,x2,x3,x4,andx5, then the mean is x=(x1+x2+x3+x4+x5)/5 and the standard deviation is: s=(x1x)2+(x2x)2+(x3x)2+(x4x2)+(x5x2)5 Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation.
    Write a function max_magnitude() with three integer parameters that returns the largest magnitude value. Use the function in the main program that takes three integer inputs and outputs the largest magnitude value. Ex: If the inputs are: 5 7 9 function max_magnitude() returns and the main program outputs: 9 Ex: If the inputs are: -17 -8 -2 function max_magnitude() returns and the main program outputs: -17 Note: The function does not just return the largest value, which for -17 -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 -17, not 17). Your program must define and call the following function:def max_magnitude(user_val1, user_val2, user_val3)
    Write a program that asks the user to input a grade that he or she received on an exam. The grade is an integer between 0 and 100 inclusive. The program should convert the numeric grade into the equivalent letter grade. Do the conversion by using a function Letter_Grade () that converts a numeric grade in the range 0 to 100 to the equivalent letter grade. The function should have one argument, the integer grade. The return value of the function should be A if the grade is 90 to 100; B if the grade is 80 to 89; C if the grade is 70 to 79; D if the grade is 65 to 69; and F if the grade is 64 or lower. After converting the grade, the program should display the nu¬meric grade and the equivalent letter grade.
  • Write a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Ex: If the input is: 0 or less, the output is: no change Ex: If the input is: 45 the output is: 1 quarter 2 dimes Your program must define and call the following function. The function exact_change() should return num_dollars, num_quarters, num_dimes, num_nickels, and num_pennies.def exact_change(user_total)     python please use this in answer  # Define your function here  if __name__ == '__main__':     input_val = int(input())        num_dollars, num_quarters, num_dimes, num_nickels, num_pennies = exact_change(input_val)     # Type your code here.
    Write a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Ex: If the input is: 0 or less, the output is: no change Ex: If the input is: 45 the output is: 1 quarter 2 dimes Your program must define and call the following function. The function exact_change() should return num_dollars, num_quarters, num_dimes, num_nickels, and num_pennies.def exact_change(user_total) # Define your function here  if __name__ == '__main__':     input_val = int(input())        num_dollars, num_quarters, num_dimes, num_nickels, num_pennies = exact_change(input_val)     # Type your code here.   python
    Write a program that takes as input five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x1, x2, x3, x4, and x5, then the mean is x = (x1 + x2 + x3 + x4 + x5)/5 and the standard deviation is: Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation. ____________________________
  • Engineers often measure the ratio of two power measurements in decibels, or dB, which can be calculated as follows:dB= log10P2/P1Where P2 is the power level being measured, and P1 is some reference power level. Write a function that calculates the level. The function’s prototype is as follows:double dBCalculator (double P1, double P2);Then, call dBCalculator from the main function to find the power ratio for the measurements from 1 to 20 Watts, in 2 Watt steps. You can assume that the reference power P1 is 1 Watt.
    Write a function MaxMagnitude() 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 absolute-value built-in math function. #include <iostream>using namespace std; void MaxMagnitude(int userVal1, int userVal2) {if (abs(userVal1) > abs(userVal2)) {return userVal1;}else if (abs(userVal2) > abs(userVal1)) {return userVal2;}}/* Define your function here */ int main() { int userVal1;int userVal2;cin >> userVal1 >> userVal2;/* Type your code here. Your code must call the function. */ cout << MaxMagnitude(userVal1, userVal2) << endl;/* Type your code here */ return 0;} Please help me with this problem using…
    Write a program that reads the values for the width, length, and height of a rectangular box using three variables of double type in the function main(). Pass values of these variables to a function, which calculates the volume and surface area for six sides of the box. The volume and surface area of the box passed back from two other arguments of this function are printed out in the function main(). Check your program with the user input for the width, length, and height of 2, 3, 4 meters, respectively. please kindly use pointers and write this program in C langauge.
    • SEE MORE QUESTIONS
    Recommended textbooks for you
  • C++ Programming: From Problem Analysis to Program...
    Computer Science
    ISBN:9781337102087
    Author:D. S. Malik
    Publisher:Cengage Learning
    C++ for Engineers and Scientists
    Computer Science
    ISBN:9781133187844
    Author:Bronson, Gary J.
    Publisher:Course Technology Ptr
  • C++ Programming: From Problem Analysis to Program...
    Computer Science
    ISBN:9781337102087
    Author:D. S. Malik
    Publisher:Cengage Learning
    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