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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 59 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 }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply