MAIN MENU          BIODATA              ASSIGNMENTS                TUTORIALS                EMAILS

 

Object-Oriented Systems Development (TCS 2064)

TUTORIAL 3

QUESTION:

Create a class named Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class. The numerator and the denominator. Provide a constructor that enables an object of the class to be initialized when it is declared. The constructor should stop the fraction in reduced form. The fraction 2/4 is equivalent to ½  and would be in the object as 1 in the numerator and 2 in the denominator. Provide a no-argument constructor with default values in class no initializers are provided. Provide public method that perform each of the following:

a)      Add a + b to rational numbers. The result should be stored in reduced form.

b)      Subtract – result a – b in reduced form.

c)      Multiply - a * b in reduced form

d)      Division – a/b in reduced form

e)      Print rational number in the form a/b, a = numerator, b = denominator

f)        Print rational number in floating point format.