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

Question

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;

max = array;

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

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

### Object Oriented Programming 