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
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
Change each one of these questions to now work using a function.  decide what the name of the function of each should be, how many parameters are required and what value needs to be returned. You’re no longer required to solve the problem - try to re-manage your code to be a function. Write a program that uses input to prompt a user for their name and then welcomes them. Enter your name: Chuck Hello Chuck
Modify the program so that it does the following: Performs a function that gets the area of a rectangle. The function must receive two parameters (decimal numbers) that represent the base and height of the rectangle and must return the calculated value (decimal number). Perform a second function that obtains the total area of a rectangular prism with a rectangular base. The total area of such a prism is equal to the sum of the areas of each of its faces. It uses calls to the previous function for this calculation. Call this last function in the main with user data. Execution example Give me the base: 21.3 Give me the height: 10 Give me the depth: 2.0 The total area of the prism is: 551.2
Design a function called intdiv() which takes a dividend and a divisor as parameters and returns the result and remainder (2 integers) as a tuple. E.G. given 9/2 equals 4 remainder 1:9 is the dividend, 2 is the divisor (parameters), 4 is the result and 1 is the remainder (values returned as a tuple).Write program statements which test this function by calling it twice with different parameters, and printing the returned values each time.

Chapter 5 Solutions

Problem Solving with C++ (10th Edition)

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