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

Create the functions findMaxIndex and findMaxIndex for the C++ program given bel

ID: 3623745 • Letter: C

Question

Create the functions findMaxIndex and findMaxIndex for the C++ program given below. The functions must return the index of the maximum value and index of the minimum value. Please add comments for important steps. Any help would be appreciated.

#include
#include
#include

using namespace std;

//-------------------------------------------------------------------
//
// sequentialSearch()
//
// Given an array of integers, the length of the array and a value to
// search for, return the index of the value if found, else return -1.
//
//--------------------------------------------------------------------

int sequentialSearch(int array[], int arrayLength, int searchValue)
{
for(int i = 0; i < arrayLength; i++) if(array[i] == searchValue)return(i);

return(-1); // searchValue was not found.
}

//-------------------------------------------------------------------
//
// findMax()
//
// Given an array of integers and the length of the array, find and
// return the maximum value in the array.
//
//--------------------------------------------------------------------

int findMax(int array[], int arrayLength)
{
int maxValue = array[0];

for(int i = 1; i < arrayLength; i++)
if(array[i] > maxValue) maxValue = array[i];

return(maxValue);
}

//-------------------------------------------------------------------
//
// findMin()
//
// Given an array of integers and the length of the array, find and
// return the minimum value in the array.
//
//--------------------------------------------------------------------

int findMin(int array[], int arrayLength)
{
int minValue = array[0];

for(int i = 1; i < arrayLength; i++)
{
if(array[i] < minValue)
{
minValue = array[i];
}
}

return(minValue);
}

//----------------------------------------------------------------------

int main()
{
const int arraySize = 1000;
int array[arraySize];

//------------------------------------------

srand ( time(NULL) );

for(int i = 0; i < arraySize; i++) array[i] = rand();

//------------------------------------------

cout << " The maximum value is ";
cout << findMax(array, arraySize);
cout << ". ";

//------------------------------------------

// Write me.

cout << " The index of the maximum value ";
cout << findMaxIndex(array, arraySize);
cout << ". ";

//------------------------------------------

cout << " The minimum value is ";
cout << findMin(array, arraySize);
cout << ". ";

//------------------------------------------

// Write me too.

cout << " The index of the minimum value ";
cout << findMinIndex(array, arraySize);
cout << ". ";

//------------------------------------------

int maxValue = findMax(array, arraySize);

cout << " The location of the maximum value " << maxValue << " is index ";
cout << sequentialSearch(array, arraySize, findMax(array, arraySize));
cout << ". ";
}

Explanation / Answer

#include using namespace std; //------------------------------------------------------------------- // // sequentialSearch() // // Given an array of integers, the length of the array and a value to // search for, return the index of the value if found, else return -1. // //-------------------------------------------------------------------- int sequentialSearch(int array[], int arrayLength, int searchValue) { for(int i = 0; i