Question: I am struggling making the code like the output. For example fill in the arrays, I am getting (1,1), I want to do it like

I am struggling making the code like the output. For example fill in the arrays, I am getting (1,1), I want to do it like the output without getting any errors for many rows and columns.

Here is my code :

#include #include #include #include using namespace std; class Matrix {

public:

Matrix();

// default constructor

// Postcondition: all elements are initialized to 0

double& operator()(const int rn, const int cn);

// rn: row subscript; cn: column subscript

// Postcondition: returns the value of data[rn][cn]

void operator()();

// An overloaded function that sets all array elements to zero

// Postcondition: clears or reset all elements of 2D data array

void transpose(int &numRows, int &numCols);

// numRows and numCols: the actual # rows & columns that are to be operated on

// Postcondition: entire rows and columns are interchanged

void fill2dArray(int &numRows, int &numCols);

// Precondition: numRows

// Postcondition: data array filled with numRows x numCols values

void display2dArray(int &numRows, int &numCols);

// Postcondition: displays the contents of numRows x numCols 2D array

private:

static const int ROW_SIZE = 20, COL_SIZE = 20;

double data[ROW_SIZE][COL_SIZE];

}; Matrix::Matrix() { data[ROW_SIZE][COL_SIZE] = { 0 }; // intialize a 2d array to all zero } double& Matrix::operator()(const int rn, const int cn) { double requestedData = data[rn][cn]; return requestedData; // return the requested data } void Matrix::operator()() { data[ROW_SIZE][COL_SIZE] = { 0 }; // reset all to zero } void Matrix::transpose(int &numRows, int &numCols) { double transMatrix[ROW_SIZE][COL_SIZE] = { 0 }; // create a temp matrix for (int i = 0; i

for (int i = 0; i> data[i][j]; } } } void Matrix::display2dArray(int &numRows, int &numCols) { for (int i = 0; i

cout > c; cout > d;

cout

My output is different , I want to get this one below, I need to keep the functions the way they are , just i need to tweak the code to work like the below picture.

I am struggling making the code like the output. For example fill

C: Windows exe You may enter up to 10 rows and 10 columns of numbers How many rows? 3 manuy colunns? 5 Enter 5 values for row #0 1 2 3 4 5 Enter 5 values for row #1 6 7 8 910 Enter 5 values for row #2 11 12 13 14 15 Contents of the 3 5 array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 After transpose: 1 6 11 2 7 12 3 8 13 4 9 14 5 10 15 Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!