#include <iostream>
#include <fstream>
#include <string>

using namespace std;

template <typename T>
class TwoDArray {
  private:
    T** theArray;
    int numRows;
    int numCols;
    T defSpace;

  public:
    TwoDArray<T> (int r, int c, T def);
    ~TwoDArray<T>();
    void insert(int r, int c, T value);
    T access(int r, int c);
    void remove(int r, int c);
    void print();
    int getNumRows();
    int getNumCols();
};

//initializes the 2D Array
template <typename T>
TwoDArray<T>::TwoDArray(int r, int c, T def) {
  numRows = r;
  numCols = c;
  defSpace = def;
  theArray = new T*[r];
  for(int i=0; i<r; i++) {
    theArray[i] = new T[c];
  }
  //sets all values to the default
  for(int i=0; i<r; i++) {
    for(int j=0; j<c; j++) {
    theArray[i][j] = defSpace;
    }
  }
}

//deletes the 2D Array
template<typename T>
TwoDArray<T>::~TwoDArray() {
  for(int i=0; i<numRows; i++) {
    delete[] theArray[i];
  }
  delete[] theArray;
}

//inserts value v at row r and column c
template<typename T>
void TwoDArray<T>::insert(int r, int c, T value) {
  theArray[r][c] = value;
}

//get value at row r, column c
template<typename T>
T TwoDArray<T>::access(int r, int c) {
  T result = theArray[r][c];
  return result;
}

//set value at row r and column c back to default
template<typename T>
void TwoDArray<T>::remove(int r, int c) {
  theArray[r][c] = defSpace;
}

//print the 2D Array
template<typename T>
void TwoDArray<T>::print() {
  for(int i=0; i<numRows; i++) {
    for(int j=0;j<numCols; j++) {
      std::cout << theArray[i][j];
      std::cout << " ";
    }
    std::cout << std::endl;
  }
}

//gets number of rows for test
template<typename T>
int TwoDArray<T>::getNumRows() {
  return numRows;
}

//gets number of columns for test
template<typename T>
int TwoDArray<T>::getNumCols() {
  return numCols;
}
int main()
{
    TwoDArray<std::string>* s = new TwoDArray<std::string>(5, 5, "o");

    s->insert(0, 2, "North");
    s->insert(4, 2, "South");
    s->insert(2, 4, "East");
    s->insert(2, 0, "West");
    s->print();

    delete s;

    return 0;
}
