Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started