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

Write a program that reads an unspecified number (no more than 20) of positive i

ID: 3541410 • Letter: W

Question

Write a program that reads an unspecified number (no more than 20) of
    positive integers, finds, and prints the maximal and minimal values using an array.
    The input ends with the 0. For example, if you entered 1, 100, 20, 2, and 0,
    the program should print 100 and 1.

This exercise is for learning the array concept with a proper use of reference and value parameters.
*/

#include <iostream>
using namespace std;

//function prototype of a function returning max & min values of an integer array
//function prototype of getBoundary function // returning max, min values of an integer array

int main( )
{
    const int    CAPACITY = 20;    //array capacity
    int        value[CAPACITY];
    int        max, min;   // maximum and minimum values stored in the array value
    int        intNum;   //stores the number of integer read
    
    // read values from the input until it reads 0 and store the values in the array except 0
    // read values from the input until it reads 0 and store the values in the array except 0

    //call the function to get max and min value in the array value
    //call the function to get max and min value in the array value
    
    cout << intNum <<" integers have been read." << endl
         << "The maximal value is " << max << endl
         << "The minimal value is " << min << endl;

    return 0;
}

//Implementation of the void function getBoundary
// function returns max & min values of an integer array as reference parameter

void getBoundary (    )

  Write the function body of getBoundary
    

    

Explanation / Answer

please rate - thanks


any problems please be specific about what they are.

tested with DEV C++


#include <iostream>
using namespace std;

//function prototype of a function returning max & min values of an integer array
//function prototype of getBoundary function // returning max, min values of an integer array
void getBoundary(int [],int,int&,int& );
int main( )
{
const int CAPACITY = 20; //array capacity
int value[CAPACITY];
int max, min; // maximum and minimum values stored in the array value
int intNum; //stores the number of integer read

// read values from the input until it reads 0 and store the values in the array except 0
// read values from the input until it reads 0 and store the values in the array except 0
intNum=0;
cout<<"Enter value "<<intNum+1<<" (0 to exit): ";
cin>>value[intNum];
while(value[intNum]!=0)
{intNum++;
cout<<"Enter value "<<intNum+1<<" (0 to exit): ";
cin>>value[intNum];
}
//call the function to get max and min value in the array value
//call the function to get max and min value in the array value
getBoundary(value,intNum,max,min);
cout << intNum <<" integers have been read." << endl
<< "The maximal value is " << max << endl
<< "The minimal value is " << min << endl;
system("pause");
return 0;
}

//Implementation of the void function getBoundary
// function returns max & min values of an integer array as reference parameter

void getBoundary (int value[],int intNum,int& max, int& min )
{int i;
max=value[0];
min=value[0];
for(i=1;i<intNum;i++)
    {if(value[i]<min)
         min=value[i];
    if(value[i]>max)
        max=value[i];
        }
}

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