Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE USE C++ AND MAKE SURE THE PROGRAM DOES EXACTLY WHAT IS ASKED IN THE QUEST

ID: 3888285 • Letter: P

Question

PLEASE USE C++ AND MAKE SURE THE PROGRAM DOES EXACTLY WHAT IS ASKED IN THE QUESTION. THANKS

Write a function, array_stats, that finds both the maximum and minimum of an array of values. Because a c+ function cannot return more than one value, create a function that takes three arguments of type vector, double, and double. The second two argument should be passed by reference and used to return the max and min of the array. The function should be of type void so that it does not return a value. Write a short program that generates an array to test your function.

Explanation / Answer

#include <iostream>

#include <vector>

using namespace std;

void array_stats(vector<double>& array,double& min,double& max){

  

//print the array.............

cout <<"array is:-"<<endl;

for (int i=0; i<array.size();i++){

cout << array[i] << endl;

}

  

//find max in array...

max = array[0]; // start with max = first element

for(int i = 1; i<array.size(); i++)

{

if(array[i] > max)

max = array[i];

}

//find min in array...

min = array[0]; // start with min = first element

for(int i = 1; i<array.size(); i++)

{

if(array[i] < min)

min = array[i];

}

}

int main() {

double min,max;

//create an array here.........

static const int arr[] = {16,2,77,29,78,45,1};

vector<double> array(arr, arr + sizeof(arr) / sizeof(arr[0]) );

//call the function to find min and max in array

  

array_stats(array,min,max);

  

//print min and max values

  

cout<<"maximum value="<<max<<endl;

cout<<"minimum value="<<min;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote