Question
Asked Sep 18, 2019

In C++

Create a function that takes in an array and outputs the min, max and average of the array to a file.

check_circleExpert Solution
Step 1

A function is to be created in C++ that will take in an array and will results with minimum, maximum and average values. The program is given below:

Step 2

#include <iostream>

using  namespace std;

void minMaxAvg(double array[], int size,double& min, double& max, double& avg)

{

    if (size <= 0)   // to return error code if size <= 0

        return;

    min = array[0];

    max = array[0];

    avg = 0;

    int i;

    int sum = 0;

    for (i=0; i < size; i++)

    {

        sum += array[i];

        if ( array[i] > max) // data access by array[i]

        {

            max=array[i]; //value is assigning to max

        }

        if (array[i] < min) {

            min=array[i];

        }

    }

    avg = sum/size;

}

int main()

{

    double array[]={10.0,20.0,30.0,40.0};

    double min = 0, max = 0, avg = 0; //variables are defined and initialized     

    minMaxAvg(array, sizeof(array)/sizeof(array[0]), min, max, avg); // function calling

    std::cout << min << ", " << max << ", " << avg << std::endl;

    return 0;

}

Step 3

In the above program, a function is created named as minMaxAvg that will take the required parameters. The values for min, max and avg are initialized to 0. The ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour*

See Solution
*Response times may vary by subject and question
Tagged in

Engineering

Computer Science

Object Oriented Programming

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Construct an unambiguous grammar equivalent to the grammar in  S→AB|aaaB, A→a|Aa, B→b.

A: Solution: Construct an unambiguous grammar to grammar.Given that,S -&gt; AB|aaaBA -&gt; a|AaB -&gt; ...

question_answer

Q: please help me solve this problem  the language is C++

A: Program Instructions:Ask the user the name of each friend one by one.Calculate the 20% tip, total bi...

question_answer

Q: Which command can you use to determine who is logged in on a specific terminal?

A: Different commands are used to determine who is logged in on a specific terminal. These commands are...

question_answer

Q: **accounting information system**1. HTML and XML- how are they similar? how are these different? XML...

A: We will answer the first question since the exact one is not specified. Please submit a new question...

question_answer

Q: Use the worksheets to show, one path augmentation at a time, how to use the Ford-Fulkerson Algorithm...

A: For solving your problem first of all we define Ford-Fulkerson Algorithm.Ford-Fulkerson Algorithm fo...

question_answer

Q: Construct an npda corresponding to the grammar S→aABB|aAA,A→aBB|b,B→bBB|A.

A: Firstly, we will convert the given grammar into GNFS → aABB|aAAA → aBB|bB → bBB|aBB|a

question_answer

Q: Write a program which does the following (name=xxx_and_xxx_lab2):1) Create a 2 dim array containing ...

A: Description:The following program is to print the two dimensional array with the given information i...

question_answer

Q: Write a program called StudentTable that prints the below table. Use only print() orprintf(). DO NOT...

A: Using the given hint "printf" the below program was done in C language where "println()" is used in ...

question_answer

Q: I have a Python question and I cannot seem to figure out how to answer this problem exactly (I've at...

A: Hey..To print the power of 2 you have to use a  power function  "pow(2,N) " .It is inbuild function ...