Implement an immutable data type Rational for rational numbers that supports addition, subtraction, multiplication, and division. public class Rational: Rational(int numerator. int denominator) Rational plus(Rational b) sum of this number and b Rational minus(Rational b) difference of this number and b Rational times(Rational b) product of this number and b Rational divides(Rational b) quotient of this number and b boolean equals(Rational that) is this number equal to that ? String toString() string representation You do not have to worry about testing for overflow, but use as instance variables two long values that represent the numerator and denominator to limit the possibility of overflow. Use Euclid’s algorithm  to ensure that the numerator and denominator never have any common factors. Include a test client that exercises all of your methods.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter13: Overloading And Templates
Section: Chapter Questions
Problem 20PE
icon
Related questions
Question

Implement an immutable data type Rational for rational numbers that supports addition, subtraction, multiplication, and division. public class Rational:


Rational(int numerator. int denominator)
Rational plus(Rational b) sum of this number and b
Rational minus(Rational b) difference of this number and b
Rational times(Rational b) product of this number and b
Rational divides(Rational b) quotient of this number and b
boolean equals(Rational that) is this number equal to that ?
String toString() string representation


You do not have to worry about testing for overflow, but use as instance variables two long values that represent the numerator and denominator to limit the possibility of overflow. Use Euclid’s algorithm  to ensure that the numerator and denominator never have any common factors. Include a test client that exercises all of your methods.

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning