So i suppose to do some Matrix calculator and perform some calculation by using classes.
But we need to copy the square matrixes to other matrix to perform the calculation without changing the actual value.
So we can use the same matrix and just changing the form to
upper or lower triangular ,etc...
Can someone please help me...
Your advise is very much appreciated
Thank You
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
class Matrix
{
public :
Matrix ();
Matrix (int,int);
~Matrix();
Matrix (const Matrix&);
void lowerTriangleM();
void upperTriangleM();
void diagonalM();
void transpose();
void addMatrix (const Matrix&);
void minusMatrix ( const Matrix&);
Matrix multiplyMatrix (const Matrix&);
bool equality (const Matrix&) const;
void printMatrix ();
private :
int row;
int col;
int **m;
void initMatrix();
void generateMatrix();
};
Matrix::Matrix ()
{
// do nothing
}
Matrix::Matrix (int row,int col)
{
Matrix:: initMatrix ();
this -> row = row;
this -> col = col;
m = new int* [row];
for (int i = 0; i < row; i++)
{
m [i] = new int [col];
}
Matrix :: generateMatrix ();
Matrix :: printMatrix();
}
Matrix::~Matrix ()
{
cout << "Garbage collection - Matrix 1" << endl;
int sum=0;
for(int i=0;i<row;i++)
{
delete m[i];
delete m;
cout << "Row " << sum++ << " deleted" << endl;
}
cout <<"Whole Matrix deleted" << endl;
}
Matrix::Matrix (const Matrix& m)
{
this->row = m.row;
this->col = m.col;
this->m = m.m;
}
void Matrix::initMatrix ()
{
row = 0;
col = 0;
}
void Matrix::generateMatrix ()
{
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
m [i][j] = rand () % 10;
}
void Matrix:: lowerTriangleM ()
{
for (int i = 0; i < row; i++)
{
cout << "\t" << "[";
for (int j = 0; j < i; j++)
{
cout << m [i][j] << "\t";
}
cout << "]";
cout << endl;
}
}
void Matrix::upperTriangleM()
{
// generate an lower triangle type
}
void Matrix::diagonalM()
{
for (int i = 0; i < row; i++)
{
cout << "\t" << "[";
for (int j = 0; j < col; j++)
{
if(i != j)
{
m[i][j] = 0;
}
cout << m [i][j] << "\t";
}
cout << "]";
cout << endl;
}
}
void Matrix :: transpose()
{
// generate transpose matrix
}
void Matrix::addMatrix (const Matrix&)
{
// to calculate addition inside the matrix
}
void Matrix::minusMatrix ( const Matrix&)
{
// tp Substract all the elements inside the matrix
}
bool Matrix:: equality (const Matrix&) const
{
return true;
}
void Matrix::printMatrix ()
{
for (int i = 0; i < row; i++)
{
cout << "\t" << "[";
for (int j = 0; j < col; j++)
{
cout << m [i][j] << "\t";
}
cout << "]";
cout << endl;
}
}
Matrix Matrix::multiplyMatrix (const Matrix& m)
{
// Multiply matrix
}
int main ()
{
int option;
int choose;
char choice;
int order;
srand (time(NULL));
int row;
int col;
int **m;
do{
cout << endl;
cout << "Matrix Calculator" << endl;
cout << "Here are some of the options" << endl;
cout << " 1 . An example of square Matrix" << endl;
cout << " 2 . Properties of square Matrix" << endl;
cout << " 3 . Matrices operations" << endl;
cout << " 9 . Quit"<< endl;
cout << "Your option: ";
cin >> option;
if (option==1)
{
do
{
cout << "An example of Matrix " << endl;
cout << endl;
cout << "Enter the number of rows :";
cin >> row;
cout << "Enter the number of columns :";
cin >> col;
cout << endl;
cout << "Matrix is" << endl;
Matrix m1(row,col);
cout << "See more example (Y/N) ? ";
cin >> choice;
cout << setw(80) << setfill ('-') << " "<<endl;
}while (choice!='n'&&choice!='N');
}
else if (option==2)
{
cout << " Here are some of the properties of square matrix" << endl;
cout << " Enter the order n of n x n matrix : ";
cin >> order;
row = col = order;
cout << " Here is the square Matrix" << endl;
Matrix m2(row,col);
do{
Matrix m(m2); /* SO I WANT TO COPY THE FIRST SQUARE MATRIX FIRST TO PERFORM BELLOW TASK
WITHOUT ACTUALLY CHANGE THE FIRST MATRIX VALUE*/
cout << "Wish to see some special matrices" << endl;
cout << endl;
cout << " 1. Diagonal matrix" << endl;
cout << " 2. Lower triangular matrix" << endl;
cout << " 3. Upper triangular matrix" << endl;
cout << " 4. Transpose of a matrix" << endl;
cout << " 9. Not interested" << endl;
cout << "Your choice: ";
cin >> choose;
if (choose == 1)
{
m.diagonalM();
}
else if (choose == 2)
{
m.lowerTriangleM();
}
}while (choose!=9);
}
}while (option!=9);
}