Dynamic Matrix Class

Dynamic Matrix Class

Description:

This purpose of this project is to create a matrix class that can grow the rows or columns dynamically. The program uses a struct array that contains a row pointer and the number of rows. The row pointer then points to an array of columns where each node in the column array contains a pointer to another array of data for the specific row/column and the number of columns. Abstraction can be seen in the diagram in the Project URL.

For instance, say we have two scopes currently available: global and main. Global encapsulates the main scope but does not have access to any of the variables within main. For example, if the main scope contains the variable userVar of type int then userVar can not be access by the global scope.

Commands within symtable.h class:
  • numcols: returns the number of columns in the current row r.
  • growcols: the function grows the number of columns in the row r up to C columns.
  • grow: the function grow creates a new matrix of size R & C. The matrix is initialized to default value by the copy constructor used to create the matrix.
  • size: returns the number of elements in the matrix by traversing through the whole matrix and counting each element (with the use of a counter).
  • at: returns the exact location within the matrix; returns (r,c) element given r = rows and c = columns. Used to access or change element.
  • operator (): returns the exact location within the matrix; returns (r,c) element given r = rows and c = columns. Used to access or change element
  • operator * (scalar multiplication): traverses through the matrix and updates each element by multiplying it by a scalar value. Returns the updated matrix. Must be in form M2 = M1 * 2.
  • operator * (matrix multiplication): Must be called in form M3 = M1 * M2. Matrix multiplication produces a new matrix given the size of the rows from the original (this) matrix and the columns of the other matrix.
  • _output: couts the matrix by traversing the matrix and outputting each element. [More detailed description of commands in code documentation within the file].
Data Structure: Arrays w/ pointers and structs.
Leveraged Knowledge: use of structs to create an array of pointers, general-purpose class in C++, copy constructor [more on website].

Sample Outputs

Download Code Here

Diagrams by Professor Joseph Hummel