Question: Using C++: Files required: Rational.h, Rational.cpp, RationalTest.cpp (main in here) Implement a complete class named Rational for dealing with rational numbers. In mathematics, a rational

Using C++:

Files required: Rational.h, Rational.cpp, RationalTest.cpp (main in here)

Implement a complete class named Rational for dealing with rational numbers. In mathematics, a rational number is any number that can be expressed as the quotient or fraction p/q of two integers, a numerator p and a non-zero denominator q. Throw an invalid_argument exception if the denominator is 0.

1. Constructors that support the following usage.

Rational() // 0

Rational(1) // 1

Rational(22, 7) // 22 / 7

Rational(rational) // where rational is a Rational

2. Mutators and accessors:

+set(numerator: integer, denominator: integer) : void

+getNumerator(): integer

+getDenominator(): integer

3. Support the following operations: Rational r1, r2, r3; double x; int n;

a. r1 = r1.add(r2);

b. r3 = r1.add(n);

c. r1.equals(r2) d. x = r1.to_double();

e. r1.print(n); // output r1 to the console with n fractional digits. n >= 0, ex: 3.123324423424242342424324332424234

4. Provide a main function and illustrate the use of the class. MUST provide the definition and implementation files for the class. Do not use any inline implementations.

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!