Reference no: EM1318299
Build a class known as Rational for carrying out the arithmetic with fractions. Write down a driver program in order to test your class.
Utilize the integer variables in order to represent private instance variables of the class—the numerator and the denominator. Provide a constructor method that allows an objet of this class to be initialized at the time it is declared. The constructor must store fraction in decreased form (that is, the fraction 2/4 would be stored within the object as 1 in the numerator and 2 in the denominator). Give a no argument constructor with the default values in case no initializes are offered. Give public methods for each of the following:
a) Addition of the two Rational numbers. Result of addition must be stored in reduced form.
b) Subtraction of the two Rational numbers. The result of subtraction must be stored in reduced form.
c) Multiplication of the two Rational numbers. The result of multiplication should be stored in reduced form.
d) Division of the two Rational numbers. The result of division must be stored in reduced form.
e) Printing Rational numbers in form a/b, where a is the numerator and b is the denominator.
f) Printing the Rational numbers in floating-point format. (Consider providing the formatting capabilities which allow the user of class to specify number of digits of precision to the right of the decimal point.)