home *** CD-ROM | disk | FTP | other *** search
- // CCurr.h: CCurrency header file
-
- #include <string.h>
- #include <iostream.h>
-
- class CCurrency
- {
- private:
- long Dollars;
- int Cents;
-
- public:
- CCurrency () // default constructor
- {
- Dollars = Cents = 0;
- }
- CCurrency (long Dol, int Cen = 0) // conversion constructor
- {
- SetAmount (Dol, Cen);
- }
- CCurrency (double DolAndCen) // conversion constructor
- {
- Dollars = long (DolAndCen);
- Cents = int ((DolAndCen - Dollars) * 100.0 + 0.5);
- }
- void GetAmount (long *PDol, int *PCen)
- {
- *PDol = Dollars;
- *PCen = Cents;
- }
- void PrintAmount ()
- {
- cout.fill ('0');
- cout.width (1);
- cout << '$' << Dollars << '.';
- cout.width (2);
- cout << Cents << '\n';
- }
- void SetAmount (long Dol, int Cen)
- {
- Dollars = Dol + Cen / 100;
- Cents = Cen % 100;
- }
- friend CCurrency operator+ (const CCurrency &Curr1,
- const CCurrency &Curr2);
- };
-
- CCurrency operator+ (const CCurrency &Curr1, const CCurrency
- &Curr2)
- {
- return CCurrency (Curr1.Dollars + Curr2.Dollars,
- Curr1.Cents + Curr2.Cents);
- }
-