To write two classes in C++ with one matrix class and vector class
- Matrices and vectors shall be able to be multiplied
- Addition and scalar multiplication shall be supported as well
-
A Vector class MyVector is created by following the below steps
- Private variables to hold total size, pointer to start and current capacity are created
- The vector objects shall be created on the heap instead of stack because of the need of dynamic allocation
- The vector class is templated in order to have vectors of different datatypes
- Below constructors are created
- Default constructor with no parameter
- Constructor with input as length of vector and initial values
- Constructor with input as a list of values to create dynamic vector
- Constructors based on Rule of three
- copy constructor
- assignment constructor
- destructor
- Below public functions are created
- void display_elements()
- To display elements of vector to std out
- unsigned int get_size()
- To get the size of the vector
- unsigned int get_current_capacity()
- To get the current capacity of vector
- void push(T element);
- To push element to an existing vector
- void pop();
- To pop last element of a vector
- T& operator[](const unsigned &index);
- To access single elements of vector with [] operator
- void display_elements()
- Below operations are supported through public functions
- MyVector& operator*(MyVector vector, T scalar)
- Multiplication of vector with a scalar
- MyVector& MyVector::operator+(MyVector other)
- Addition of two vectors
- MyVector& operator*(T scalar, MyVector vector)
- Scalar dot product of two vectors
- MyVector& operator*(MyVector vector, T scalar)
-
A Matrix class MyMatrix is created by following the below steps
- Matrix class is a vector object that holds more vector objects that is based on the vector class created above.
- Private variables to hold rows, columns, pointer to start and current capacity are created
- Below constructors are created
- Default constructor with no parameter
- Constructor with input as square matrix size and initial values
- Constructor with input as a list of vectors to create dynamic matrix
- Constructors based on Rule of three
- copy constructor
- assignment constructor
- destructor
- Below public functions are created
- void display_elements()
- To display elements of matrix to std out
- unsigned int get_rows()
- To get the rows of the matrix
- unsigned int get_columns()
- To get the columns of the matrix
- void push(T element);
- To push element to an existing matrix
- void pop();
- To pop last element of a matrix
- T& operator[](const unsigned &index);
- To access single elements of matrix with [] operator
- void display_elements()
- Below operations are supported through public functions
- MyVector& operator*(MyMatrix &matrix, MyVector vector);
- Multiplication of matrix with a vector
- MyMatrix* operator*(MyMatrix &matrix, double scalar);
- Multiplication of matrix with scalar
- MyMatrix* operator+( MyMatrix &matrix1, MyMatrix &matrix2);
- Addition of two matrices
- MyVector& operator*(MyMatrix &matrix, MyVector vector);