1 / 4

Problem Session

Problem Session. Working in pairs of two, solve the following problem. 1. 1. 2. 4. 3. 7. 4. 2. 5. 5. 6. 8. 7. 3. 6. 8. 9. 9. Problem. If a matrix is as follows:. We’ve seen how to derive a Matrix from vector<Row>. then the transpose of that matrix is as follows:.

grady-fox
Télécharger la présentation

Problem Session

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Problem Session Working in pairs of two, solve the following problem...

  2. 1 1 2 4 3 7 4 2 5 5 6 8 7 3 6 8 9 9 Problem If a matrix is as follows: We’ve seen how to derive a Matrix from vector<Row>. then the transpose of that matrix is as follows: Intuitively, the transpose operation interchanges the rows and columns of a matrix. Write a function member Matrix::Transpose() that returns the transpose of the Matrix receiving the message.

  3. Coding: Interface // Matrix.h // Directives have been omitted ... typedef vector<double> Row; class Matrix : public vector<Row> { public: Matrix(); Matrix(int rows, int columns); int Rows() const; int Columns() const; Matrix operator+(const Matrix & mat2); Matrix Transpose() const; void Read(istream & in); void Print(ostream & out) const; friend istream & operator>>(istream & in, Matrix & mat); friend ostream & operator<<(ostream & out, const Matrix & mat); // ...

  4. Coding: Definition // Matrix.cpp // ... Matrix Matrix::Transpose() const // I’m m-by-n { Matrix result(myColumns, myRows); // it’s n-by-m for (int r = 0; r < myRows; r++) // for row r for (int c = 0; c < myColumns; c++) // for col c result[c][r] = (*this)[r][c]; // set result return result; }

More Related