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

Write the program in C++ only Please read the question carefully and answer corr

ID: 3822080 • Letter: W

Question

Write the program in C++ only

Please read the question carefully and answer correctly

***THIS PROBLEM REQUIRES YOU TO CREATE MULTIPLE FUNCTIONS.

READ THIS ENTIRE PROBLEM BEFORE YOU BEGIN!!!

- NOTE this problem DOES NOT use TWO-DIMENSIONAL arrays!

Write a program that uses functions to do the following array manipulations. Your program will

create a one dimensional array and store random numbers in the array. You will also create a

second array that has the same numbers in the reverse order. Main should only consist of

variable declarations, function calls, and print statements. An outline of main is as follows (you

MUST include these comments!):

//declare a constant for size of array

const int maxnums = 30;

//declare two 1-dimensional arrays the size of maxnums

//and any other variables needed

//call initArray to store numbers in array

//call printArray to print with 5 numbers per row

//call findMax to determine max

//call findMin to determine min

//call findAvg to determine average

//print minimum, maximum, average

//call reverseArray to store numbers in second array in reverse

order

//call printArray to print the reversed array with 7 numbers per

row

Create the following functions that receive and process arrays. FOLLOW THE SPECS

BELOW FOR EACH FUNCTION – make sure you are CLEAR on the “inputs” and

“outputs”. There are many similarities in these functions so write and test ONE FUNCTION

at a time!) . Start with just initArray and printArray, and build from there).

initArray          Receives an array and the size of the array as parameters. Has no return. Stores random numbers in the range of 1 to 999 in the array.

printArray        Receives an array, the size of the array, and the number of values to print on each row as parameters. Print the values in the array with the specified number of values (columns) per row. (Hint: use a counter to keep track of how many values have been printed and determine when to move to the next line. You could also use the mod operator. DO NOT use nested loops! WORK OUTTHE ALGORITHM BEFORE YOU CODE IT.)

findMax           Receives an array and the size of the array as parameters. Determine the maximum value of the array and return that value.

findMin           Receives an array and the size of the array as parameters. Determine the minimum value of the array and return that value.

findAvg            Receives an array and the size of the array as parameter. Determine the average of the numbers and return that value.

reverseArray Receives two arrays, and the size of the array as parameters. Copy one array to another in reverse order. Note that it actually stores the values in the second array.

This function DOES NOT PRINT THE VALUES. FOLLOW THE OUTLINE

FOR MAIN.

Sample output: (Note your numbers will be different due to the random number generator.

The numbers are:

176     941     752     344     73

543     582     644     330     357

560     25        13       482     336

607     456      756     416     347

911     439      912     714     242

601     985     396     649     303

The largest number is 985

The smallest number is 13

The average is 496.4

The reversed numbers are:

303     649     396     985     601     242     714

912     439     911     347     416     756     456

607     336     482     13       25       560     357

330     644     582     543     73       344     752

941     176

Explanation / Answer

#include<iostream>

using namespace std;

void intArray(int array[],int size){
   srand (time(NULL));
   for(int i=0;i<size;i++)
       array[i]=rand()%999+1;
}

void printArray(int array[],int size, int no_of_rows){
   for(int i=0;i<size;i++){
       cout<<setw(4)<<array[i];
       if (i%(no_of_rows-1)==0) cout<<endl;
   }
}

int findMax(int inputArray[],int size){
int maxValue = inputArray[0];
for(int i=1;i < size;i++){
if(inputArray[i] > maxValue){
maxValue = inputArray[i];
}
}
return maxValue;
}

// Method for getting the minimum value
int findMin(int inputArray[],int size){
int minValue = inputArray[0];
for(int i=1;i<size;i++){
if(inputArray[i] < minValue){
minValue = inputArray[i];
}
}
return minValue;
}

// Method for getting the average value
float findAvg(int inputArray[],int size){
float avgValue = inputArray[0];
for(int i=1;i<size;i++)
       avgValue += inputArray[i];
return avgValue/size;
}

// Method for reverse
void reverseArray(int inputArray[],input revArray[], int size){
for(int i=0;i<size;i++)
       revArray[i]=inputArray[size-i-1];
}

void main(){
//declare a constant for size of array
const int maxnums = 30;
//declare two 1-dimensional arrays the size of maxnums
//and any other variables needed
int max,min,array[maxnums],rArray[maxnums];
float avg;

//call initArray to store numbers in array
initArray(array,maxnums);

//call printArray to print with 5 numbers per row
printArray(array,maxnums,5);

//call findMax to determine max
max=findMax(array,maxnums);

//call findMin to determine min
min=findMin(array,maxnums);

//call findAvg to determine average
avg=findAvg(array,maxnums);

//print minimum, maximum, average
cout<<"The largest number is "<<max;
cout<<"The smallest number is "<<min;
cout<<"The average is "<<avg;

//call reverseArray to store numbers in second array in reverse order
reverseArray(array,rArray,maxnums);

//call printArray to print the reversed array with 7 numbers per row
printArray(revArray,7);

}

//Online url for testing :http://ideone.com/2BVsP0