Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this project we implement a simple class called the Rational class that can used to represent fractions. These objects hold an integer values that

In this project we implement a simple class called the Rational class that can used to represent fractions. These objects hold an integer values that may be be zero or above, but should not go negative Be sure to include the following members for Rational: a private member variables to hold the numerator and denominator values a default constructor an overloaded constructor that accepts two values for an initial fraction member functions add(), sub(), mul(), div(), less(), eq(), and neq(). a member function to return the current numerator and denominator. a member function that accepts an argument of type ostream that writes the fraction to that open output stream. Do not let either numerator or denominator stored value go negative. Display an error message on the user terminal if any of member functions try to force a negative count value. Test programs will vary. Here is a simple test program for the Rational class: The one member function I would add is a reduce member function. This function should compute the greatest common divisor (GCD) of the numerator and denominator, then divide each by this number. This will reduce the fraction to lowest common terms. If this is not done, the numerator and denominator can grow, possibly far enough to cause integer overflow for int variables. Sequence for writing the member functions: The idea here is Code in small increments then test. Write the constructors of several kinds. Write an access function for the real and imaginary parts to test the constructors. TEST. Write the less and neg functions. TEST If you plan to write the reduce function, do it now. TEST. Write the output and input member functions. TEST Write the arithmetic functions, one at a time, and call the reduce function after the these functions have done their work, before returning the caller. TEST.

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Gather internal and external data and prepare financial statements.

Answered: 1 week ago