Page 1 of 1

Below is Fraction.h which has the declaration of the Fraction class. The Fraction class stores rational fractions with a

Posted: Sun May 15, 2022 12:34 pm
by answerhappygod
Below Is Fraction H Which Has The Declaration Of The Fraction Class The Fraction Class Stores Rational Fractions With A 1
Below Is Fraction H Which Has The Declaration Of The Fraction Class The Fraction Class Stores Rational Fractions With A 1 (67.67 KiB) Viewed 60 times
Below is Fraction.h which has the declaration of the Fraction class. The Fraction class stores rational fractions with a numerator and denominator. Fraction.h: 1 2 4 5 6 7 S class Fraction { private: int num, den; // member variables public: // constructor Fraction(int n, int d = 1) { num = n; den d; } // operator overloads Fraction operator+(const Fraction rhs); friend Fraction operator+(const Fraction lhs, const Fraction rhs); friend ostream& operator<<(ostream& out, const Fraction a); }; Define the three operator overloads declared above (+, *, <<) in Fraction.cpp below. 9 10 11 12 13 14 Fraction.cpp: int main() { Fraction a(5, 8); Fraction b(4, 9); cout << (a * b) << endl; // prints 20/72 cout << (a + b) << endl; // prints 76/72 }