Project 3 - Currency Type
|
Represent a rational number (fraction) as a numerator and denominator. More...
#include <rational.hpp>
Classes | |
class | zero_denominator |
Exception class if the denominator is ever zero. More... | |
Public Types | |
typedef T | value_type |
Convenience typedef for the integral type of the numerator and denominator. | |
Public Member Functions | |
rational (value_type num=0) | |
rational (value_type num, value_type den) | |
rational (double r) | |
template<class U > | |
rational (rational< U > const &that) | |
Copy from a different type of rational. | |
value_type | numerator () const |
Return the numerator. | |
value_type | denominator () const |
Return the denominator. | |
template<class U > | |
U | as () const |
Convert the rational number to another type, especially floating-point. | |
rational & | operator= (value_type) |
Assignment of an integer. | |
template<class U > | |
rational & | operator= (rational< U > const &rhs) |
Assignment of a rational with a different size. | |
rational & | operator+= (rational const &rhs) |
Addition assignment operator. | |
rational & | operator+= (value_type const &rhs) |
Addition assignment operator. | |
rational & | operator-= (rational const &rhs) |
Subtraction assignment operator. | |
rational & | operator-= (value_type const &rhs) |
Subtraction assignment operator. | |
rational & | operator*= (rational const &rhs) |
Multiplication assignment operator. | |
rational & | operator*= (value_type const &rhs) |
Multiplication assignment operator. | |
rational & | operator/= (rational const &rhs) |
Division assignment operator. | |
rational & | operator/= (value_type const &rhs) |
Division assignment operator. | |
rational & | operator++ () |
Pre-increment. | |
rational & | operator-- () |
Pre-decrement. | |
rational | operator++ (int) |
Post-increment. | |
rational | operator-- (int) |
Post-decrement. | |
template<class U > | |
T | scale (U value) |
template<class U > | |
rational< T > & | operator= (rational< U > const &rhs) |
Represent a rational number (fraction) as a numerator and denominator.
Definition at line 16 of file rational.hpp.
|
inline |
Default constructor and constructor from a single value. As a default constructor, initializes to zero. Otherwise, initializes to the integer num
.
num | The integer value to use as the initial value |
Definition at line 33 of file rational.hpp.
rational< T >::rational | ( | value_type | num, |
value_type | den | ||
) |
Construct a rational number
num | numerator |
den | denominator |
zero_denominator | if den == 0 |
Definition at line 106 of file rational.hpp.
Initialize the rational number with an approximation of r
r | the initial value |
Definition at line 114 of file rational.hpp.