DEV Community

Quoc Bao
Quoc Bao

Posted on • Edited on

2 1

Matrix class implementation

The concept of matrix and multidimensional array had always been an intriguing topic for me when I was in programming classes. Since computer memory isn’t organized in tabular form, there should be a way to represent it. Today, I am going to show you how to implement a matrix class with a component of an array. It will simply has some basic operations of matrix such as addition, subtraction, and multiplication.

class Matrix
{
private:
    Array *A;
    int rows = 0, cols = 0;

    void deepcopy(const Matrix &other);

public:
    Matrix();
    Matrix(int x, int y);
    void input();
    void output();

    void insert(int, int, int);
    int findCelebrity();

    // ~Matrix();

    Matrix(const Matrix &other);
    Matrix &operator=(const Matrix &other);
    void create_identity(int);
    void create_celeb_test(int);

    // Matrix &operator+(const Matrix &other);
    Matrix &operator-(const Matrix &other);

    int view_rows();
    int view_cols();
    int getElement(int, int);
    void setElement(int, int, int);
    bool knows(int, int);

    friend istream &operator>>(istream &in, Matrix &a);
    friend ostream &operator<<(ostream &out, Matrix a);
};
Enter fullscreen mode Exit fullscreen mode

Read more here!

Image of Bright Data

Global Data Access Unlocked – Reach data across borders without restrictions.

Unlock the power of global data collection with our advanced proxy solutions. Ideal for market research and more.

Unlock Data Now

Top comments (0)

Image of Bright Data

Ensure Data Quality Across Sources – Manage and normalize data effortlessly.

Maintain high-quality, consistent data across multiple sources with our efficient data management tools.

Manage Data

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay