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
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 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started