Post-Lab - Lab (6) - A Rational Number Class



Write a C++ program that conducts the rational number operations.  Your program will use a rational number class to perform the addition, subtraction, multiplication, and division operations on two fractions.  You are required to write this class as part of this assignment.  For now, assume that the user will enter the numerator and the denominator of the first fraction, followed by those for the second fraction.

You need to use constructors for:
    1) correctly initializing variable members, and
    2) creating objects with given initial values.  Note that a fraction may have both a numerator and a denominator, for example: (8/3), or may simply be a number, for example: 6, in which case you will actually use (6/1) to represent it.  Thus, the constructors with two and one arguments should be included in the class definition.

Your class will have a function for each one of the four operations.  For example: Suppose we have defined objects a and b as two fractions, then to compute a + b, we will use:

a.add(b);

When you conduct an operation, you do not have to simplify the result, i.e., 4/5 * 5/10 = 20/50.

Here are some of the rules you may need:
a/b + c/d = (a*d + b*c) / (b*d)
a/b - c/d = (a*d - b*c) / (b*d)
(a/b) * (c/d) = (a*c) / (b*d)
(a/b) / (c/d) = (a*d) * (c*b)

A more complicated version of this program is listed at the end of Chapter (6) - Problem 9.