Question #309064

Write a program in C++ that defines an m x n two dimensional array containing integer elements, where m and n represent the numbers of rows and columns respectively. The numbers of rows and columns should be defined as constants. The program should provide the following user-defined functions with appropriate parameters:

  • setArrData(...): The function accepts elements from the keyboard and stores them into the array.
  • printArrData(...): The function prints the array values on the screen.
  • getAverage(...): The function accepts the array, number of rows and number of columns as parameters and returns the average of all values in the array.
  • findMax(...): The function accepts the array, number of rows and number of columns as parameters and prints the greatest element from each column of the array. 

Expert's answer

Here is my program:

void setArrData(int a[5][5], const int m, const int n)
{
	cout << "Enter element array: " << endl;
	for (int i = 0; i < m; i++)
	{


		for (int j = 0; j < n; j++)
		{
			cin >> a[i][j];
		}
		
	}
}
void printArr(int arr[5][5], const int m, const int n)
{
	for (int i = 0; i < m; i++)
	{
		
		for (int j = 0; j < n; j++)
		{
			cout << arr[0][j] << " ";
		}
		cout << arr[i][0] << endl;
	}
}
void getAverage(int arr[5][5], const int m, const int n)
{
	int average;
	int r;
	for (int i = 0; i < m; i++)
	{


		for (int j = 0; j < n; j++)
		{
			average += arr[0][j];
			r++;
		}
		average += arr[i][0];
		r++;
	}
	average = average / r;
	cout << "Array average: " << average << endl;
}
void findMax(int arr[5][5] ,const int m , const int n)
{
	for (int i = 0; i < m; i++)
	{


		int max = arr[0][0];


		for (int j = 0; j < n; j++)
		{
			if ((arr[0][0] > arr[j + 1][i]) && (arr[j][i] > max))
			{
				max = arr[j][i];
			}
		}


		cout << "In " << i + 1 << " columns greatest element - " << max << endl;
	}
}
int main()
{
	const int m = 5;
	const int n = 5;
	int arr[m][n]{};

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS