Question: Please need help in C++ Finish implementation of the rotate2DArray() prototype provided so that it alters the 8x8 integer 2D array passed to it (shown
Please need help in C++
Finish implementation of the rotate2DArray() prototype provided so that it alters the 8x8 integer 2D array passed to it (shown below). In your rotate2DArray() function, rotate the values of the 2D array argument by 90 degrees clockwise, and store them back in the same argument passed to the function.
"You may NOT use any library functions ". Rotation of your array should be done on a cell-by-cell basis.
BEFORE Rotation:
0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37 40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57 60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77
You should have this Output AFTER Rotation: 70 60 50 40 30 20 10 0 71 61 51 41 31 21 11 1 72 62 52 42 32 22 12 2 73 63 53 43 33 23 13 3 74 64 54 44 34 24 14 4 75 65 55 45 35 25 15 5 76 66 56 46 36 26 16 6 77 67 57 47 37 27 17 7
#include
using namespace std;
void rotate2DArray( int arr[][8] ); // provided - do not change
int main() {
int arr[8][8] = { // declare the array { 0, 1, 2, 3, 4, 5, 6, 7 }, // row 0 { 10, 11, 12, 13, 14, 15, 16, 17 }, // row 1 { 20, 21, 22, 23, 24, 25, 26, 27 }, { 30, 31, 32, 33, 34, 35, 36, 37 }, { 40, 41, 42, 43, 44, 45, 46, 47 }, { 50, 51, 52, 53, 54, 55, 56, 57 }, { 60, 61, 62, 63, 64, 65, 66, 67 }, { 70, 71, 72, 73, 74, 75, 76, 77 }, // row 7 };
rotate2DArray( arr ); // rotate the array passed to the function by 90 degrees
for( int r=0; r<8; r++) { // print the 2D array after rotation for( int c=0; c<8; c++ ){ cout << arr[r][c] << " "; } cout << endl; // terminate each row so we can start a new output line }
}
void rotate2DArray( int arr[][8]) { // TODO: your implementation goes here }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
