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

Please answer the question 5 in C++ with the reference of question 4. Thank you!

ID: 3747117 • Letter: P

Question

Please answer the question 5 in C++ with the reference of question 4. Thank you!

4. Complete the program minmax.cpp which uses two functions readdata and minmax to find the maximum and minimum of a set of floats stored in the file minmax.txt. You can assume that the number of values in the file is less than 100 signment # 1 This first number in this file is an int indicating the number of floats which follow. The function readdata opens the input file minmax.txt reads the first number, n, and then reads the following n floats into an array. The file is then closed by the function The function minmax computes the minimum and maximum values found in the array The main program prints the maximum and minimum. The content of the output file minmaxout.txt will be The array has 80 elements The maximum value in the array is 63.606 The minimum value in the array is 4.8089

Explanation / Answer

numbers.txt

721 37 620 577 598 291 125 631 76 639 677 423 321 877 266 796 670 613 436 233 83 316 647 786 844 163 835 64 921 425 419 648 67 48 936 595 236 254 447 211 943 877 256 95

_________________

#include <fstream>

#include <iostream>

#include <iomanip>

using namespace std;

// Function Declarations

void readdata(ifstream& dataIn,float *array,int &size);

void minmax(float *array,int size,float &min,float &max);

int main()

{

ofstream outfile;

int size;

float min,max;

  

// Creating an Integer array

float *array=new float[size];

  

// defines an input stream for the data file

ifstream dataIn;

readdata(dataIn,array,size);

  

minmax(array,size,min,max);

  

outfile.open("minmax.txt");

outfile << "The Lowest element in the array is :" << min<<endl;

outfile << "The Highest element in the array is :" << max<<endl;

outfile.close();

  

return 0;

}

void minmax(float *array,int size,float &min,float &max)

{

min = array[0];

max = array[0];

for (int m = 0; m < size; m++)

{

if (min > array[m])

min = array[m];

  

  

if (max< array[m])

max = array[m];

  

}

  

}

void readdata(ifstream& dataIn,float *array,int &size)

{

float num;

int i=0;

// Opening the input file

dataIn.open("numbers.txt");

/* Geting the data from the file and

* populate those values into an array

*/

while (dataIn >> num)

{

size++;

}

// Closing the intput file

dataIn.close();

// Opening the input file

dataIn.open("numbers.txt");

  

while (dataIn >> num)

{

array[i]=num;

i++;

}

  

}

_________________

minmax.txt

The Lowest element in the array is :37
The Highest element in the array is :943

______________