Please answer the question 5 in C++ with the reference of question 4. Thank you!
ID: 3745858 • 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.8089Explanation / Answer
The following c++ code -
#include <iostream>
int main ()
{
int values[80]; // Declares array and how many elements
int small, big; // Declares integer
big = small = values[0]; // Assigns element to be highest or lowest value
for (int i = 0; i < 80; i++) // Counts to 20 and prompts the user for a value and stores it
{
cout << "Enter value ";
cin >> values[i];
}
for (int i = 0; i < 80; i++) // Works out the biggest number
{
if(values[i] > big) // Compare biggest value with current element
{
big = values[i];
}
}
for (int i = 0; i < 80; i++) // Works out the smallest number
{
if (values[i] < small) // Compares smallest value with current element
{
small = values[i];
}
}
cout << "The maximum number is " << big << endl; // Prints outs the biggest number
cout << "The minimum number is " << small << endl; // Prints out the smallest number
}
Here in minmax.txt the maximum and minimum no will be printed.
Thank you....