#include <iostream>
#include <fstream>
#include "matrix.h"
using namespace std;

int main() {

  ifstream fin;

  do {
    if (fin.fail()) {
      cout << "Unable to open file." << endl;
      fin.clear();
    }
    string filename;
    cout << "Enter filename containing two matrices: ";
    cin >> filename;
    fin.open(filename.c_str());
  } while (fin.fail());


  matrix A,B;
  fin >> A >> B;

  cout << "Matrix A was read as:" << endl;
  cout << A << endl;
  cout << "Matrix B was read as:" << endl;
  cout << B << endl;

  //  Let's try to determine all the possible ways that we can
  //  legally add/multiply the two operands.

  if (A.numRows() == 1 && A.numColumns() == 1) {
    // A is a scalar
    cout << "B + A as scalar arithmetic is..." << endl;
    cout << B + A(0,0) << endl;
	
    cout << "B * A as scalar arithmetic is..." << endl;
    cout << B * A(0,0) << endl;
  } else if (B.numRows() == 1 && B.numColumns() == 1) {
    // B is a scalar
    cout << "A + B as scalar arithmetic is..." << endl;
    cout << A + B(0,0) << endl;
	
    cout << "A * B as scalar arithmetic is..." << endl;
    cout << A * B(0,0) << endl;
  } else {
    // both are non-trivial
    if (A.numRows() == B.numRows() && A.numColumns() == B.numColumns()) {
      cout << "A + B is..." << endl;
      cout << A + B << endl;
    }

    if (A.numColumns() == B.numRows()) {
      cout << "A * B is..." << endl;
      cout << A * B << endl;
    }

    if (B.numColumns() == A.numRows()) {
      cout << "B * A is..." << endl;
      cout << B * A << endl;
    }

  }
}
