Question: Given the Matrix class interface below, you are asked to 1) implement all the member functions and 2) write a main() function to generate an

Given the Matrix class interface below, you are asked to 1) implement all the member functions and 2) write a main() function to generate an output similar to the following sample display. Also, you are asked to perform the transpose operation by swapping and moving the values stored in the array instead of using an additional intermediate array to get the job done.

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 = 4, COL_SIZE = 4;

double data[ROW_SIZE][COL_SIZE];

}; Given the Matrix class interface below, you are asked to 1)

C: Windows system32\ cmd.exe You may enter up to 10 rows and 10 columns of numbers How many rows? 3 How manuu columns? 5 Enter 5 values for row #0 1 2 34 5 Enter 5 values for row #1 6 7 8 9 10 Enter 5 values for row #2 11 12 13 14 15 Contents of the 3 x 5 array 1 2 3 4 5 6 7 89 10 1112 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 .. . C: Windows system32\ cmd.exe You may enter up to 10 rows and 10 columns of numbers How many rows? 3 How manuu columns? 5 Enter 5 values for row #0 1 2 34 5 Enter 5 values for row #1 6 7 8 9 10 Enter 5 values for row #2 11 12 13 14 15 Contents of the 3 x 5 array 1 2 3 4 5 6 7 89 10 1112 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!