Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Currency Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

5.2 Exchange Rates and Exchange Rate Tables

Most currency exchange rates are published in the form:

In the Currency Module parlance, 1.5455 is a multiplicative conversion factor for converting US Dollars to Canadian Dollars. This means that you multiply an amount in US Dollars by 1.5455 to convert to Canadian Dollars. The class RWExchangeRate encapsulates the information shown above by storing a source currency, a target currency and, by convention, a multiplicative conversion factor. The following example shows how you initialize RWExchangeRate object usToCan with the factor shown above:

RWExchangeRate provides members that can return or set an object's source currency mnemonic, target currency mnemonic or rate. It also provides functions and operators that can persist an object to, and restore an object from a virtual stream or a file.

The class RWExchangeRateTable stores exchange rates as unique pairs of source and target currencies and an associated rate. No two exchange rates in the table have the same source/target currency pair.

The RWExchangeRateTable class can be initialized from a stream, in particular, from an ifstream (file), using the initialize() member function. The format for the stream is:

For example, the following code initializes exchange rate table rates from the file exchange_rates.txt.

An RWExchangeRateTable, when combined with one or more currency exchange groups, provides the basis for an exchange factory that can be used to convert money from one currency to another. Section 5.5, "Currency Exchange Factory," shows how to set up a factory.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.