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 "rational" number, composed of two integers with division indicated. The division is not carried out, it is only indicated, as in 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 or you should provide a constructor with a single int parameter. Also include a default constructor that initializes an object to that is to
Overload the input and output operators and Numbers are to be input and output in the form and so forth. Note that the numerator, the denominator, or both may contain a minus sign, so and are also possible inputs. Inputoutput operators can be used on any inputoutput 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.
means
means
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, ie
Zero by itself
Zeros in the numerator
Negative numerator andor denominator
Solid integers,
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
