QuestionQuestion

Imagine that the company you work for is going to create a lot of tutorials on Fractions. You are to create a robust Fraction class that will have all of the following (all examples are for a fraction half that has a numerator of 1 and a denominator of 2):
- Private integers numerator and denominator ;
- All public getter and setter functions for the numerator and denominator;
- Safeguard that the denominator will NEVER become 0!
- a default constructor with no arguments;
- a constructor that accepts both the numerator and denominator;
- a toDecimal method that returns the decimal value of the fraction, example: 1/2 will be 0.5;
- a toString method that will return the fraction as a string, example: 1/2 will be "1/2";
- a reduce method that will change the numerator and denominator by finding a common denominator and reducing the fraction. Example 3/12 becomes 1/4;

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include "Fraction.h"

Fraction::Fraction() {
    numerator = 0;
    denominator = 1;
}

Fraction::Fraction(int numerator, int denominator){
    setNumerator(numerator);
    setDenominator(denominator);
}

Fraction::~Fraction() {
}

void Fraction::setDenominator(int denominator) {
    // denominator cannot be zero
    if (denominator == 0) {
       this->denominator = 1;
    }
    else{
       this->denominator = denominator;
    }
}...
$15.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats