Professional Documents
Culture Documents
Assignment 3
Assignment 3
// SparseMatWMult.h
#ifndef SparseMatWMult_h
#define SparseMatWMult_h
#include "SparseMat.h"
template <class Object>
class SparseMatWMult : public SparseMat<double> {
public:
// we need a default constructor for lists
// (used only be SpMt so no protection needed)
SparseMatWMult(int numRows, int numCols);
bool MatMult(SparseMatWMult<Object> & a, SparseMatWMult<Object> & b);
};
int main()
{
clock_t startTime, stopTime;
double randFrac;
int randRow, randCol, smallPercent;
srand(time(NULL)); // for randomness
// non-sparse dynamic matrix
DynMat matDyn, matDynAns;
// clean up
for (int r = 0; r < MAT_SIZE; r++) {
delete[] matDyn[r];
delete[] matDynAns[r];
cout << endl;
}
double temp2[5][5]{
{ 02.00, 01.00, 05.00, 00.00, 02.00 },
{ 1.00, 4.00, 3.00, 2.00, 7.00},
{ 4.00, 4.00, 4.00, 4.00, 4.00},
{ 7.00, 1.00, -1.00, -1.00, -1.00},
{ 0.00, 0.00, 8.00, -1.00, -6.00}
};
aMat.showSubSquare(0, 5);
bMat.showSubSquare(0, 5);
resultMat.showSubSquare(0, 5);
resultMat.MatMult(aMat, bMat);
resultMat.showSubSquare(0, 5);
0 0 0 0 0 0 0 0
0 0
0 0.421444 0 0 0 0 0 0
0 0
0.159887 0 0 0 0 0 0.780732 0
0 0
0 0.265255 0 0 0 0 0 0
0 0.15937
0.267477 0 0 0 0 0 0 0
0 0
0 0 0 0 0 0.910627 0 0
0 0
0 0 0 0 0 0 0 0
0 0.123801
0 0 0.190337 0 0 0.607408 0 0
0.48244 0
0 0.1526 0 0 0 0 0 0
0 0
0 0 0.0453086 0 0 0 0 0
0 0