CIS 3020 Project 2
Background
In this assignment you will perform basic arithmetic operations with rational numbers (x/y). Many fractional numbers cannot be represented exactly. For example, the value 1/3 as a real number is 0.333333333... At some point we must stop writing 3s, which results in a roundoff error. A similar problem exists with many fraction numbers inside a computer. To alleviate this problem, we can represent these numbers as rationals. A rational number maintains the numerator and denominator as separate integer values, never performing the division. Since integers are represented exactly, no roundoff errors occur.
In this assignment you are to implement the basic arithmetic operations of addition, subtraction, multiplication, and division. The output of the operations must also be in the form of a rational number. The operations are performed as illustrated below:
Addition
x1 x2 (x1*y2) + (x2*y1) ---- + ---- = ------------------- y1 y2 (y1*y2)
For example:
1/2 + 2/3 = 7/6
Subtraction
x1 x2 (x1*y2) - (x2*y1) ---- - ---- = ------------------ y1 y2 (y1*y2)
For example:
2/3 - 1/2 = 1/6
Multiplication
x1 x2 (x1*x2) ---- * ---- = --------- y1 y2 (y1*y2)
For example:
1/2 * 2/3 = 2/6
Division
x1 x2 (x1*y2) ---- / ---- = --------- y1 y2 (y1*x2)
For example:
1/2 / 2/3 = 3/4