Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A. Implement the Rational class. B. Overload the operator [] so that a Rational object can access to the numerator and the denominator in the

image text in transcribed

A. Implement the Rational class.

B. Overload the operator [] so that a Rational object can access to the numerator and the denominator in the same manner as array. Also, it allows assigning values to the numerator and the denominator. For instance if we have a Rational object Rational r(3,4),then we can access the numerator by using r[0], and we can change the numerator by using r[0] = 9.

C. In part B, we overload the [] operator. If the subscript is neither 0 nor 1, the function throws a runtime_error exception. Define a custom exception called IllegalSubscriptException and let the function operator throw an IllegalSubscriptException if the subscript is neither 0 nor 1. Write a test program with a try-catch block to handle this type of exception.

Rationa -numerator: int -denominator: int +RationalO +Rational (numerator: int, The numerator of this rational number The denominator of this rational number Creates a rational number with numerator 0 and denominator 1 Creates a rational number with specified numerator and denominator: int) +getNumeratorO: int const +getDenominatorO: int const +add(secondRational: Rational): Returns the addition of this rational with another. denominator Returns the numerator of this rational number Returns the denominator of this rational number Rationalconst +subtract(secondRational: +multiply(secondRational: +divide(secondRational: +compareTo(secondRational: Returns the subtraction of this rational with another Rational):Rational const Returns the multiplication of this rational with another Rational): Rationalconst Returns the division of this rational with another Rational): Rationalconst Returns an int value -1,0, or 1 to indicate whether this rational Rational): int const number is less than, equal to, or greater than the specified number +equals(secondRational: Returns true if this rational number is equal to the specified number Rational): bool const +intValueO: int const +doubleValueO: double const +toStringO: string const Returns the numerator/denominator Returns the 1.0numerator/denominator Returns a string in the form "numeratorI denominator." Returns numerator if denominator is 1 -gcd(n: int, d: int): int Returns the greatest common divisor between n and d

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

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

=+a. The stock market declines sharply, reducing consumers wealth.

Answered: 1 week ago