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

*please do only exercise 9, exercises 7&8 are forreference, thank you! Exercise

ID: 3614962 • Letter: #

Question

*please do only exercise 9, exercises 7&8 are forreference, thank you!

Exercise 9:
Write an int-returning function that prompts theuser for the number of values to be entered, creates anint array of that size, and reads that many valuesinto it. The function then passes this array to theGreatest function defined in Exercise 8, andreturns the result from that function as its own result. Callthe new function GetGreatestInput.

Exercise 8:
Wrap the For loop written in Exercise 7 an int-returning functioncalled Greatest that takes the array and its sizeas parameters and returns the value in max afterthe array is deleted. Be sure to change the loop to work with thegiven array size rather than the constant 100.

Exercise 7:
Write a For loop that scans through a dynamically allocated intarray, pointed to by a variabled called dataPtr,keeping track of the greatest value in a staticint variable max. The arraycontains 100 values. At the end of the loop, the array should bedeleted.

Explanation / Answer

#include <iostream>
#include <cstdlib>

using namespace std;
int Greatest(int *dataPtr,int size)
{
    int i;
    static int max;
    max = dataPtr[0];
    for(i=0;i<size;i++)
     if(max < dataPtr[i])
      max = dataPtr[i];
return max;
}

int GetGreatestInput()
{
    int n,i;
    int *arr,max;
    cout<<"Enter the size:";
    cin>>n;
    arr = new int[n];
    for(i=0;i<n;i++)
     {
     cout<<"Enter the input of"<<(i+1)<<" number :";
     cin>>arr[i];
     }
     max = Greatest(arr,n);
          delete[]arr;     
          returnmax;
}
int main(){

cout<<"Max value in array is:"<<GetGreatestInput()<<endl;
      
      
system("pause");
    return 0;
}