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);
};
Read more here!
Top comments (0)