diff --git a/src/models/money.cpp b/src/models/money.cpp index e4105d5..331915d 100644 --- a/src/models/money.cpp +++ b/src/models/money.cpp @@ -4,43 +4,35 @@ #include "money.h" -long long Budget::Models::Money::getDollars() const { return dollars; } +using namespace Budget::Models; -long long Budget::Models::Money::getCents() const { return cents; } +long long Money::getDollars() const { return dollars; } -Budget::Models::Money Budget::Models::operator+(const Budget::Models::Money &lhs, const Budget::Models::Money &rhs) { - long long total_cents = lhs.cents + rhs.cents; - long long total_dollars = lhs.dollars + rhs.dollars + total_cents / 100; +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}; } -Budget::Models::Money Budget::Models::operator-(const Budget::Models::Money &lhs, const Budget::Models::Money &rhs) { - long long total_cents = lhs.dollars * 100 + lhs.cents - rhs.dollars * 100 - rhs.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 Budget::Models::operator==(const Budget::Models::Money &lhs, const Budget::Models::Money &rhs) { - return lhs.dollars == rhs.dollars && lhs.cents == rhs.cents; +bool operator==(const Money &lhs, const Money &rhs) { + return lhs.getDollars() == rhs.getDollars() && lhs.getCents() == rhs.getCents(); } -bool Budget::Models::operator<(const Budget::Models::Money &lhs, const Budget::Models::Money &rhs) { - return lhs.dollars * 100 + lhs.cents < rhs.dollars * 100 + rhs.cents; +bool operator<(const Money &lhs, const Money &rhs) { + return lhs.getDollars() * 100 + lhs.getCents() < rhs.getDollars() * 100 + rhs.getCents(); } -bool Budget::Models::Money::operator>(const Budget::Models::Money &rhs) const { - return rhs < *this; -} - -bool Budget::Models::Money::operator<=(const Budget::Models::Money &rhs) const { - return !(rhs < *this); -} - -bool Budget::Models::Money::operator>=(const Budget::Models::Money &rhs) const { - return !(*this < rhs); -} - -std::ostream &operator<<(std::ostream &os, const Budget::Models::Money &money) { +std::ostream &operator<<(std::ostream &os, const Money &money) { os << "$" << money.getDollars() << "."; if (money.getCents() < 10) { os << "0"; diff --git a/src/models/money.h b/src/models/money.h index f62c1f7..cb180a2 100644 --- a/src/models/money.h +++ b/src/models/money.h @@ -26,12 +26,6 @@ namespace Budget::Models { friend bool operator==(const Money &lhs, const Money &rhs); friend bool operator<(const Money &lhs, const Money &rhs); - - bool operator>(const Money &rhs) const; - - bool operator<=(const Money &rhs) const; - - bool operator>=(const Money &rhs) const; private: long long dollars;