Project 3 - Currency Type

- Main Page
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | List of all members
rational< T > Class Template Reference

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)

## Detailed Description

### template<class T>
class rational< T >

Represent a rational number (fraction) as a numerator and denominator.

Definition at line 16 of file rational.hpp.

## Constructor & Destructor Documentation

template<class T>

rational< T >::rational | ( | value_type | num = `0` | ) |
| inline

Default constructor and constructor from a single value. As a default constructor, initializes to zero. Otherwise, initializes to the integer `num`.

Parameters

  num | The integer value to use as the initial value

Definition at line 33 of file rational.hpp.

template<class T >

rational< T >::rational | ( | value_type | num,
|  | value_type | den
| ) |  |

Construct a rational number

Parameters

  num | numerator
  den | denominator

Exceptions

  zero_denominator | if `den` == 0

Definition at line 106 of file rational.hpp.

template<class T >

rational< T >::rational | ( | double | r | ) |

Initialize the rational number with an approximation of `r`

Parameters

  r | the initial value

Definition at line 114 of file rational.hpp.

The documentation for this class was generated from the following file:

- rational.hpp