The purpose of this problem is to write some small functions and practice passing things around amoung functions. 1) The main function shall ask the user to enter three numbers and read the three numbers. 2) Write a function named findSum that takes three numbers as arguments and returns their sum. The main function shall call this function. 3) Write a function named findAverage that takes the sum and the number of numbers and returns the average. The main function shall call this function. 4) Write a function named findSmallest that takes the three numbers and returns the smallest value. The main function shall call this function. 5) The main function shall print the results in the following format, with two decimal positions and the decimal points aligned: Results: First number 17.23 Second number 3.98 Third number 22.32 Total 43.53 Average 14.51 Smallest 3.98 Test the program twice with the following two sets of numbers: 37.144 2.4144 19 4.23 5.78 6.21

Respuesta :

Limosa

Answer:

Following are the program in the C++ Programming Language.

#include<iostream> //header file

#include<iomanip>  //header file

using namespace std;//using namespace

//set method for sum

double findSum(double x, double y, double z)

{

double s = x+y+z;

return s;

}

//set method for Average

double findAverage(double s, int a)

{

double avg = s/a;

return avg;

}

//set method for smallest number

double findSmallest(double x, double y, double z)

{

double mn;

if(x<y && x<z)

mn = x;

else if(y<x && y<z)

mn = y;

else if(z<x && z<y)

mn = z;

return mn;

}

//set the main function

int main()

{

cout<<fixed<<setprecision(2)<<endl;

//set double type variables

double xx, yy, zz, t, avg, mn;

//get input from the user

cout<<"Enter first value: ";

cin>>xx;

cout<<"Enter second value: ";

cin>>yy;

cout<<"Enter third value: ";

cin>>zz;

//calling of functions and store their values

t = findSum(xx, yy, zz);

avg = findAverage(t, 3);

mn = findSmallest(xx, yy, zz);

//print the output

cout<<"\n";

cout<<"Results: "<<endl;

cout<<"First number "<<xx<<endl;

cout<<"Second number "<<yy<<endl;

cout<<"Third number "<<zz<<endl;

cout<<"Total        "<<t<<endl;

cout<<"Average      "<<avg<<endl;

cout<<"Smallest     "<<mn<<endl;

return 0;

}

Output:

Enter first value: 17.23

Enter second value: 3.98

Enter third value: 22.32

Results:

First number 17.23

Second number 3.98

Third number 22.32

Total        43.53

Average      14.51

Smallest     3.98

Explanation:

Here, we define the double data type function " findSum()" in which we pass three double type arguments "x", "y", "z" in its parentheses.

  • inside it, we set the double type variable 's' in which we store the sum of variable x, y, z and return the variable s.

Then, we define the function "findAverage()" in which we pass two arguments double type s and integer type a.

  • inside it, we set the double type variable avg in which web store the divide of s and a then return avg

Then we set the function "findSmallest()" in which we pass three double type arguments "x", "y", "z" in its parentheses.

  • inside it, we set the double type variable "mn" which store the value of the smallest number among them.

Finally, we define the main function in which se call and pass the function and the value in its parameter then, we print the result.

ACCESS MORE
EDU ACCESS