Question 1
Write a C++ program that contains the following functions
A function that takes in a 2D array with 5 rows and 6 columns, and has the user read in values to fill up the array
A function that takes in the 2D array and a parallel array and finds the largest element using row-major order and stores these elements in the corresponding location of the parallel array, as explained in class
A function that does the same as above using column-major order
A function to print the 2D array using row-major order
A function to print the 2D array using column-major order
A function that takes in a 1D array and it's size and prints the entire array.
Use appropriate function calls in the main to display the 2D array in column and row major order, and the content of the 1D arrays
1
Expert's answer
2018-04-27T12:09:08-0400
#include <iostream>
using namespace std;
const int ROWS = 5; const int COLS = 6;
void fillArray(int array[ROWS][COLS]) { for (int row = 0; row < ROWS; ++row) { for (int col = 0; col < COLS; ++col) { cin >> array[row][col]; } } }
void largestInRow(int array[ROWS][COLS], int largest[]) { for (int row = 0; row < ROWS; ++row) { int max = array[row][0]; for (int col = 1; col < COLS; ++col) { if (array[row][col] > max) max = array[row][col]; } largest[row] = max; } }
void largestInCol(int array[ROWS][COLS], int largest[]) { for (int col = 0; col < COLS; ++col) { int max = array[0][col]; for (int row = 0; row < ROWS; ++row) { if (array[row][col] > max) max = array[row][col]; } largest[col] = max; } }
void printRowMajor(int array[ROWS][COLS]) { for (int row = 0; row < ROWS; ++row) { for (int col = 0; col < COLS; ++col) { cout << array[row][col] << " "; } cout << endl; } }
void printColMajor(int array[ROWS][COLS]) { for (int col = 0; col < COLS; ++col) { for (int row = 0; row < ROWS; ++row) { cout << array[row][col] << " "; } cout << endl; } }
void printArray(int array[], int arrSize) { for (int i = 0; i < arrSize; ++i) { cout << array[i] << " "; } cout << endl; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment