Esempio n. 1
0
void initializeArrayStrings(Array2D<T> &boo)
{
	for (int i = 0; i < boo.getRow(); i++)
	{
		for (int j = 0; j < boo.getColumn(); j++)
		{
			boo[i][j] = to_string(i + j);
		}
	}
}
Esempio n. 2
0
void initializeArrayInts(Array2D<T> &boo)
{
	for (int i = 0; i < boo.getRow(); i++)
	{
		for (int j = 0; j < boo.getColumn(); j++)
		{
			boo[i][j] = i + j;
		}
	}
}
Esempio n. 3
0
void printArray(const Array2D<T> &boo)
{
	for (int i = 0; i < boo.getRow(); i++)
	{
		for (int j = 0; j < boo.getColumn(); j++)
		{
			cout << boo[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}
Esempio n. 4
0
void print(Array2D<T> myArray)
{
	for (int i = 0; i < myArray.getRow(); i++)
	{
		for (int j = 0; j < myArray.getColumn(); j++)
		{
			cout << myArray.Select(i, j) << " ";
		}

		cout << endl;
	}
}
Esempio n. 5
0
void testInts()
{
	cout << "Testing with a simple data type: integers" << endl;
	cout << "First, we'll test the constructors:" << endl;

	cout << "Testing the default constructor, row and column should = 0)" << endl;
	Array2D<int> blob;
	cout << "Rows: " << blob.getRow() << " Columns: " << blob.getColumn() << endl << endl;

	cout << "Testing the constructor with both rows and columns defined at initialization: " << endl;
	Array2D<int> boo(3, 5);
	cout << "Rows: " << boo.getRow() << " Columns: " << boo.getColumn() << endl << endl;

	cout << "Testing subscript operators with valid input: " << endl;
	initializeArrayInts(boo);
	printArray(boo);

	cout << "Testing copy constructor: " << endl;
	Array2D<int> bo(boo);
	cout << "Rows: " << bo.getRow() << " Columns: " << bo.getColumn() << endl << endl;
	printArray(bo);

	cout << "Testing the assignment operator: " << endl;
	blob = bo;
	cout << "Rows: " << blob.getRow() << " Columns: " << blob.getColumn() << endl << endl;
	printArray(blob);

	cout << "Now testing mutator functions for both rows and columns: " << endl << endl;
	cout << "First with adding rows: " << endl;
	boo.setRow(6);
	cout << "Rows: " << boo.getRow() << " Columns: " << boo.getColumn() << endl << endl;
	initializeArrayInts(boo);
	printArray(boo);

	cout << "Now deleting rows: " << endl;
	boo.setRow(3);
	cout << "Rows: " << boo.getRow() << " Columns: " << boo.getColumn() << endl << endl;
	printArray(boo);

	cout << "Now passing an invalid row length: " << endl;
	try
	{
		boo.setRow(-1);
	}
	catch (Exception &except)
	{
		cout << except << endl << endl;
	}

	cout << "Now adding columns (maintains data position in current rows/columns): " << endl;
	boo.setColumn(7);
	cout << "Rows: " << boo.getRow() << " Columns: " << boo.getColumn() << endl << endl;
	printArray(boo);

	cout << "Now deleting columns (maintains data position in current rows/columns which are being kept): " << endl;
	boo.setColumn(5);
	cout << "Rows: " << boo.getRow() << " Columns: " << boo.getColumn() << endl << endl;
	printArray(boo);

	cout << "Now passing invalid value for column: " << endl;
	try
	{
		boo.setColumn(-1);
	}
	catch (Exception &except)
	{
		cout << except << endl << endl;
	}
	cout << "Rows: " << boo.getRow() << " Columns: " << boo.getColumn() << endl << endl;
	printArray(boo);

	cout << "Testing subscipt operator access on a const object: " << endl;
	const Array2D<int> const_boo(boo);
	printArray(const_boo);

}
Esempio n. 6
0
Array2D<T>::Array2D(const Array2D<T> &copy) : m_array(copy.getRow() * copy.getColumn()), m_row(copy.getRow()), m_col(copy.getColumn())
{
	m_array = copy.m_array;
}