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
15 points Save ARS Consider the following scenario in which host 10.0.0.1 is communicating with an external SMTP mail server at IP address 128.119.40.186. NAT translation table WAN side addr LAN side addr (c), 5051 (d), 3031 S: (e),5051 SMTP B D (f.(g) 10.0.0.4 server 138.76.29.7 128.119.40.186 (a) is the source IP address at A, and its value. S: (a),3031 D: (b), 25 10.0.0.1 A 10.0.0.2. 1. 138.76.29.7 10.0.0.3
6.3A-3. Multiple Access protocols (3). Consider the figure below, which shows the arrival of 6 messages for transmission at different multiple access wireless nodes at times t=0.1, 1.4, 1.8, 3.2, 3.3, 4.1. Each transmission requires exactly one time unit. 1 t=0.0 2 3 45 t=1.0 t-2.0 t-3.0 6 t=4.0 t-5.0 For the CSMA protocol (without collision detection), indicate which packets are successfully transmitted. You should assume that it takes .2 time units for a signal to propagate from one node to each of the other nodes. You can assume that if a packet experiences a collision or senses the channel busy, then that node will not attempt a retransmission of that packet until sometime after t=5. Hint: consider propagation times carefully here. (Note: You can find more examples of problems similar to this here B.] ☐ U ப 5 - 3 1 4 6 2
Just wanted to know, if you had a scene graph, how do you get multiple components from a specific scene node within a scene graph? Like if I wanted to get a component from wheel from the scene graph, does that require traversing still?   Like if a physics component requires a transform component and these two component are part of the same scene node. How does the physics component knows how to get the scene object's transform it is attached to, this being in a scene graph?

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