Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

FIRST OF ALL PLEASE NOT ONLY GIVE ME THE ANSWER, PLEASE POR FAVOR EXPLAIN THE ST

ID: 3632860 • Letter: F

Question

FIRST OF ALL PLEASE NOT ONLY GIVE ME THE ANSWER, PLEASE POR FAVOR EXPLAIN THE STEPS

Write a function that copies a 1D array into a 2D array.

void copy1DTo2D(int a[], int size,

int b[][COLS], int n_rows, int n_cols,

int& not_copied_or_not_filled);



Write a function that searches a 2D array for a target.

void search(int a[][COLS], int n_rows, int n_cols,

int target, int& target_row, int& target_col);



Your copy functions must handle 1D arrays that have more or less elements than their 2D arrays.



Your search function must indicate that a search succeeded or failed.



Write a main program to test your functions.

Explanation / Answer

Dear.. #include <iostream> using namespace std; using namespace std; #define ROWS 3 #define COLS 3 void copy1DTo2D(int a[], int size, int b[][COLS], int n_rows, int n_cols, int& not_copied_or_not_filled) { int i = 0, j = 0; for( int k = 0; k < size; k++) { b[i][j] = a[k]; j++; if ( j >= n_cols ) { i++; j = 0; if ( i >= n_rows ) break; } } not_copied_or_not_filled = (n_rows * n_cols) - size; } void search(int a[][COLS], int n_rows, int n_cols, int target, int& target_row, int& target_col) { for(int i = 0; i < n_rows; i++) for(int j = 0; j < n_cols; j++) if(a[i][j] == target) { target_row = i; target_col = j; break; } } int main() { int a[5] = {10,20,30,40,50}; int size_1D = 5; int b[ROWS][COLS]; int not_copied; copy1DTo2D(a, size_1D, b, ROWS, COLS, not_copied); cout << " One dimensional array:" << endl; for(int k = 0; k < size_1D; k++) cout << a[k] << " "; cout <<endl; cout << " Two dimensional array: " << endl; cout << " Two dimensional array: " << endl; int i = 0, j = 0; int copied = ROWS * COLS - not_copied; for(int k =0; k < copied; k++) { cout << b[i][j] << " "; j++; if( j >= COLS) { j = 0; i++; cout << endl; } } cout << " copied cells: " << copied << endl; cout << "not copied cells: " << not_copied << endl; cout << "size of 2-D array: " << ROWS <<"*"<< COLS << endl; int target, target_col = -1, target_row = -1; cout << " Enter search element: "; cin >> target; search(b, ROWS, COLS, target, target_row, target_col); cout << " Target row: " << target_row << endl; cout << "Target column: " << target_col << endl; return 0; }

}