OO . , , . , , , ( ).
, , . , , . , , , . , , .
( ++, ):
class Rational {
int numerator; int denominator;
public:
Rational (int x, int y) {
if (y == 0) { throw DivisionByZero; }
assert (y != 0);
if (y<0) { x = -x; y = -y; }
assert (y>0);
int d = gcd(x,y);
assert(d>0);
assert (x % d == 0);
assert (y % d == 0);
numerator = x/d;
denominator = y/d;
}
bool eq(Rational other) {
numerator == other.numerator && denominator == other.denominator;
}
}:
, , , , . , . , . , .
:
R: int * int - { x,y | y<0 or Exists d. d divides y and d divides x }
, , R ,
R < == > A
A - , .
: . , , , OO, , , , , , ( ββ, ).
- , , , .
Yttrill: ..dont!
, !