Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions