Question: Write a rational number class. A rational number is a ratio - nal number, composed of two integers with division indicated. The division is not

Write a rational number class. A rational number is a "ratio-nal" number, composed of two integers with division indicated. The division is not carried out, it is only indicated, as in 12,23,1532,654,165. You should represent rational numbers by two int values, numerator, and denominator.
A principle of abstract data type (ADT) construction is that constructors must be present to create objects with any legal values. You should provide constructors to make objects out of pairs of int values; this is a constructor with two int parameters. Since every int is also a rational number, as in 21 or 171, you should provide a constructor with a single int parameter. Also include a default constructor that initializes an object to 0(that is, to 01).
Overload the input and output operators >> and . Numbers are to be input and output in the form 12,1532,300401, and so forth. Note that the numerator, the denominator, or both may contain a minus sign, so -12,1532, and -300/-401 are also possible inputs. (Input/output operators can be used on any input/output stream)
Overload all the following operators so that they correctly apply to the type Rational: ==,,,>,,,+,-,**, and ??. Also overload the unary -. The following equations show how rational number algebra is performed.Testing the Code:In the main function, generate many test cases for the rational numbers class.Declare at least two objects that would represent two rational numbers. Let the user input the object values from any input stream. Test the two objects with each of the overloaded functions. Also test the operators with a combination of integers and objects.
Some samples than can test the integrity of your code are:
Division by zeros, i.e.30,-50
Zero by itself 00
Zeros in the numerator 03,0-3
Negative numerator and/or denominator -3-8,-38,3-8
Solid integers, 8,-2,0,-1
 Write a rational number class. A rational number is a "ratio-nal"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!