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

Goals: Practicing functions with reference parameters and arrays Take the code g

ID: 3681526 • Letter: G

Question

Goals: Practicing functions with reference parameters and arrays

Take the code given below and in main, modify the declaration so that the array can hold up to 1000 values.

Copy the data file Labs4-7S4.dat to the same folder as your source code file (do edit this file or change the filename of the file). Modify the function that reads data from a file so that it uses Labs4-7S4.dat file (you can either hard code the change or add code that allows the user to enter the filename).

Add a fourth function that is a void function which uses a single loop to determine the minimum and maximum value in the array (using the data file) and sends these two values back to the function call. Initially set both the maximum and minimum to the first element of the array, then write the loop to run from the second element to the last element.

Add code to main to call this fourth function and to output the minimum and maximum values. (Main should still output how many values were entered into the array as before).

Do not use the same identifiers in main and in your function. Also put your function definition after main.

Explanation / Answer

Program plan: Here,i am mentioning the code for fimding the minimum and maximum values in the given array.this function takes array as argument and print the maximum and minimum number in that array list elements.as mentioned in the question i am just copying the main and modify it as mentioned.

Program:

#include<iostream.h>

#include<conio.h>

void PrintArray(const double abc[], int size);
int ReadValues(double def[], int maxnumb);
int getValues(double xyz[], int howmany);

void printmaxandmin(double value[]);

int main()
{

//we can increase the array size 20 to 1000 by modifying the value as 1000
        double values[20];
        int numbentered;


//Add function call to get values
//      numbentered = getValues(values, 20); for interative input

        numbentered = ReadValues(values, 20);

        cout <<" "<< numbentered << " values were entered." << endl;
        PrintArray(values, numbentered);

cout<<"the maximum and minimum numbers entered for array are: "<<printmaxandmin(values);//calling the function


        return 0;
}

void printmaxandmin(double values[])

{

double max=value[0],min=value[0];

int i;

for(i=1;i<=20;++i)

{

if(value[i]>max)max=value[i];

if(value[i]<min)min=value[i];

}

cout<<"The maximum number in the array is: "<<max<<" The minimum number of the array is : "<<min;

}

note:we can read the data from the file and also add same logic to find out maximum and minimum number.

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