Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. i need your help

i need your help

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicstutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14982052
    wrote on last edited by
    #1

    I have a project and this is what the project is about :

    Implement a template library handling matrices.
    the library must offer operation like:
    • submatrix: return a matrix that contains a contiguous subrange of rows and columns of the original matrix
    • transpose: return a matrix with rows and columns inverted
    The matrices returned by such operators must share the data with the original matrix, but direct copy of the matrices and vectors must result in a deep copy (sharing a matrix can be obtained by taking a submatrix extending the whole row and column ranges).
    Create iterators for the matrix traversing the whole data in any order.
    Provide matrix addition and (row-by-column) multiplication as overloaded operators

    so i did everything and i am stuck in how to implment operator overloaded for multiplication and addition, i mean should i creat a class for this operation or should i implment them in the main and how to do this.

    this is the matrix interface:

    #include #include #include using namespace std;
    // creating matrux interface
    template < typename T>
    class matrix_interface {

    public:
    // virtual keyword allows derived classes to replace the implementation provided by the base class
    virtual int getCol() const = 0;
    virtual int getRow() const = 0;
    virtual T get(int row, int col) const = 0;
    virtual T& get_ref(int row, int col) = 0;
    virtual ~matrix_interface() {};

    };

    //Base

    template < typename T>
    class standard_matrix : public matrix_interface {

    private:

    int row,col;
    
    vector data;
    

    public:

    int getRow() const override {
        return row;
    }
    
    int getCol() const override {
        return col;
    }
    
    standard\_matrix(const vector &data, int row, int col) : row(row), col(col), data(data) {
        if (data.size() < row\*col)
            throw ("the vector is invalid");
        if (row < 1 || col < 1 ){
            throw ("the dimensions are invalid");
        }
    }
    
    
    
     T &getRef(int r, int c) override {
        if (r < 1 || r > row) {
            throw "Row is off limit";
        } else if (c < 1 || c > col) {
            throw "Column is off limits";
        } else{
            T& t= data.at(col \* (r - 1) + c - 1);
            return t;
        }
    }
    
    T get(int r, int c) const override {
        if (r < 1 || r > row) {
            throw "Row is off limit";
        } else if (c < 1 || c > col) {
    
    V 1 Reply Last reply
    0
    • M Member_14982052

      I have a project and this is what the project is about :

      Implement a template library handling matrices.
      the library must offer operation like:
      • submatrix: return a matrix that contains a contiguous subrange of rows and columns of the original matrix
      • transpose: return a matrix with rows and columns inverted
      The matrices returned by such operators must share the data with the original matrix, but direct copy of the matrices and vectors must result in a deep copy (sharing a matrix can be obtained by taking a submatrix extending the whole row and column ranges).
      Create iterators for the matrix traversing the whole data in any order.
      Provide matrix addition and (row-by-column) multiplication as overloaded operators

      so i did everything and i am stuck in how to implment operator overloaded for multiplication and addition, i mean should i creat a class for this operation or should i implment them in the main and how to do this.

      this is the matrix interface:

      #include #include #include using namespace std;
      // creating matrux interface
      template < typename T>
      class matrix_interface {

      public:
      // virtual keyword allows derived classes to replace the implementation provided by the base class
      virtual int getCol() const = 0;
      virtual int getRow() const = 0;
      virtual T get(int row, int col) const = 0;
      virtual T& get_ref(int row, int col) = 0;
      virtual ~matrix_interface() {};

      };

      //Base

      template < typename T>
      class standard_matrix : public matrix_interface {

      private:

      int row,col;
      
      vector data;
      

      public:

      int getRow() const override {
          return row;
      }
      
      int getCol() const override {
          return col;
      }
      
      standard\_matrix(const vector &data, int row, int col) : row(row), col(col), data(data) {
          if (data.size() < row\*col)
              throw ("the vector is invalid");
          if (row < 1 || col < 1 ){
              throw ("the dimensions are invalid");
          }
      }
      
      
      
       T &getRef(int r, int c) override {
          if (r < 1 || r > row) {
              throw "Row is off limit";
          } else if (c < 1 || c > col) {
              throw "Column is off limits";
          } else{
              T& t= data.at(col \* (r - 1) + c - 1);
              return t;
          }
      }
      
      T get(int r, int c) const override {
          if (r < 1 || r > row) {
              throw "Row is off limit";
          } else if (c < 1 || c > col) {
      
      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Member 14982052 wrote:

      i am stuck in how to implment operator overloaded for multiplication and addition, i mean should i creat a class for this operation or should i implment them in the main and how to do this.

      You should (have to) implement them in your matrix class. See the example: [beginner - C++ operator overloading for matrix operations - follow-up - Code Review Stack Exchange](https://codereview.stackexchange.com/questions/149669/c-operator-overloading-for-matrix-operations-follow-up)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups