Question
Program Template: /** * Chapter 7, Programming Challenge 19: 2D Array Operations * Gaddis' text: pages 454 */ // Place your name here #include using
Program Template:
/** * Chapter 7, Programming Challenge 19: 2D Array Operations * Gaddis' text: pages 454 */
// Place your name here
#include
// Constants for the array sizes const int ROWS = 4; const int COLS = 5;
// Function prototypes int getTotal(int[][COLS], int, int); double getAverage(int[][COLS], int, int); int getRowTotal(int[][COLS], int, int); int getColumnTotal(int[][COLS], int, int); int getHighestInRow(int[][COLS], int, int); int getLowestInRow(int[][COLS], int, int);
int main() { // Array with test data int testArray[ROWS][COLS] = { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 }, { 11, 12, 13, 14, 15 }, { 16, 17, 18, 19, 20 } };
// TODO: Display the total of the array elements. // TODO: Display the average of the array elements. // TODO: Display the total of row 0 to row 3 (4 rows in total). // TODO: Display the total of column 0 to column 5 (each row has 5 columns). // TODO: Display the highest value in each row. // TODO: Display the lowest value in each row. return 0; }
// ******************************************************** // The getTotal function returns the total of all * // the elements in the array. * // ******************************************************** int getTotal(int array[][COLS], int rows, int cols) { int total = 0;
// TODO
return total; }
// ******************************************************** // The getAverage function returns the averave value * // of the elements in the array. * // ******************************************************** double getAverage(int array[][COLS], int rows, int cols) { // Calculate the number of elements in the array. // Use a double so we can avoid integer division // later. double numElements = rows * cols;
// TODO: Get the average of the elements. double average;
// Return the average. return average; }
// ******************************************************** // The getRowTotal function returns the total of the * // the elements in the specified row of the array. * // ******************************************************** int getRowTotal(int array[][COLS], int rowToTotal, int cols) { int total = 0;
// TODO
return total; }
// ******************************************************** // The getColTotal function returns the total of the * // the elements in the specified column of the array. * // ******************************************************** int getColumnTotal(int array[][COLS], int colToTotal, int rows) { int total = 0;
// TODO
return total; }
// ******************************************************** // The getHighestInRow function returns the highest * // value in the specified row. * // ******************************************************** int getHighestInRow(int array[][COLS], int rowToSearch, int cols) { int highest = array[rowToSearch][0];
// TODO
return highest; }
// ******************************************************** // The getLowestInRow function returns the lowest * // value in the specified row. * // ******************************************************** int getLowestInRow(int array[][COLS], int rowToSearch, int cols) { int lowest = array[rowToSearch][0];
// TODO
return lowest; }
it has to be in C++
19, 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any data type you wish. The program should have the following functions: r getTotal. total function should accept array array as its argument and a two-dimensional of all the values in the This return the get Average. This function should accept a two-dimensional array as its argument and return the average of all the values in the array getRowTotal. This function should accept a two-dimensional array as its first argu- ment and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the total of the values in the specified row. get column Total. This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The function should return the total of the values in the specified column. getHighestInRow. This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the highest value in the specified row of the array. getLowestInRow. This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the lowest value in the specified row of the array. Demonstrate each of the functions in this programStep 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