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

Write a C++ program, a function to find the max and min in an array. Description

ID: 3568920 • Letter: W

Question

Write a C++ program, a function to find the max and min in an array.

Description Write a function to find the max and min in an array. Use double as the base type of the array. The function will need 4 parameters: array, size. max, and min. This function does not need to return any value; max and min are changed inside the function, which must also change the original arguments. In addition, inside this function, before you search for the max and min, initialize max with DBL_MIN and min with DBL_MAX. DBL_MIN is the smallest value of a double; DBL_,MAX is the largest value of a double. You should do *include to use them. (You can see the actual value by placing the cursor in either DBL_MAX or DBL_M1Nand press Cirl+F12 in Visual Studio It will open the file where they are defined). Write a driver (main ( ) ) and test your function. The drive can only call the function using required arguments and print out the result. Declare an array in the driver with the following numbers (in order): 7.5. 4.3. 8.6. 4.8. 5.9. 7.9. 7.2. 7.1. 5.2. and 8.2. Requirement ? The programming style requirements are like previous labs and homework. ? Please reference to the file comment template (see lab 6 instructions) and the function comment template (see lab 9 instructions) for how to comment your source file. Output CMPSC 201-Lab1e [his is A driver to test a function that finds the max And min in an array. Max in the array is: 8.6 in in the Array is: 4.3

Explanation / Answer

Here you go :)

//Please change it according to the programming style you are following in the previous labs

#include <iostream>
#include<cfloat>

using namespace std;


void min_max(double arr[],int size,double *min,double *max)
{
double *a=min;
double *b=max;
*a=DBL_MAX;
*b=DBL_MIN;
for(int i=0;i<size;i++)
{
if(arr[i]<*a)*a=arr[i];
if(arr[i]>*b)*b=arr[i];
}
}

//driver
int main()
{
cout<<"This is a driver to test min and max in an array"<<endl;
double arr[]={7.5,4.3,8.6,4.8,5.9,7.9,7.2,7.1,5.2,8.2};
double min,max;
min_max(arr,10,&min,&max);

cout<< "Max in the array is: "<<max<<endl;
cout<< "Min in the arrays is: "<<min<<endl;
return 0;
}

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