Question: Your task in this homework assignment is to add three constructors to the Fraction class. The fraction class stores a numerator and denominator. Member functions

Your task in this homework assignment is to add three constructors to the Fraction class.

The fraction class stores a numerator and denominator. Member functions allow for retrieval of the

fraction as a double and another outputs the value in lowest terms.

## Solution Specifications

Your solution to this problem must meet the following criteria.

1. Write a default constructor that creates a fraction with the value of one.

2. Write a custom constructor that takes one integer as an argument to be used as the denominator.

3. Write a second custom constructor that takes two integer as arguments to be used as the numerator and denominator.

In C++ Programming language:

In main.cpp file:

 Your task in this homework assignment is to add three constructors

In fraction.h file:

to the Fraction class. The fraction class stores a numerator and denominator.

In fraction.cpp file:

Member functions allow for retrieval of the fraction as a double and

#include "Fraction.h" #include 13 using namespace std; 15 int main() { // Some test fractions Fraction fo; cout #include using namespace std; 18 class Fraction { public: // TODO Add fraction constuctors here double getDouble(); void outputReducedFraction(); 26 private: int numerator; int denominator; // Finds greatest common divisor of numerator and denominator int god(); }; 28 29 30 #include "Fraction.h" using namespace std; // ====================== // Fraction::Fraction // Constructors for the fraction class 18 // ====================== // TODO Add fraction constuctors here // ====================== // Fraction::getDouble // Returns the fraction's value as a double // ====================== double Fraction::getDouble() { return (static_cast(numerator) / denominator); } 29 31 33 34 35 36 // ===================== // Fraction::outputReduced Fraction // Reduces the fraction and outputs it to the console. // ====================== void Fraction::outputReducedFraction() { int g; 40 g = ged(); cout denominator) { g = denominator; } else { g = numerator; // Work down to 1, testing to see if both numerator and denominator // can be divided by g. If so, return it. while (g > 1) { if (((numerator % g) == 0) && ((denominator % g) == 0)); return gi g--; return 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!