Program Description You will be working with 2D arrays in th

Program Description You will be working with 2-D arrays in this assignment. Firs create two integer arrays ofidentical size, 3 rows and 3 columns each, and the ask user to enter all values to both arrays. Complete the 6 functions provided below. Verify your program with my sample output. Function Header Description void getValues int dataArray [COL], int This function will ask user to enter values to one array. This row function should be called twice once for each array. the main function int, calculates um(int dataArray CITCOL int This function should calculate and return the sum of the row) array parameter. This function should be called twice once for each array- in the main function. There should not be any cout statement in this function void display values (int data iICOL This function will display values in the array parameter int row Each value should be displayed left justified and with column width of 5 void calculateSumofTwoArray(int This function should calculate the sum of dataArray1 and data rray1[][COL], int dataArray2 COL data Array2 and store the sum in array \"sumofArrays int COL], int row There should not be any cout statement in this function void displayspecialValues (int n main function, you should ask user to enter a number, data Array1[][COL int data Array2 COL that is between 0 and 2. This number will be used as either int row, int number) row or column. For example, if user has entered a hat means you will calculate the sum of row1 in dataArray1 and coll in dataArray2; 3 4 5 dataArray 6 7 8 9 0 1 And 1 2 3 dataArray 2 6 5 4 7 8 9 Entering a 1 means you are calculating Row1 of data Array1: [6 7 8] Coll of dataArray2: 5 Sum to be displayed: 8 12 16 void searchvalue (int dataArray COL int This function should ask user to enter a value to search for ROW, int & r int & C within the first matrix, he value is found, reference parameter r and c should be the correct row and column number. If not found, both r and c should be -1.The function should be called in the main function, if both rand c are -1, display a message \"not found\" in main function

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;
}

 Program Description You will be working with 2-D arrays in this assignment. Firs create two integer arrays ofidentical size, 3 rows and 3 columns each, and the
 Program Description You will be working with 2-D arrays in this assignment. Firs create two integer arrays ofidentical size, 3 rows and 3 columns each, and the
 Program Description You will be working with 2-D arrays in this assignment. Firs create two integer arrays ofidentical size, 3 rows and 3 columns each, and the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site