Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

2.11 Money.h++ Examples

Table 5 lists the C++ and Java examples and briefly describes what they do.

Table 5 -- Example programs

Java nameC++ nameDescription 
CurrencyExample.javacurrexam.cppA very simple example using the RWCurrencyBook/CurrencyBook class. The example illustrates how to initialize a currency book object from a file and how to access currency information using it. 
Example1.java
example1.cpp
A very simple example illustrating how decimals give exact results, whereas floating-point values have built-in rounding errors.
FactoryExample.java
factoryexam.cpp
An example illustrating the use of the class RWExchangeFactory/ExchangeFactory. A factory contains an exchange rate table and at least one exchange group. Exchange groups can construct exchange objects, which are used to perform currency conversions. When presented with a source/target currency pair the exchange factory searches its list of exchange groups until it finds a group that can create an exchange object given the source/target pair and the factory's associated exchange rate table. If no group can create such an object,the factory returns an invalid (or nul, in Java) object.
Format1.java
format1.cpp
Simple example illustrating that the RWDecimalFormat/MoneyFormat class can be used to do simple formatting of RWMoney/Money objects.
Format2.java
format2.cpp
An example of how to format a large data set of money. A sales report is generated in two different styles using the same data.
GroupExample.java
groupexam.cpp
Illustrates the use of exchange groups and of RWExchangeFactory/ ExchangeFactory.
A factory contains an exchange rate table and at least one exchange group. Exchange groups can construct exchange objects, which are used to perform currency conversions. When presented with a source/target currency pair, the exchange factory searches its list of exchange groups until it finds one that can create an exchange object given the source/target pair and the factory's associated exchange rate table. If no group can create such an object an invalid object is returned in C++ or a null value is returned in Java.
In this example an exchange factory object is created and three exchange groups are added including our own creation, a US dollar base group. Several currency exchanges are performed.
MoneyCalculatorExample.java
calcexam.cpp
Reads in an RWExchangeRateTable/ExchangeRateTable and RWEuroGroup/EuroGroup to construct an RWExchangeFactory/ExchangeFactory. This factory is then associated with an RWMoneyCalculator/MoneyCalculator. The calculator is used to perform arithmetic with different currency conversion policies and rounding methods.
Savings.java
savings.cpp
Demonstrates how a savings account grows. Shows how to use the RWDecimal/BigDecimal class.

2.11.1 Running the Examples in Java

The Java examples are in

To compile and run these examples:

  1. Make sure your CLASSPATH environment variable includes the directory containing com.

  2. cd to the examples directory that correponds to your installation type (see above).

  3. Enter: javac *.java

Run each of the examples by typing its complete name. For example:

2.11.2 Building and Running the C++ Examples

For information about compiling the C++ examples, see the Money.h++ Build Guide available in <rw_root>/htmldocs/mny<ver>bd/index.html for Software Parts Manager installations, and <rw_common>\docs\htmldocs\mny<ver>bd\index.html for Visual Studio Edition installations. Once the examples are built, change to the examples directory and type the example's file name to run the example.



Previous fileTop of DocumentContentsIndexNext file

©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.