Assignment #7: Given the following 2-dimensional n x n integer matrix class

 

class nMatrix {

int **values;

int size; //size of matrix
public:

nMatrix(int n, int x); // construct nMatrix of size n and initialize it as x;

~nMatrix(); // destructor;
nMatrix(const nMatrix& a); // copy constructor

friend ostream& operator<<(ostream&, const nMatrix&);

};

 

ostream& operator<<(ostream& os, const nMatrix& m) { 

for(int i=0;i<m.size;i++) {

for(int k=0;k<m.size;k++) os << m.values[i][k] << " ";

os<<"\n";

}

return os

 

1.    Complete constructor nMatrix(int n, int x), destructor ~nMatrix(), and copy constructor nMatrix(const nMatrix& a).

2.    Program a function nMatrix addnMatrix(nMatrix a, nMatrix b) that adds two nMatrix a and b and return the result.

 

Oral Test at the lab on April 12.

 

#4/10 updated : Hint_video

#4/12 updated : lab_ppt