Example #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));
}
Example #2
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;
}
Example #3
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 << "|";
}
Example #4
0
Number operator/( Number l, Number r)
{
	Number inverse(r.denominator(), r.numerator());	
	return l*inverse;
}
Example #5
0
bool operator==( Number l, Number r ) { 
    return (l.numerator() == r.numerator() && l.denominator() == r.denominator());
}
Example #6
0
// copy constructor
Number::Number(const Number &c) :
	num(c.numerator()), denom(c.denominator())
{}