Matrices are used in a wide variety of applications in mathematics, physics, and a plethora of other fields. Though widely used, matrices provide a number of interesting implementational challenges, including the need to deal with dynamic memory allocation and mis-matched matrix sized. (Operations on large or distributed matrices present efficiency challenges as well, though these are rather beyond the scope of this course.) Matrices also have the rather nice feature of supporting a wide variety of mathematical operations. This makes them ideal as an introduction to operator overloading.
For this assignment, you will be implementing a matrix class capable of dealing with matrices of doubles.
Your task for this program is to build a Matrix class to represent a matrix of doubles. Your class will need to provide overloaded operators to make using the class easier.
Unlike previous projects, main() will be provided for you. You need only provide an implemenation of the Matrix class to power the pre-written code.
There is no need for you to implement input as part of your matrix class.
You should overload the << operator to output Matrices:
Matrices should be output as bracketed matrices with bracketed rows. Each row should have have values printed with one space between them. The matrix should start on a new line, and each row should be on a seperate line. All lines but the first should have a single space prior to the first bracket on the line.
This statement
cout << "The first Matrix is: " << matrix1 << endl << "The second Matrix is: " << matrix2 << endl;should print something formatted like:
The first Matrix is: [[4.2 5.6 3.2 6.7 1.221 6 1000000] [4.6 1.1 0.9999 3.1 1 100000 0] [0 0 0 0 0 0 0] [4 5 6 7 0 0 0]] The second Matrix is: [[5.5 1000.1 0 0 0 0] [4.6 1.1 0.9999 3.1 1 100000] [0 0 0 0 0 0] [4.5 5.5 6.5 0 0 0] [0 0 0 0 0 0]]
This class should create a Matrix which can store doubles.
The Matrix class should have the following functionality:
You should overload operators to do the following:
You should implement both the common (eg +) and assignment (eg +=) forms of the mathematical operations. Remember that multiplication may change the size of the matrix!
int main() is provided for you in the file main.cpp. You should not make any changes to this file. It should, in fact, be possible for the grader to compile your program with a different version of main.cpp and have the new program compile and run.
You will provide a Makefile that we can use to compile and run your program. It needs to include the rules for default, clean, and run (see the example here for details). Note that you will need to include main.cpp in the Makefile.
The main function is, of course, implemented in main.cpp. Your class should be implemented in Matrix.h and Matrix.cpp. Other classes or functions should have appropriate header and source files.
Only the following functions and classes may be used (remember to add using namespace std;):
Note, however, that while you may include these libraries it is not required that you do so.
Have fun, and remember that all the usual rules regarding cheating and cooperation are in full effect for this program.