Project 3 - Currency Type
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 >
as () const
 Convert the rational number to another type, especially floating-point.
 
rationaloperator= (value_type)
 Assignment of an integer.
 
template<class U >
rationaloperator= (rational< U > const &rhs)
 Assignment of a rational with a different size.
 
rationaloperator+= (rational const &rhs)
 Addition assignment operator.
 
rationaloperator+= (value_type const &rhs)
 Addition assignment operator.
 
rationaloperator-= (rational const &rhs)
 Subtraction assignment operator.
 
rationaloperator-= (value_type const &rhs)
 Subtraction assignment operator.
 
rationaloperator*= (rational const &rhs)
 Multiplication assignment operator.
 
rationaloperator*= (value_type const &rhs)
 Multiplication assignment operator.
 
rationaloperator/= (rational const &rhs)
 Division assignment operator.
 
rationaloperator/= (value_type const &rhs)
 Division assignment operator.
 
rationaloperator++ ()
 Pre-increment.
 
rationaloperator-- ()
 Pre-decrement.
 
rational operator++ (int)
 Post-increment.
 
rational operator-- (int)
 Post-decrement.
 
template<class U >
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
numThe 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
numnumerator
dendenominator
Exceptions
zero_denominatorif 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
rthe initial value

Definition at line 114 of file rational.hpp.


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