Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter 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
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
Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions: - getScore– This function ask the user for a test score, store it in a reference parameter variable, and validate it. For input validation, do not accept test scores lower than 0 or higher than 100. This function should be called by main () once for each of the five scores to be entered. - calcAverage – This function calculates and display the average of the four highest score. This function should be called just once by main (), by should be passed the five scores. - findLowest – This function finds and returns the lowest of the five scores passed to it. It should be called by calcAverage function, which uses the function to determine which of the five scores to drop.
Write a function called cForce() that takes three numbers as parameters, and returns the centrifugal force. The formula for centrifugal force is:      F = mrw**2 F is force, r is radius, w is angular velocity.

Chapter 5 Solutions

Problem Solving with C++ (9th 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
functions in c programming | categories of function |; Author: Education 4U;https://www.youtube.com/watch?v=puIK6kHcuqA;License: Standard YouTube License, CC-BY