Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write in C++ (30) 2. Given the ADT Rational specification below design, implement, and test the member functions that perform arithmetic with fractions. Ensure that

write in C++
image text in transcribed
(30) 2. Given the ADT Rational specification below design, implement, and test the member functions that perform arithmetic with fractions. Ensure that the fractions are always stored in reduced form using the private member function reducel), e.g., if the fraction 21/30 is created either by a constructor or another member function, it should be stored as 7/10 (numerator/denominator).printRationalAsReal() should output a double value. Example output is given below (Rational bc6, 8); results in 3/4 being stored). 1/ catigoal.ch #ifndef. RATIONAL_H #define RATIONAL_H class Rational private: int numerator; Sell integer numerator int denominator; // integer denominator void reduce(); // reduces fraction to lowest form public: Rational(int = 0, int = 1); // stor Rational add(const Rational &); // addition function Rational subtract(const Rational &); // subtraction function Rational multiply(const Rational &); // multiplication function Rational divide(const Rational &); // division function void rcintRationall) const; // print rational format void rcintRationalAsBeall) const; // print rational as double }; // end Rational #endif 1* Example output: Testing class Rational 7/11 + 3/4 = 61/44 61/44 = 1.38636 7/11 - 3/4 = -5/44 -5/44 = -0.113636 7/11 * 3/4 - 21/44 21/44 = 0.477273 7/11 / 3/4 = 28/33 28/33 = 0.848485

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

Strong analytical, communication, and problem-solving skills

Answered: 1 week ago