-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMoney.h
36 lines (31 loc) · 908 Bytes
/
Money.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef __MONEY_H
#define __MONEY_H
#include <iostream>
class Bank;
class Money
{
public:
enum CURRENCY {USD, CHF, LAST_CURRENCY};
Money(int amount, CURRENCY currency) : m_amount(amount), m_currency(currency)
{}
CURRENCY currency() const {return m_currency;}
bool operator==(const Money &rhs) const
{return rhs.m_currency == m_currency && rhs.m_amount == m_amount;}
bool operator!=(const Money &rhs) const {return !(rhs == *this);}
Money times(int multiplier) {return Money(m_amount * multiplier, m_currency);}
friend std::ostream &operator<<(std::ostream &os, const Money &m);
private:
int m_amount;
CURRENCY m_currency;
friend class Bank;
};
inline std::ostream &operator<<(std::ostream &os, const Money &m)
{
switch (m.m_currency) {
case Money::USD: os << "$ "; break;
case Money::CHF: os << "CHF "; break;
}
os << m.m_amount;
return os;
}
#endif /* __MONEY_H */