Exemplo n.º 1
0
bool operator<(Number l, Number r)
{
	int lnum = l.numerator();
	int lden = l.denominator();
	int rnum = r.numerator();
	int rden = r.denominator();
	if (lnum < 0 && rnum >= 0)
		return true;
	if (rnum <= 0 && lnum >=0)
		return false;
	return operatorHelper(abs(lnum), abs(lden), abs(rnum), abs(rden));
}
Exemplo n.º 2
0
Matrix Matrix::operator-()
{
	Matrix negate(rows,cols);
	for (int i = 0; i < rows; i++)
	{
		for (int j = 0; j < cols ; j++)
		{
			Number num = at(i).at(j);
			num.numerator( -1*(num.numerator()) );
		}	
	}
	return negate;
}
Exemplo n.º 3
0
Number operator*( Number l, Number r)
{
	int lnum = l.numerator();
	int lden = l.denominator();
	int rnum = r.numerator();
	int rden = r.denominator();
	// cross factor
	int factor1 = gcdFunction(lnum, rden);
	int factor2 = gcdFunction(rnum, lden);

	lnum /= factor1;
	rden /= factor1;
	rnum /= factor2;
	lden /= factor2;

	Number prod(lnum*rnum, rden*lden);
	return prod;
}
Exemplo n.º 4
0
void Matrix::printRowAt(int row)
{
	cout << "|";
	for (int j = 0; j < at(row).size() ; j++)
	{
		Number num = at(row).at(j);
		// if positive
		if (num >= Number())
		{
			cout << " ";
		}
		// if whole number
		if (num.denominator() == 1)
		{
			cout << "   " << num.numerator() << " ";
		}
		else
		{
			cout << " " << num << " ";
		}
	}
	cout << "|";
}
Exemplo n.º 5
0
Number operator/( Number l, Number r)
{
	Number inverse(r.denominator(), r.numerator());	
	return l*inverse;
}
Exemplo n.º 6
0
bool operator==( Number l, Number r ) { 
    return (l.numerator() == r.numerator() && l.denominator() == r.denominator());
}
Exemplo n.º 7
0
// copy constructor
Number::Number(const Number &c) :
	num(c.numerator()), denom(c.denominator())
{}