PDA

View Full Version : Rational



melina
چهارشنبه 05 بهمن 1384, 17:43 عصر
Create a class called Rational for performing arithmetic with fractions. Write a program to test your class
use integer variables to represent the private data of the class __ the numerator and the denominator . provide a constructor that enables an object of this class to be initialized when it is declared . the constructor should contain default valurs in case no initializers are provided and should store the fraction in reduced from . for example , the fraction 2/4 would be stored in the object as 1 in the numerator and 2 in the denominator . provide public member functions that perform each of the following tasks : a) adding two Rational numbers . the result should be stored in reduced form . b) subtracting two Rational numbers. the result should be stored in reduced form . c) multiplying teo Rational numbers. The result should be stored in reduced form. d) dividing two Rational numbers the result should be stored in reduced form . e) printing Rational numbers in the form a/b where a is the numerator and b is the denominator. f) printing Rational numbers in floating- point format