Answered step by step
Verified Expert Solution
Link Copied!

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 "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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Multimedia Database Systems

Authors: V.S. Subrahmanian

1st Edition

1558604669, 978-1558604667

More Books

Students also viewed these Databases questions

Question

What is the difference between probability and statistics

Answered: 1 week ago