1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <iostream>
#include "matrix.h"
using namespace std;
#define MAXROWS 3
#define MAXCOLS 3
int main()
{
Matrix matrix1, matrix2, matrix3, matrix4;
int array1[MAXROWS][MAXCOLS] =
{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int array2[MAXROWS][MAXCOLS] =
{
{10, 11, 12},
{13, 14, 15},
{16, 17, 18}
};
cout << "Matrix object 'matrix1' instantiated:" << endl;
matrix1.display();
cout << "2D array1 added to matrix1 using += " << endl;
matrix1 += array1;
matrix1.display();
// Use overloaded assignment operator to copy the values across
cout << "2D array2 added to matrix2 using += " << endl;
matrix2 += array2;
matrix2.display();
cout << "All elements of matrix1 incremented with ++ " << endl;
++matrix1;
matrix1.display();
cout << "Using addition and subtraction operators" << endl;
matrix3 = matrix1 + matrix2;
matrix4 = matrix2 - matrix1;
cout << "matrix3 = matrix1 + matrix2" << endl;
matrix1.display();
cout << "+" << endl;
matrix2.display();
cout << "--------------" << endl;
matrix3.display();
cout << "matrix4 = matrix2 - matrix1" << endl;
matrix2.display();
cout << "-" << endl;
matrix1.display();
cout << "--------------" << endl;
matrix4.display();
return 0;
}
|