#include using namespace std; #define N 100 class my_matrix { int matrix[N][N]; int max_entries; public: void set_values (int _max_entries); void set_entries () ; int trace () ; int determinant(); }; void my_matrix::set_values (int _max_entries) { max_entries = _max_entries ; } void my_matrix::set_entries () { //declaring the entries of the 2 dimensional array. for (int i = 0 ; i < max_entries ; ++i ) for (int j = 0 ; j < max_entries ;++j) matrix[i][j] = i+j + 1 ; } int my_matrix::trace() { int return_value = 0 ; for (int i = 0 ; i < max_entries ; ++ i) return_value +=matrix[i][i] ; return return_value ; } int main () { int n ; my_matrix mat ; cout << " This program calculates the trace of a matrix. " << endl; cout << " Please enter the dimension of the matrix: " ; cin >> n; mat.set_values (n); mat.set_entries(); cout << "trace of the matrix " << mat.trace() << endl; return 0; }