Personal Finance 1.0.0
An application that allows you to track/store/view finances, as well as calculate different financial values.
Money Class Reference

The Money class is used to allow operations on Money. More...

#include <Money.h>

Inheritance diagram for Money:
Account Expense Formulas Income

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...
 

Detailed Description

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.

Author
Dawson Dauphinais

Constructor & Destructor Documentation

◆ Money() [1/4]

Money::Money ( )

Default constructor for the Money class.

◆ Money() [2/4]

Money::Money ( double  m)
explicit

Constructor for the Money class based on a double.

Constructs a money object from a double value.

Parameters
mA monetary value given as a double.
Author
Dawson Dauphinais

◆ Money() [3/4]

Money::Money ( int  d,
int  c 
)

Constructor for the Money class based on two integers.

Parameters
dThe dollar amount as an integer.
cThe cent amount as an integer.
Author
Dawson Dauphinais

◆ Money() [4/4]

Money::Money ( const string &  s)
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.

Parameters
sThe string containing the monetary value.
Author
Dawson Dauphinais

Member Function Documentation

◆ operator*()

Money Money::operator* ( double  val) const

Overloads the * operator for the Money class.

This allows for multiplication of Money objects.

Attention
This may cause precision errors. It is unlikely, but not impossible.
Parameters
valThe value to multiply the Money object by.
Returns
A Money object containing the result of the multiplication.
Author
Dawson Dauphinais

◆ operator+()

Money Money::operator+ ( const Money m) const

Overloads the + operator for the Money class.

This allows for addition of Money objects.

Parameters
mA Money object to be added to the current Money object.
Returns
A Money object containing the result of the addition.
Author
Dawson Dauphinais

◆ operator-() [1/2]

Money Money::operator- ( ) const

Overloads the - operator for the Money class.

This allows for negative values in the Money class.

Returns
A Money object containing the negative value.
Author
Dawson Dauphinais

◆ operator-() [2/2]

Money Money::operator- ( const Money m) const

Overloads the - operator for the Money class.

This allows for subtraction of Money objects.

Parameters
mA Money object to be subtracted from the current Money object.
Returns
A Money object containing the result of the subtraction.
Author
Dawson Dauphinais

◆ operator/() [1/2]

Money Money::operator/ ( double  m) const

Overloads the / operator for the Money class.

This allows for the division of Money objects.

Attention
This could potentially cause precision errors. Unlikely, but not impossible.
Parameters
mThe value to divide the current Money object by.
Returns
A Money object containing the result of the division.
Author
Dawson Dauphinais

◆ operator/() [2/2]

Money Money::operator/ ( Money m) const

Overloads the / operator for the Money class.

This allows for the division of Money objects

Attention
This could potentially cause precision errors. Unlikely, but not impossible.
Parameters
mThe Money object to divide the current Money object by.
Returns
A Money object containing the result of the division.
Author
Dawson Dauphinais

◆ operator==()

bool Money::operator== ( const Money m) const

Overloads the == operator for the Money class.

Allows equality checking between to Money objects..

Parameters
mA Money object to compare with current object.
Returns
True if the objects are equal; false otherwise.
Author
Dawson Dauphinais

◆ power() [1/2]

static double Money::power ( double  d,
int  exp 
)
static

Helper function for the power function of the Money class.

See also
power(Money &m, int exp)
Parameters
dThe monetary value.
expThe exponent.
Returns
The result of raising the monetary value to the specified power.
Author
Dawson Dauphinais

◆ power() [2/2]

static Money Money::power ( Money m,
int  exp 
)
static

Implements the power function for the Money class.

Allows a Money object to be raised to a specified power.

Parameters
mA Money object containing the initial value.
expThe exponent.
Returns
A Money object containing the result.
Author
Dawson Dauphinais

◆ toDouble()

static double Money::toDouble ( const Money m)
static

Converts a Money object to a double value.

Attention
Could potentially cause loss of precision. Unlikely, but not impossible.
Parameters
mThe Money object to be converted.
Returns
The value as a double.
Author
Dawson Dauphinais

◆ toString()

static string Money::toString ( const Money m1)
static

Converts a Money object to a string.

Parameters
m1The Money object to be converted.
Returns
The value as a string.
Author
Dawson Dauphinais

Friends And Related Function Documentation

◆ operator<<

ostream & operator<< ( ostream &  out,
const Money m 
)
friend

Overloads the << operator for the Money class.

This allows Money objects to be printed as follows: $4.56

Parameters
outThe ostream for the operator.
mThe Money object to be printed to the screen.
Returns
An ostream containing the formatted output.
Author
Dawson Dauphinais