I am suppose to creat a Money class that has the following methos with operators for:
Addition, Assignment(+=), Substraction, Minus equal, Multiplication, Times equal, division, divide equal, Negation, Equality, Greater Than, Less than, Greater and Less than or equal to, File input and output.

The public interface for Money is as follows: (it has to be done this way)
Money()
Money(long, int) // first parameter is dollars, second is cents
Money(long) // long is number of dollars, cents is .00
double getValue() // returns dollar amount of Money, ie: 2.27
void displayValue() // displays as $2.27 or -$2.27
int getValueInCents() //returns amount in cents, ie: $2.27 would be 227

I am only confusing myself more and more, I had my program down to one error. Now I have a ton of errors. Also, I need help getting started on my Negation overloading and the comparison operators like <, >=, etc.

here is what I have already and the test file it must work with.

1
5 #include<iostream>
6
7 #include<iostream>
8 #include<fstream>
9 #include<iomanip>
10
11 using namespace std;
12
13 #ifndef MONEY
14 #define MONEY
15
16 class Money
17 {
18 friend Money operator* (Money, Money); //Overloads * to implement this-Money * value
19 //post: this-Money is unchanged
20 //returns: this-Money * valu
21 friend Money operator/ (Money, Money); //Overloads / to implement this-Money / value
22 //post: this-Money is unchanged
23 //returns: this-Money / value
24 /*friend Money operator> (Money, Money);
25 friend Money operator< (Money, Money);
26 friend Money operator>= (Money, Money);
27 friend Money operator<= (Money, Money);*/
28 friend Money& operator- (Money, Money);
29 friend Money& operator*= (Money&, Money);
30 friend Money& operator/= (Money&, Money);
31 friend Money& operator-= (Money&, Money);
32 friend ostream& operator<< (ostream&, Money);
33 friend ostream& operator>> (ostream&, Money);
34
35
36 public:
37
38 //Class constructors
39
40 Money(); //Default Constructor
43 Money(long d, int c); //Constructor
49 Money(long dol); //Constructor
56
59 Money& operator= (const Money&);
60 Money& operator+= (const Money&);
61
62 double getValue();
63 void displayValue();
64 int getValueInCents();
65
66 private:
67
68 //Data members
-- int total; //integer representation of money
70
71 };
72
73 Money::Money();
-- {
-- total = 0;
-- }
--
-- Money::Money(long d, int c)
-- {
-- int dollars = d;
-- int cents = c;
-- total = (dollars * 100) + cents;
-- }
--
-- Money::Money(long dol)
-- {
-- total = dol * 100;
-- }
74
-- //return data from private member
-- double Money::getValue()
99 {
100 return total;
101 }
102
103 void Money::displayValue()
104 {
105 if(total >= 0)
106 {
107 cout<<'$'<<(total/100);
108 cout<<setw(2)<<setfill('0');
109 }
110 else
111 {
112 cout<<"-$"<<(total/100);
113 cout<<setw(2)<<setfill('0');
114 }
115 }
116
117 int Money::getValueInCents()
118 {
119 return total;
120 }
121
122 Money& Money:perator=(const Money& rightSide)
123 {
124 if (&rightSide != this) //using the this pointer to make sure the object is not copied over itself
125 {
126 this->total = rightSide.total;
127 }
128
129 return *this;
130 }
131
132 Money& Money:perator+=(const Money& rightSide)
133 {
134 this->total += rightSide.total;
135
136 return *this;
137 }
138
139
140 /*Money operator> ( Money first, Money second )
141 {
142 bool test;
143 test = first.total > second.total;
144 return test;
145 }*/
146 //Overload + relative to Money class
147 Money operator+ ( Money f, Money e )
148 {
149 Money temp;
150 temp = e.total + f.total;
151 return temp;
152
153 }
154
155 //Overload - relative to Money class
156 Money& operator- ( Money &a, Money b )
157 {
158 Money temp;
159 temp = a.total - b.total;
160 a = temp;
161 return a;
162 }
163
164 //Overload * for Money
165 Money operator* ( Money c, Money d )
166 {
167 Money temp;
168 temp.total = c.total * d.total;
169 return temp;
170 }
171
172 //Overload / for Money divided by double
173 Money operator/ ( Money one, Money two)
174 {
175 Money temp;
176 temp.total = one.total / two.total;
177 return temp;
178 }
179
180 Money& operator/= ( Money &c, Money d ) //passes Count object by reference
181 {
182 c.total /= d.total;
183 return c;
184 }
185
186 Money& operator*= ( Money &p, Money q )
187 {
188 p.total *= q.total;
189 return p;
190 }
191
192 Money& operator-= ( Money &u, Money y )
193 {
194 u.total -= y.total;
195 return u;
196 }
197
198 //Overload insertion operator to output Money object
199 ostream& operator << (ostream& outs, Money& value)
200 {
201 if(value.total >= 0)
202 {
203 outs<<'$'<<(total/100);
204 outs<<setw(2)<<setfill('0');
205 }
206 else
207 {
208 outs<<"-$"<<(total/100);
209 outs<<setw(2)<<setfill('0');
210 }
211
212 return outs;
213 }
214
215 //Overload insertion operator to input Money objects
216 istream& operator >> (istream& ins, Money& value)
217 {
218 long d=0; //holds dollar values
219 int c=0; //holds cent values
220 char ch; //holds '.' character
221
222 cin>>d;
223 cin>>ch;
224 cin>>c;
225
226 total = (d * 100) + c;
227
228 return ins;
229 }
230
231 # endif


*************************************************
here is the test file.
#include <iostream>
#include "Money.h"


int main()
{
Money m(2,27);
Money a(-3,8), b;

m.displayValue();

cout << a << endl;

cout << "Enter Money: ";
cin >> b; //Enter -33.07
b.displayValue();
cout << b.getValueInCents() << endl;

Money c;
c = b + a;

cout << "c is equal to " << c << endl;

if (a == b) cout << "a equals b\n";
else cout << "a does not equal b\n";

a = b;

if (a == b) cout << "a equals b\n";
else cout << "a does not equal b\n";

a = -c;

a.displayValue();
c.displayValue();

Money x(10), y(5);

cout << x * y << endl;
cout << x / y << endl;
x *= y;
x.displayValue();

return 0;
}