INSTRUCTIONS: Work individually and submit to the Blackboard by the deadline. You are encouraged to start early.
//Define a named constant #define SIZE 16 //Function pre-declarations void printPattern(char p[][SIZE]); void flipPattern(char p[][SIZE]); int main() { //Two-Dimensional arrays to hold patterns char triangle[SIZE][SIZE]; char flag[SIZE][SIZE]; //Create a pattern of triangle and store it into the 2D array variable triangle // ... //Create a pattern of flag and store it into the 2D array variable flag // ... //Print patterns printPattern(triangle); printPattern(flag); //Flip patterns flipPattern(triangle); flipPattern(flag); cout <<"\nAfter flipping ..." << endl; //Print patterns after flipping printPattern(triangle); printPattern(flag); return 0; } //Function Definitions: //Print a pattern stored in a 2-D array void printPattern(char p[][SIZE]) { // ... } //Flip a pattern along its first diagonal void flipPattern(char p[][SIZE]) { //Think about a letter at (i, j) or p[i][j] and a letter at (j, i) or p[j][i] // ... } //Sample output: Triangle pattern * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * - - * * * * * * * * * * * * * * - - - * * * * * * * * * * * * * - - - - * * * * * * * * * * * * - - - - - * * * * * * * * * * * - - - - - - * * * * * * * * * * - - - - - - - * * * * * * * * * - - - - - - - - * * * * * * * * - - - - - - - - - * * * * * * * - - - - - - - - - - * * * * * * - - - - - - - - - - - * * * * * - - - - - - - - - - - - * * * * - - - - - - - - - - - - - * * * - - - - - - - - - - - - - - * * - - - - - - - - - - - - - - - * Flag pattern - - - - - - - - * * * * * * * * - - - - - - - - * * * * * * * * - - - - - - - - * * * * * * * * - - - - - - - - * * * * * * * * - - - - - - - - * * * * * * * * - - - - - - - - * * * * * * * * - - - - - - - - * * * * * * * * - - - - - - - - * * * * * * * * - - - - - - - - * * * * * * * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - After flipping ... Triangle pattern * - - - - - - - - - - - - - - - * * - - - - - - - - - - - - - - * * * - - - - - - - - - - - - - * * * * - - - - - - - - - - - - * * * * * - - - - - - - - - - - * * * * * * - - - - - - - - - - * * * * * * * - - - - - - - - - * * * * * * * * - - - - - - - - * * * * * * * * * - - - - - - - * * * * * * * * * * - - - - - - * * * * * * * * * * * - - - - - * * * * * * * * * * * * - - - - * * * * * * * * * * * * * - - - * * * * * * * * * * * * * * - - * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * Flag pattern - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * * * * * * * * * - - - - - - - * * * * * * * * * - - - - - - - * * * * * * * * * - - - - - - - * * * * * * * * * - - - - - - - * * * * * * * * * - - - - - - - * * * * * * * * * - - - - - - - * * * * * * * * * - - - - - - - * * * * * * * * * - - - - - - -
//Define named constants #define ROWS 3 #define COLS 5 //Function predeclarations void print1DArray(int oneDarr[], int length); void fitIn1DArray(int twoDarr[][COLS], int oneDarr[]); void reverse(int oneDarr[], int length); int main() { //Two Dimensional array of integers int n[ROWS][COLS] = { {2, 5, 7, 1, 3}, {9, 6, 3, 4, 7}, {8, 2, 5, 5, 0} }; int p[ROWS*COLS]; //Move 2D array into 1D array fitIn1DArray(n, p); //Print out the 1D array print1DArray(p, ROWS*COLS); //Reverse 1D array reverse(p, ROWS*COLS); cout <<"\nAfter reversing ..." << endl; //Print out the 1D array after reversing print1DArray(p, ROWS*COLS); cout << endl; return 0; } //Print out the 1D array void print1DArray(int oneDarr[], int length) { //oneDarr is the input array and length is its size //... } //Move a 2D array into a 1D array row by row starting from the first row (top) void fitIn1DArray(int twoDarr[][COLS], int oneDarr[]) { //Need to have an index variable for the one-dimentional array //Is this helpful? index = i * COLS + j // ... } //Reverse a 1D array void reverse(int oneDarr[], int length) { //There are many ways to do this. //Think about swapping the heads with the tails of the array // ... } //Output: 2 5 7 1 3 9 6 3 4 7 8 2 5 5 0 After reversing ... 0 5 5 2 8 7 4 3 6 9 3 1 7 5 2
//Input: a 2D array (twoDarr) and the column index (col) //Output: the largest number in the specific column int findLargest(int twoDarr[][COLS], int col) { int largest = twoDarr[0][0]; //Find the largest in the column "col" //... return largest; } //Sample output (from the main() function) Column: 0, 1, 2, 3, 4 Largest: 9, 6, 7, 5, 7