{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

FinalReport8

# FinalReport8 - Benjamin Jones Final Report Laboratory 8...

This preview shows pages 1–4. Sign up to view the full content.

Benjamin Jones 02/28/08 Final Report Laboratory 8 Header File: // *********************************************************************** // File: functions.h // // Matrix Multiply - User creates a file that specifies matrix dimensions, // and matrix data, and the program multiplies that matrices together, // outputting the resultant matrix // // Author: Benjamin Jones // Created: 28 February 2008 // Updated: Original // // Assignment: Lab 8 // Compiler: MinGW32 G++ 3.4.2 (GNU) //************************************************************************* #include <iostream> #include <cstdlib> #include <fstream> const int OK = 0; const int NOTOK = 1; const int MAX_DIMEN = 100; const int MIN_DIMEN = 1; using namespace std; // 2.a Validate matrix dimensions bool areMatricesValid(int rowOneCount, int colOneCount, int rowTwoCount, int colTwoCount) { // Function: determines if the dimensions for the matrices are valid // // Inputs: the dimensions for each matrix // Ouputs: Whether or not the dimensions are OK (True or False) // 2.a.i If matrix dimensions are not between 1 and 100 // 2.a.i.A Warn user // 2.a.i.B Exit program if ((rowOneCount <= MIN_DIMEN) || (rowOneCount >= MAX_DIMEN)) { cout << "Row dimension not valid for matrix one." << endl; return NOTOK; } if ((rowTwoCount <= MIN_DIMEN) || (rowTwoCount >= MAX_DIMEN)) { cout << "Row dimension not valid for matrix two." << endl; return NOTOK; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
if ((colOneCount <= MIN_DIMEN) || (colOneCount >= MAX_DIMEN)) { cout << "Column dimension not valid for matrix one." << endl; return NOTOK; } if ((colTwoCount <= MIN_DIMEN) || (colTwoCount >= MAX_DIMEN)) { cout << "Column dimension not valid for matrix two." << endl; return NOTOK; } // 2.a.ii If matrix dimensions are not valid for resultant // (<colOneCount != <rowTwoCount>) // 2.a.ii.A Warn user // 2.a.ii.B Exit program if ((colOneCount != rowTwoCount)) { cout << "No such resultant matrix." << endl; return NOTOK; } return OK; } void clearMatrices(float** matrixOne, float** matrixTwo, float** matrixThree, int rowOneCount, int colOneCount, int rowTwoCount, int colTwoCount, int rowThreeCount, int colThreeCount) { // Function: clear each element of each matrix to zero // // Inputs: pointers to each matrix, and each of the dimensions // Outputs: Nothing for (int i = 0; i < rowOneCount; i++) { for (int j = 0; j < colOneCount; j++) { matrixOne[i][j] = 0; } } for (int i = 0; i < rowTwoCount; i++) { for (int j = 0; j < colTwoCount; j++) { matrixTwo[i][j] = 0; } } for (int i = 0; i < rowThreeCount; i++) { for (int j = 0; j < colThreeCount; j++) { matrixThree[i][j] = 0; } } } float** allocate2DArray(int ROWS,int COLUMNS) { // Function: allocates, and creates an array of given dimensions // // Inputs: The needed rows and columns for the array // Outputs: Returns the new array
float** array_2D; array_2D = new float*[ROWS]; for (int i = 0; i < ROWS; ++i){ array_2D[i] = new float[COLUMNS]; } return array_2D; } void delete2DArray(float** array_2D, int ROWS, int COLUMNS) { // Function: deletes an array from memory // // Inputs: The array, its rows, and columns // Outputs: Nothing for (int i = 0; i < ROWS; ++i) { delete[] array_2D[i]; } delete[] array_2D; } // 1.a Get dimensions for matrix one and two

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

FinalReport8 - Benjamin Jones Final Report Laboratory 8...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online