/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ /* * File: Fraction.cpp * Author: jcmtiernan * * Created on June 10, 2017, 8:32 PM */ #include "Fraction.h" Fraction::Fraction() { Setnum(0); Setdenom(1); } Fraction::Fraction(int n) { Setnum(n); Setdenom(1); } Fraction::Fraction(int n, int d) { Setnum(n); // num = n; Setdenom(d); // denom = d; } Fraction::Fraction(const Fraction& orig) // what needs to be added to Fraction.h? { Setnum(orig.num); Setdenom(orig.denom); } bool Fraction::Setdenom(int val) { if (val > 0) { this->denom = val; return true; } else if (val == 0) { denom = 1; return false; } else { // val < 0 Setnum(this->Getnum() * -1); Setdenom(val * -1); return true; } } Fraction Fraction::SetFrac(int n, int d) { this->Setnum(n); this->Setdenom(d); return *this; } double Fraction::DecimalFrac() { return (double)num/(double)denom; } Fraction Fraction::MultiplyFraction(Fraction fracB) { Fraction product(0,1); product.Setnum(this->Getnum() * fracB.Getnum()); product.Setdenom(this->Getdenom() * fracB.Getdenom()); return product; } int Fraction::CommonDenom(int denomB) // value = frac1.CommonDenom(frac2.Getdenom()); { int unify = 0; int denomA = this->Getdenom(); unify = (denomA * denomB); return unify; } int Fraction::compareto(Fraction fracB) { int first = (this->Getnum()) * fracB.Getdenom(); int second = this->Getdenom() * fracB.Getnum(); if (first > second) {return 1;} else if (first == second) {return 0;} else {return -1;} } /* * Add two Fractions and return the sum as a Fraction * Use the CommonDenom function above for this problem */ /* * Divide invoking Fraction by parameter Fraction. Use multiplication function * to accomplish this */ /* * Convert improper fraction to mixed number. You will need to create a class * for representing the mixed number. */ Fraction::~Fraction() { }