In this program you will create a simple matrix manipulation engine. The main purpose of this assignment is not to program all of the possible matrix calculations but to learn how to write C++ classes. With this in mind, the use of the C++ Standard Template Library will not be allowed. You MUST write all classes used in this program yourself with the one exception of the String class.
Your program is to perform the following operations on matrices:
Operator | Operation |
---|---|
Transpose of the matrix If matrix T is the transpose of matrix A, the value at position T[i][j] = A[j][i]. The dimensions of A and T will be exactly opposite. That is, the number of rows in A will equal the number of columns in T and the number of columns in A will equal the number of rows in T. | |
Matrix multiplication (the cross product) When multiplying matrices A and B, the dimensions must follow a specific form. The number of columns of A must equal the number of rows of B and the resulting matrix will have the same number of rows as A and the same number of columns as B. If A has size of R1xC1 and B has size of R2xC2, C1 must equal R2 and the resulting matrix will have size R1xC2. If matrix R is the result of adding A and B, the value at R[i][j] = Sum of (A[i][1]*B[1][j] + A[i][2]*B[2][j] + ... + A[i][m]*B[m][j]), where m is the number of columns in A. Note the A*B is not the same as B*A. | |
Matrix addition When adding matrices A and B, the dimensions must be the same. That is the number of rows in A must equal the number of rows in B and the number of columns in A must equal the number of columns in B. If matrix R is the result of adding A and B, the value at R[i][j] = A[i][j] + B[i][j]. | |
Scalar multiplication (the dot product) This is when a singular value will be multiplied by a matrix or a matrix will be multiplied by a singular. The resulting matrix R will have the same dimensions as the original matrix A and R[i][j] = value*A[i][j]. |
Your program will have to keep track of multiple matrices. The total number of matrices to be stored in your program is undefined; therefore you must have a dynamic storage class to hold the matrices. Each matrix is identified by a name (a String). The names are used as the keys to store and retreive the matrices. While the use of a fast dynamic storage structure such as a hash table is encouraged, it is not required. You may use any dynamic storage structure that you wish. This storage structure must be a C++ class, but there are no requirements on the methods that must be included in this class. Also all names used will be any sequence of non-white space characters.
The program is to use text input to get commands from standard input or a file. Each command will be given on its own line in the input and can be in either upper or lower case. The command will be the first non-white space character on the line. If the first non-white space character is not a command some error message should be produced. Each command (except for the # command) is to produce a message stating the command occurred. The commands are:
The data will consist of integer values. The first two integer values will specify the size of the matrix in rows and columns (the first integer will specify the number of rows, the second integer will specify the number of columns). After this, the data values for each position in the matrix will be given in row-major order (all of the values for the first row will be given, then all of the values for the second row, then all of the values for the third row, etc). You may assume that the input will always contain the proper number of integer values for the size specified. You must check that the size values given are both values of one or greater. If either size value is incorrect, print an error message and continue processing the input for valid commands from the current input source.
If the name given in the command corresponds to a matrix that already exists, remove (and deallocate) that matrix than create a new matrix with the current information. If the name does not correspond to an existing matrix, create a new matrix with a new name.
Here are a list of data files that we created. These do NOT test all possible input to your program. So you will have to create your own tests for this. Also, these files are not the only ones that will be used when grading your program.
Here are a list of data files that we created. These do NOT test all possible input to your program. So you will have to create your own tests for this. Also, these files are not the only ones that will be used when grading your program.
Your program must also take an optional command line argument. The argument would be the name of a file that would contain commands for the program to use. If this command line argument is given, your program should use the command line value as the filename for an f command. So if a command line argument is given, the file is opened and the commands are read from the file. Once the end of the file is reached, commands should be taken from the standard input.
As specified, your program will need three dynamic classes.
This program will require the use of multiple source code files and separate compilation. The division of the subroutines between the multiple source code files must be logical. One suggestion would be to have each class in its own file (or one file with all classes) and the command interface code in another source code file. Note: a "source code file" is not the same as a "header file". Source code files will have a file extension of .c (or .cpp, .C, .CC, etc.), while a header file will have a file extension of .h. To perform separate compilation, your makefile must separately compile the source code files into ".o" files and then link the ".o" files together. Using a #include statement with a source code file (a .c file) will NOT satisfy a requirement of separate compilation.
In addition to using and submitting a makefile, this program will also require a 1-2 page write up of the data structures used in the program and the logical division of your program into multiple source code files (i.e. which routines are where). Remember that this write-up is to be written in ASCII format and is to be electronically turned in with your program. The name of this file should be "readme.txt". Also recall that your program will be given to another student to write a critique. Therefore, it is suggested that you do not include your Social Security Number in your program. Instead use your name and your CS User ID to identify yourself.
Your program must be written in good programming style. This includes (but is not limited to) meaningful identifier names, a file header at the beginning of each source code file, a function header at the beginning of the function, proper use of blank lines and indentation to aide in the reading of your code, explanatory "value-added" in-line comments, etc.
The work you turn in must be 100% your own. You are not allowed to share code with any other person (inside this class or not). You may discuss the project with other persons; however, you may not show any code you write to another person nor may you look at any other person's written code.
You are to submit this project using the CS Department's UNIX machine's turnin command. The project name for this assignment is mp3. Be sure to submit all source code, header files, makefile as well as your program description. Failure to turnin all required pieces will result in a lower grade for the assignment.