Question: Array Helper Functions Below is a list of functions, their parameters, and what they do void print2DArray(int** array, int rows, int cols) Takes in a

Array Helper Functions

Below is a list of functions, their parameters, and what they do

  • void print2DArray(int** array, int rows, int cols)
    • Takes in a 2D array and prints it
    • The array is unchanged
    • See sample run for formatting
  • int arraySum(int* array, int size)
    • Takes in a 1D array and returns the sum of all values
  • double arrayAvg(int* array, int size)
    • Takes in a 1D array and returns the average of all values
  • int arraySum2D(int** array, int rows, int cols)
    • Takes in a 2D array and returns the sum of all values
  • double arrayAvg2D(int** array, int rows, int cols)
    • Takes in a 2D array and returns the average of all values
  • int arrayMax2D(int** array, int rows, int cols)
    • Takes in a 2D array and returns the largest value in the entire array
  • int** arrayFromFile(std::string fileName, int& numRows, int& numCols)
    • Creates a 2D array based on the specifications in the file
    • Sets the ints passed by reference to the dimensions of the array
    • Returns a pointer to the 2D array
    • Assumes the following file format:
   

Example file for an array with 2 rows 3 columns:

2 3 9.5 4.4 10.0 7.5 2.6 7964.1 

Note:

int** arr could also be written as int* arr[], also int* arr could be written as int arr[]. There is a slight difference, but either are acceptable for this program.

  • int main()
    • Call your other function to handle as much of the work as possible! For example, use
    • After the array is filled, print the array
    • Uses the functions to print the sum and average of each row
    • Finally, print the largest, sum, and average of the entire array
    • There is ZERO user interaction; just print

Sample run

Assume data.txt contains the following:

3 4 1 3 5 7 9 2 4 6 8 0 3 2 

Now the program was invoked from terminal like this:

$>./lab07 data.txt 
Here is your array 1, 3, 5, 7 9, 2, 4, 6 8, 0, 3, 2 row 0 sum= 16, avg = 4.0 row 1 sum= 21, avg = 5.25 row 2 sum= 13, avg = 3.25 The largest value in the array is = 9 The sum for the entire array is = 50 The average for the entire array is = 4.166666666666667

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!