// // Created by quentin on 2/5/23. // #include "money.h" using namespace Budget::Models; long long Money::getDollars() const { return dollars; } long long Money::getCents() const { return cents; } Money operator+(const Money &lhs, const Money &rhs) { long long total_cents = lhs.getCents() + rhs.getCents(); long long total_dollars = lhs.getDollars() + rhs.getDollars() + total_cents / 100; total_cents = total_cents % 100; return {total_dollars, total_cents}; } Money operator-(const Money &lhs, const Money &rhs) { long long total_cents = lhs.getDollars() * 100 + lhs.getCents() - rhs.getDollars() * 100 - rhs.getCents(); return {total_cents / 100, std::abs(total_cents % 100)}; } bool operator==(const Money &lhs, const Money &rhs) { return lhs.getDollars() == rhs.getDollars() && lhs.getCents() == rhs.getCents(); } bool operator<(const Money &lhs, const Money &rhs) { return lhs.getDollars() * 100 + lhs.getCents() < rhs.getDollars() * 100 + rhs.getCents(); } std::ostream &operator<<(std::ostream &os, const Money &money) { os << "$" << money.getDollars() << "."; if (money.getCents() < 10) { os << "0"; } os << money.getCents(); return os; }