Write a Fraction class that overloads the arithmetic operators (+, -, *, /). Minimally, your fraction class should include the following methods that behave as directed:
This is a default constructor for the fraction class. It should load a value of 1 into the denominator and a value of 0 into the numerator
Fraction(int numerator, int denominator)
This is an overloaded version of the constructor. It accepts inputs for the numerator and denominator and creates a fraction that starts out with those values. Be mindful to sanitize the input to ensure a zero is not loaded into the denominator.
This is a getter method for the numerator.
This is a setter method for the numerator.
This is a getter method for the denominator.
This is a setter method for the denominator. Ensure the user enters valid values for this (no zeros allowed!).
This method should reduce the contents of the fraction. The resultant fraction should be an equivalent, improper fraction in lowest terms (no mixed numbers).
Fraction operator+(Fraction addMe)
This method implements behavior for the addition operator. Your driver should clearly demonstrate the use of this operator.
Fraction operator-(Fraction subtractMe)
This method implements behavior for the subtraction operator. Your driver should clearly demonstrate the use of this operator.
Fraction operator*(Fraction multiplyMe)
This method implements the behavior for the subtraction operator. Your driver should clearly demonstrate the use of this operator.
Fraction operator/(Fraction divideMe)
This method implements behavior for the division operator. Your driver should clearly demonstrate the use of this operator.
Remember to call your reduction method every time you perform an operator on a fraction. This will ensure that the resultant Fraction is in lowest terms.
Remember to sanitize inputs for your Fractions. A denominator of zero should never be allowed at anytime. If the client code attempts to load a zero into a denominator, you should print a message informing the user that this has occurred. Additionally, you should make a decision about the action the program takes in terms of picking a value to assign to the denominator when such an errors occurs. The best course of action is probably to change nothing and just display a message to the user.
Write a Review
Leave a reply Cancel reply
Ask Your Question
We have verified professionals who are ready to answer your question.
Save Time and Money
We choose experts who can quickly answer your question and that suit your budget.
Get Your Answer
Your satisfaction is 100% guaranteed. You can keep on asking questions until you get the answer you need.