//////////////////////////////////////////////////////////////////// // // assignment 3 // due Tuesday March 5th, 1996 // // This one involves quite a bit more than previous homework's, so I'm // giving you a bit more than a week. Better get started! // // // Implement a simple 5*5 double precision matrix calculator: // // (1) write a function read_mat() which takes a 5*5 matrix of doubles as argument // and fills it with values read in from cin (see example code below) // // (2) write a function write_mat() which takes a 5*5 matrix of doubles and prints it // out to cout (see example below) // // (3) write a function add_mat() which takes 3 5*5 matrices, adds the first two, // and puts the result in the third // // (4) write a function mult_mat(), which takes 3 5*5 matrices, multiplies the first two // and puts the result in the third // // // (5) write a function read_command(), which reads cin (after skipping any whitespace) in // one of these commands, and performs the requested action (using the functions above): // (1) input // - prompts for and reads in matrixname (where matrixname is an arbitrary matrix name) // - dynamically allocates a character array to hold matrixname, as well as // space for a 5*5 matrix of doubles // - stores matrixname (i.e., the string provided) in the character array // - reads the 5*5 matrix from cin and stores it in the dynamically allocated space // // (2) output // - prompts for and reads in matrixname (where matrixname is the name of a previously input matrix) // - prints out the matrix in a nice readable form (see example code below) // // (3) multiply // - prompts for matrix1, matrix2, matrix3 // - matrix1, matrix2 are the names of pre-existing matrices // - matrix3, if it doesn't exist already, is allocated (name and matrix storage) // - multiplies matrix1, matrix2, puts result in matrix3 // // (4) add // - prompts for matrix1, matrix2, matrix3 // - same as (3), except adds instead of multiplies // // // // // Notes: // // // (0) do your best to check for user input errors - for example, unrecognized // commands, as well as adding/multiplying where one/both of the operands are undefined // // (1) you're going to want to implement both the dynamically-allocated matrices and // matrix names as pointer arrays, where it is int*[5] and char* that are being stored // // (2) sample input (so you can understand the syntax) is provided in the directory // // (3) I strongly recommend that you build up a test input file of your own, // and then run it using UNIX indirection - if your program is called "foo" and the // input file is called "my_input", then run "foo my_output", which will // read from my_input and save the output to ... my_output // // (4) I'm going to want to actually run your programs on this, so plan on indicating // the path of the binary and source files on the printout you hand in. // // (5) you can get documentation on strcpy(), strcmp() by using "man string" on pads1; // just use the input and output operations as given in the example for the moment // (I want to wait before talking about all the possibilities) // // //////////////////////////////////////////////////////////////////// #include // to get declaration of strcmp() and strcpy() #include #include // declares setprecision(), setw() #include // declares exit() int main(int argc,char *argv[]) { const int i_max=5, j_max=5; double sample_mat[i_max][j_max]; //////////////////////////// // sample matrix input cout << "enter sample_mat, row by row, numbers separated by whitespace\n" "(any number of spaces, tabs or newlines)\n"; for (int i=0; i < i_max; ++i) for (int j=0; j < j_max; ++j) if (! (cin >> sample_mat[i][j]) ) // input operation returns 0 on error { cerr << "Error reading matrix at i="<