Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started