properly seperated deffs of money
This commit is contained in:
parent
badf4f17d0
commit
0639383836
@ -4,43 +4,35 @@
|
|||||||
|
|
||||||
#include "money.h"
|
#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 Money::getCents() const { return cents; }
|
||||||
long long total_cents = lhs.cents + rhs.cents;
|
|
||||||
long long total_dollars = lhs.dollars + rhs.dollars + total_cents / 100;
|
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;
|
total_cents = total_cents % 100;
|
||||||
return {total_dollars, total_cents};
|
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)};
|
return {total_cents / 100, std::abs(total_cents % 100)};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Budget::Models::operator==(const Budget::Models::Money &lhs, const Budget::Models::Money &rhs) {
|
bool operator==(const Money &lhs, const Money &rhs) {
|
||||||
return lhs.dollars == rhs.dollars && lhs.cents == rhs.cents;
|
return lhs.getDollars() == rhs.getDollars() && lhs.getCents() == rhs.getCents();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Budget::Models::operator<(const Budget::Models::Money &lhs, const Budget::Models::Money &rhs) {
|
bool operator<(const Money &lhs, const Money &rhs) {
|
||||||
return lhs.dollars * 100 + lhs.cents < rhs.dollars * 100 + rhs.cents;
|
return lhs.getDollars() * 100 + lhs.getCents() < rhs.getDollars() * 100 + rhs.getCents();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Budget::Models::Money::operator>(const Budget::Models::Money &rhs) const {
|
std::ostream &operator<<(std::ostream &os, const Money &money) {
|
||||||
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) {
|
|
||||||
os << "$" << money.getDollars() << ".";
|
os << "$" << money.getDollars() << ".";
|
||||||
if (money.getCents() < 10) {
|
if (money.getCents() < 10) {
|
||||||
os << "0";
|
os << "0";
|
||||||
|
@ -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);
|
||||||
|
|
||||||
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:
|
private:
|
||||||
long long dollars;
|
long long dollars;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user