Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

7. Senior management supports the career system.

Answered: 1 week ago