44f7010da4c6c17cce8c563deaafbbb817ae4c21
[AXE.git] / src / money.h
1 /**************************************************************************
2 **  (c) Copyright 1999, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : money.h
7 **      SYSTEM NAME    : Andromeda X-Windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.1 $
9 **
10 **  DESCRIPTION      :  Financial classes
11 **
12 **  EXPORTED OBJECTS : class amount
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Aug 26, 1999
20 **      LAST UPDATE     : Aug 26, 1999
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 /*****************************
25    $Log: money.h,v $
26    Revision 1.1  2002-07-25 08:01:27  arjen
27    First checkin, AXE release 0.2
28
29 *****************************/
30
31 // static const char RCSID[] = "$Id: money.h,v 1.1 2002-07-25 08:01:27 arjen Exp $";
32
33 #ifndef MONEY_H
34 #define MONEY_H
35
36 #include <math.h>
37 #include <iostream.h>
38 #include "String.h"
39
40 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 **  NAME           : amount - Encapsulate an amount of money
42 **  MEMBERS        : value - The monetary value (in cents)
43 **  OPERATORS      : 
44 **                   ostream << : String to output stream.
45 **                   istream << : String from input stream.
46 **  METHODS        :
47 **
48 **  DESCRIPTION    : 
49 **
50 **  RELATIONS      : 
51 **  SEE ALSO       :
52 **  LAST MODIFIED  : Aug 26, 1999
53 **+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54 */
55
56 class amount
57 {
58    unsigned long  value;
59
60 public:
61
62    amount()
63    {
64       value = 0;
65    }
66
67    amount(unsigned long l)
68    {
69       value = l;
70    }
71
72    amount(String s);
73
74    operator long()
75    {
76       return value;
77    }
78
79    operator String();
80    String make_string(void);
81
82    amount operator+(amount a)
83    {
84       amount sum;
85
86       sum.value = value + a.value;
87       return sum;
88    }
89
90    amount operator *= (double f)
91    {
92       double  v;
93
94       v = rint(value * f);
95       value = (unsigned long)v;
96
97       return *this;
98    }
99
100    amount operator /= (double f)
101    {
102       double  v;
103
104       v = rint(value / f);
105       value = (unsigned long)v;
106
107       return *this;
108    }
109
110    amount &operator+=(amount a)
111    {
112       value += a.value;
113
114       return *this;
115    }
116
117    friend istream &operator>>(istream&, amount &);
118    friend ostream &operator<<(ostream&, amount);
119
120 };
121
122 #endif  /* MONEY_H */