The Money class is used to allow operations on Money. More...
#include <Money.h>
Public Member Functions | |
Money () | |
Default constructor for the Money class. More... | |
Money (double m) | |
Constructor for the Money class based on a double. More... | |
Money (int d, int c) | |
Constructor for the Money class based on two integers. More... | |
Money (const string &s) | |
Constructor for the Money class based on a string. More... | |
Money | operator- () const |
Overloads the - operator for the Money class. More... | |
Money | operator+ (const Money &m) const |
Overloads the + operator for the Money class. More... | |
Money | operator- (const Money &m) const |
Overloads the - operator for the Money class. More... | |
Money | operator* (double val) const |
Overloads the * operator for the Money class. More... | |
Money | operator/ (double m) const |
Overloads the / operator for the Money class. More... | |
Money | operator/ (Money &m) const |
Overloads the / operator for the Money class. More... | |
bool | operator== (const Money &m) const |
Overloads the == operator for the Money class. More... | |
Static Public Member Functions | |
static Money | power (Money &m, int exp) |
Implements the power function for the Money class. More... | |
static double | power (double d, int exp) |
Helper function for the power function of the Money class. More... | |
static double | toDouble (const Money &m) |
Converts a Money object to a double value. More... | |
static string | toString (const Money &m1) |
Converts a Money object to a string. More... | |
Friends | |
ostream & | operator<< (ostream &out, const Money &m) |
Overloads the << operator for the Money class. More... | |
The Money class is used to allow operations on Money.
This class overloads the basic arithmetic operators, allowing for operations to be performed on a monetary value. This class also serves as a basis for several other classes, allowing them to inherit from this class so that Money objects may be returned by functions belonging to other classes.
Money::Money | ( | ) |
Default constructor for the Money class.
|
explicit |
Constructor for the Money class based on a double.
Constructs a money object from a double value.
m | A monetary value given as a double. |
Money::Money | ( | int | d, |
int | c | ||
) |
Constructor for the Money class based on two integers.
d | The dollar amount as an integer. |
c | The cent amount as an integer. |
|
explicit |
Constructor for the Money class based on a string.
Parses a string and splits the value at the decimal into dollars and cents. If there is no decimal, the dollar amount is whatever the string is, and cents will be 0.
s | The string containing the monetary value. |
Money Money::operator* | ( | double | val | ) | const |
Money Money::operator- | ( | ) | const |
Money Money::operator/ | ( | double | m | ) | const |
Overloads the / operator for the Money class.
This allows for the division of Money objects.
m | The value to divide the current Money object by. |
bool Money::operator== | ( | const Money & | m | ) | const |
|
static |
Helper function for the power function of the Money class.
d | The monetary value. |
exp | The exponent. |
|
static |
|
static |
|
friend |