Money Class Reference

#include <Money.h>

List of all members.

Public Member Functions

 Money (int dollars=0, int cents=0)
int getDollars () const
int getCents () const
bool isNegative () const
Money operator+ (const Money &other) const
void operator+= (const Money &other)
Money operator- (const Money &other) const
void operator-= (const Money &other)
Money operator- () const
bool operator< (const Money &other) const
bool operator<= (const Money &other) const
bool operator> (const Money &other) const
bool operator>= (const Money &other) const
bool operator== (const Money &other) const
bool operator!= (const Money &other) const
Money operator * (double factor) const


Detailed Description

Represents a monetary amount in dollars and cents


Constructor & Destructor Documentation

Money::Money int  dollars = 0,
int  cents = 0
[explicit]
 

Construct a new money instance. Automatically normalizes so that cents is between -99 and 99 and so that signs of the dollar and cents values do not disagree.

Parameters:
dollars value in dollars
cents value in cents (sign is assumed to match that of dollars)


Member Function Documentation

int Money::getCents  )  const
 

Return the amount of cents.

If overall value is negative, the returned amount will be appropriately negated.

Returns:
number of cents (signed)

int Money::getDollars  )  const
 

Return the amount of dollars.

If overall value is negative, the returned amount will be appropriately negated.

Returns:
number of dollars (signed)

bool Money::isNegative  )  const
 

Checks if current value is negative.

Returns:
true if negative, false otherwise

Money Money::operator * double  factor  )  const
 

Multiply monetary amount by a constant. Rounds to nearest cent.

Parameters:
factor multiplicative factor
Returns:
new monetary value

bool Money::operator!= const Money other  )  const
 

Compares two monetary amounts

Parameters:
other monetary value as second operand
Returns:
true if two are non-equivalent

Money Money::operator+ const Money other  )  const
 

Binary addition of monetary values.

Parameters:
other monetary value as second operand
Returns:
sum of monetary values

void Money::operator+= const Money other  ) 
 

Mutating form of addition for monetary values.

Parameters:
other monetary value as second operand

Money Money::operator-  )  const
 

Unary negation of monetary value.

Returns:
negation of original value

Money Money::operator- const Money other  )  const
 

Binary subtraction of monetary values.

Parameters:
other monetary value as second operand
Returns:
difference of monetary values

void Money::operator-= const Money other  ) 
 

Mutating form of subtraction for monetary values.

Parameters:
other monetary value as second operand

bool Money::operator< const Money other  )  const
 

Compares two monetary amounts

Parameters:
other monetary value as second operand
Returns:
true if first is stricty less than second

bool Money::operator<= const Money other  )  const
 

Compares two monetary amounts

Parameters:
other monetary value as second operand
Returns:
true if first is less than or equal to the second

bool Money::operator== const Money other  )  const
 

Compares two monetary amounts

Parameters:
other monetary value as second operand
Returns:
true if two are equivalent

bool Money::operator> const Money other  )  const
 

Compares two monetary amounts

Parameters:
other monetary value as second operand
Returns:
true if first is stricty greater than second

bool Money::operator>= const Money other  )  const
 

Compares two monetary amounts

Parameters:
other monetary value as second operand
Returns:
true if first is greater than or equal to the second


The documentation for this class was generated from the following files:
Generated on Tue Sep 16 23:25:45 2008 by  doxygen 1.4.6