Program Description You will be working with 2D arrays in th
Solution
#include <iostream>
using namespace std;
const int COL = 3;
void getValues(int dataArray[][COL], int row);
int calculateSum(int dataArray[][COL], int row);
void displayValues(int dataArray[][COL], int row);
void CalculateSumOfTwoArray(int dataArray1[][COL], int dataArray2[][COL], int sumOfArrays[][COL], int row);
void displaySpecialValues(int dataArray1[][COL], int dataArray2[][COL], int row, int number);
void searchValue(int dataArray[][COL], int ROW, int *r, int *c);
int main()
{
int arr1[3][COL];
int arr2[3][COL];
cout << \"Please enter values for the first array: \"<< endl;
getValues(arr1, 3);
cout << \"Please enter values for the second array: \"<< endl;
getValues(arr2, 3);
cout << \"========================================\";
cout << \"The first array:\" << endl;
displayValues(arr1, 3);
cout << \"Sum of all values in the first array: \" << calculateSum(arr1,3) << endl;
cout << \"The second array:\" << endl;
displayValues(arr2, 3);
cout << \"Sum of all values in the second array: \" << calculateSum(arr2,3) << endl;
int sumarray[3][COL];
CalculateSumOfTwoArray(arr1, arr2, sumarray, 3);
cout << \"Sum of the two arrays\ \";
displayValues(sumarray, 3);
int n;
while(1)
{
cout << \"Please enter a row/col number and I will make a calculation\ \";
cin >> n;
if (n > 2 || n < 0)
{
cout << \"!!!ERROR!!! The row/col number must be between 0 and 2\";
}
else
{
break;
}
}
displaySpecialValues(arr1, arr2, 3, n);
int r = 0;
int c = 0;
searchValue(arr1, 3, &r, &c);
if ((r == -1) || (c == -1))
{
cout << \"not found\ \";
}
else
{
cout << \"The value was found on row \" << r << \" col \" << c<<endl;
}
}
void getValues(int dataArray[][COL], int row)
{ //This function will ask the user to enter values to one array. This function should be called twice in the main function, once for each array.
for(int i = 0; i < row; i++)
{
for(int j = 0; j < COL; j++)
{
cin >> dataArray[i][j];
}
}
}
int calculateSum(int dataArray[][COL], int row)
{ //This function should calculate and return the sum of the array parameter. This function should be called twice as well in the main fucntion, once for each array. There should not be any cout statement in this function
int sum = 0;
for(int i = 0; i < row; i++)
{
for(int j = 0; j < COL; j++)
{
sum += dataArray[i][j];
}
}
return sum;
}
void displayValues(int dataArray[][COL], int row)
{ //This function will display values in the array parameter. Each value should be displayed left justified and with column width of 5.
for(int i = 0; i < row; i++)
{
for(int j = 0; j < COL; j++)
{
cout << dataArray[i][j] << \" \";
}
cout << endl;
}
}
void CalculateSumOfTwoArray(int dataArray1[][COL], int dataArray2[][COL], int sumOfArrays[][COL], int row)
{ // This function should calculate the sum of dataArray1 and dataArray2 and store the sum in array sumOfArrays. There should not be any cout statement in this function.
for(int i = 0; i < row; i++)
{
for(int j = 0; j < COL; j++)
{
sumOfArrays[i][j] = dataArray1[i][j] + dataArray2[i][j];
}
}
}
void displaySpecialValues(int dataArray1[][COL], int dataArray2[][COL], int row, int number)
{
for(int i = 0; i < row; i++)
{
cout << dataArray1[number][i] + dataArray2[i][number] << \" \";
}
cout << endl;
}
void searchValue(int dataArray[ ][COL], int ROW, int *r, int *c)
{
int n;
cout << \"Please enter a value and I will search for it in the first array: \";
cin >> n;
for(int i = 0; i < ROW; i++)
{
for(int j = 0; j < COL; j++)
{
if (dataArray[i][j] == n)
{
*r = i;
*c = j;
return;
}
}
}
*r = -1;
*c = -1;
}


