#include "matrix.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>

using namespace std;

int main( int argc,char *argv[] )
{

// check the number of the input
 if (argc != 4)
     {
     cout << "The name used to start the program: " << argv[ 0 ] << "\nArguments are:\n";
     return 1;
     }
	 
// convert strings to integers 

  int imax =  atoi( argv[ 1 ] );
  int jmax =  atoi( argv[ 2 ] );
  int kmax =  atoi( argv[ 3 ] );
 
 // check the input if there are equal because we can not do sum or sub for the matrix if the dimensions are not equal
 
 if ( imax != jmax && imax != kmax && jmax != kmax )
	{
	cout<< "your input must be equals";
	}

// check the input if there contains any ZERO
 
 if ( imax == 0 && jmax == 0 && kmax == 0 )
	{
	cout<< "you con not use 0";
	}
	
 // pass the dimensions of matrix a,b and c to the MATRIX function
 
  Matrix a(imax,jmax);
  Matrix b(jmax,kmax);
  Matrix c(imax,kmax);

// create MCLASS.OUT and write on it

	ofstream myfile;
	myfile.open ("mclass.txt");
	
// write the elements of matrix A on MCLASS.OUT

	myfile<<"Matrix A: "<<endl;

	for(int i=0;i<imax;i++)
	{
		for(int j=0;j<jmax;j++)
		{
			myfile<<a.getElement(i,j)<<"  ";
		}
		myfile<<endl;
	}
	myfile<<endl;
	
// write the elements of matrix B on MCLASS.OUT

	myfile<<"Matrix B: "<<endl;

	for(int i=0;i<jmax;i++)
	{
		for(int j=0;j<kmax;j++)
		{
			myfile<<b.getElement(i,j)<<"  ";
		}
		myfile<<endl;
	}
	myfile<<endl;

// write the elements of matrix C on MCLASS.OUT	
	
	myfile<<"Matrix C: "<<endl;
	for(int i=0;i<imax;i++)
	{
		for(int j=0;j<jmax;j++)
		{
			for(int k=0;k<kmax;k++)
			{
			myfile<<c.getElement(i,k)<<"  ";
			}
		}
		myfile<<endl;
	}
	cout<<endl;

// sum matrix A anb B 

	c.operator-(c);
	c.operator=(a);
	c.operator+(b);

// write the elements of matrix C on MCLASS.OUT
	
	myfile<<"Matrix C = A + B "<<endl;
	for(int i=0;i<imax;i++)
	{
		for(int j=0;j<jmax;j++)
		{
			myfile<<c.getElement(i,j)<<"  ";
		}
		myfile<<endl;
	}
	
// sub matrix A and B

	c.operator-(c);
	c.operator=(a);
	c.operator-(b);

// write the elements of matrix C on MCLASS.OUT
	
	myfile<<"Matrix C: A - B"<<endl;
	for(int i=0;i<imax;i++)
	{
		for(int j=0;j<jmax;j++)
		{
			myfile<<c.getElement(i,j)<<"  ";
		}
		myfile<<endl;
	}

//multiply A and B
	
	c.operator-(c);
	c.operator=(a);
	c.operator*(b);

// write the elements of matrix C on MCLASS.OUT

	myfile<<"Matrix C: A x B"<<endl;
	for(int i=0;i<imax;i++)
	{
		for(int j=0;j<jmax;j++)
		{
			myfile<<c.getElement(i,j)<<"  ";
		}
		myfile<<endl;
	}

// compare A and B and write the result on MCLASS.OUT 
 
	if(a.operator==(b))
	{
		myfile<<"Matrix A and B are equal"<<endl;
	}
	else
	{
		myfile<<"Matrix A and B are not equal"<<endl;
	}

// close the MCLASS.OUT

	myfile.close();

	
	return 0;

}
