Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

In fraction.h file:

image text in transcribed

In fraction.cpp file:

image text in transcribed

#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

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

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions

Question

Identify four applications of HRM to healthcare organizations.

Answered: 1 week ago