Fill in the multiplication and division modulus With div
Fill in the multiplication, and division , modulus, <=, >=, -, * With division being a friend function
Below is your main function
#include <iostream>
using namespace std;
class money
{
private:
int dollars;
int cents;
public:
money():dollars(0), cents(0){}
money(int dollars_in):dollars(dollars_in), cents(0){}
money(int dollars_in, int cents_in):dollars(dollars_in), cents(cents_in){}
int get_dollars() const;
int get_cents() const;
void set_dollars(int d_in);
void set_cents(int c_in);
money operator ++();
money operator ++(int x);
money operator +(const money& rhs);
money operator -();
friend const money& operator +(const money& lhs, const money& rhs);
// *************************************************************
// define these operations.
money operator --();
money operator --(int x);
bool operator <=();
bool operator >=();
};
// do this as a general function
money operator *(const money& lhs, const money& rhs)
{
return money(0, 0);
}
// do this as a friend function
money operator -(const money& lhs, const money& rhs)
{
return money(0, 0);
}
//********************************************************************
// below here was already done in class
money money::operator -()
{
return money(get_dollars(), get_cents());
}
money money::operator ++(int blah)
{
int tmp_d = dollars;
int tmp_c = cents;
dollars++;
return money(tmp_d, tmp_c);
}
money money::operator ++()
{
int tmp_d = dollars;
tmp_d += 1;
return money(dollars, cents);
}
int money::get_dollars() const
{
return dollars;
}
int money::get_cents() const
{
return cents;
}
void money::set_dollars(int d_in)
{
dollars = d_in;
}
void money::set_cents(int c_in)
{
cents = c_in;
}
ostream& operator <<(ostream& os, const money& rhs)
{
os << \"$\" << rhs.get_dollars() << \".\";
if(rhs.get_cents() < 10)
{
os << \"0\";
}
os << rhs.get_cents();
return os;
}
money money::operator +(const money& rhs)
{
int tmp_d = 0;
int tmp_c = 0;
int hold_c = 0;
int hold_d = 0;
tmp_d = get_dollars() + rhs.get_dollars();
tmp_c = get_cents() + rhs.get_cents();
if(tmp_c > 99)
{
hold_c = tmp_c % 100;
cout << \"hold_c = \" << hold_c << endl;
hold_d = tmp_c / 100;
cout << \"hold_d = \" << hold_d << endl;
for(int i = 0; i < hold_d; i++)
{
tmp_d++;
}
tmp_c = hold_c;
}
return money(tmp_d, tmp_c);
}
const money& operator +(const money& lhs, const money& rhs)
{
int tmp_d = 0;
int tmp_c = 0;
int hold_c = 0;
int hold_d = 0;
// tmp_d = lhs.get_dollars() + rhs.get_dollars();
// tmp_c = lhs.get_cents() + rhs.get_cents();
tmp_d = lhs.dollars + rhs.dollars;
tmp_c = lhs.cents + rhs.cents;
if(tmp_c > 99)
{
hold_c = tmp_c % 100;
cout << \"hold_c = \" << hold_c << endl;
hold_d = tmp_c / 100;
cout << \"hold_d = \" << hold_d << endl;
for(int i = 0; i < hold_d; i++)
{
tmp_d++;
}
tmp_c = hold_c;
}
return money(tmp_d, tmp_c);
}
bool operator ==(const money& lhs, const money& rhs)
{
return ((lhs.get_dollars() == rhs.get_dollars()) && (lhs.get_cents() == rhs.get_cents()));
}
int main()
{
money m1;
money m2(100, 99);
money m3(250, 5);
cout << \"m1 = \" << m1 << endl;
cout << \"m2 = \" << m2 << endl;
cout << \"m3 = \" << m3 << endl;
m1 = m2 + m3;
cout << \"m1 = \" << m1 << endl;
m1 = m1 + 200;
cout << \"m1 + 200 \" << endl;
cout << \"m1 = \" << m1 << endl;
cout << \"m2 + m3\" << endl;
cout << \"m1 = \" << m1 << endl;
cout << \"m2 == m1 \" << endl;
cout << \"m1 = \" << m1 << endl;
cout << \"m2 = \" << m2 << endl;
cout << (m2 == m1) << endl;
m1 = money();
m2 = money();
cout << \"m1 = \" << m1 << endl;
cout << \"m2 = \" << m2 << endl;
cout << (m2 == m1) << endl;
cout << \"++m1 \" << endl;
++m1;
cout << \"m1 = \" << m1 << endl;
cout << \"m1++\" << endl;
cout << m1++ << endl;
cout << \"m1 = \" << m1 << endl;
cout << \"-m1 = \" << -m1 << endl;
m2 = money(1, 0);
m3 = money(2, 0);
money tm;
tm = (m3 + -m2);
cout << \"m3 = \" << m3 << endl;
cout << \"m2 = \" << m2 << endl;
cout << \"(m3 + -m2) = \" << tm << endl;
m1 = money;
m2 = money(101, 78);
m3 = money(202, 10);
m2 <= m3?cout << \"m2 <= m3\" << endl; : cout << \"m2 is not <= m3\" << endl;
m2 >= m3?cout << \"m2 >= m3\" << endl; : cout << \"m2 is not >= m3\" << endl;
m1 = m3 * m2;
cout << \"m3 * m2 = \" << m1 << endl;
m1 = m3 - m2;
cout << \"m3 - m2 = \" << m1 << endl;
return 0;
}
Please complete in a way it can be copied and pasted to c++ codeblocks and run the program to show it works
Solution
#include <iostream>
using namespace std;
class money
{
private:
int dollars;
int cents;
public:
money():dollars(0), cents(0){}
money(int dollars_in):dollars(dollars_in), cents(0){}
money(int dollars_in, int cents_in):dollars(dollars_in), cents(cents_in){}
int get_dollars() const;
int get_cents() const;
void set_dollars(int d_in);
void set_cents(int c_in);
money operator ++();
money operator ++(int x);
money operator +(const money& rhs);
money operator -();
friend const money& operator +(const money& lhs, const money& rhs);
money operator --();
money operator --(int x);
bool operator <=();
bool operator >=();
};
money operator *(const money& lhs, const money& rhs)
{
return money(0, 0);
}
// do this as a friend function
money operator -(const money& lhs, const money& rhs)
{
return money(0, 0);
}
friend Money operator - ( const Money & lhs , const Money & rhs);
Money operator -(const Money & rhs)const;
// ==
friend bool operator == ( const Money & lhs , const Money & rhs);
Money operator +(const Money & rhs) const ;
// stream overload
// istream == inputstream ; outputstream ostream
friend ostream & operator <<(ostream & myoutputStream , Money & m);friend istream & operator >>(istream & myinputstream , Money & m);};
money money::operator -()
{
return money(get_dollars(), get_cents());
}
money money::operator ++(int blah)
{
int tmp_d = dollars;
int tmp_c = cents;
dollars++;
return money(tmp_d, tmp_c);
}
money money::operator ++()
{
int tmp_d = dollars;
tmp_d += 1;
return money(dollars, cents);
}
int money::get_dollars() const
{
return dollars;
}
int money::get_cents() const
{
return cents;
}
void money::set_dollars(int d_in)
{
dollars = d_in;
}
void money::set_cents(int c_in)
{
cents = c_in;
}
ostream& operator <<(ostream& os, const money& rhs)
{
os << \"$\" << rhs.get_dollars() << \".\";
if(rhs.get_cents() < 10)
{
os << \"0\";
}
os << rhs.get_cents();
return os;
}
money money::operator +(const money& rhs)
{
int tmp_d = 0;
int tmp_c = 0;
int hold_c = 0;
int hold_d = 0;
tmp_d = get_dollars() + rhs.get_dollars();
tmp_c = get_cents() + rhs.get_cents();
if(tmp_c > 99)
{
hold_c = tmp_c % 100;
cout << \"hold_c = \" << hold_c << endl;
hold_d = tmp_c / 100;
cout << \"hold_d = \" << hold_d << endl;
for(int i = 0; i < hold_d; i++)
{
tmp_d++;
}
tmp_c = hold_c;
}
return money(tmp_d, tmp_c);
}
const money& operator +(const money& lhs, const money& rhs)
{
int tmp_d = 0;
int tmp_c = 0;
int hold_c = 0;
int hold_d = 0;
// tmp_d = lhs.get_dollars() + rhs.get_dollars();
// tmp_c = lhs.get_cents() + rhs.get_cents();
tmp_d = lhs.dollars + rhs.dollars;
tmp_c = lhs.cents + rhs.cents;
if(tmp_c > 99)
{
hold_c = tmp_c % 100;
cout << \"hold_c = \" << hold_c << endl;
hold_d = tmp_c / 100;
cout << \"hold_d = \" << hold_d << endl;
for(int i = 0; i < hold_d; i++)
{
tmp_d++;
}
tmp_c = hold_c;
}
return money(tmp_d, tmp_c);
}
bool operator ==(const money& lhs, const money& rhs)
{
return ((lhs.get_dollars() == rhs.get_dollars()) && (lhs.get_cents() == rhs.get_cents()));
}
int main()
{
money m1;
money m2(100, 99);
money m3(250, 5);
cout << \"m1 = \" << m1 << endl;
cout << \"m2 = \" << m2 << endl;
cout << \"m3 = \" << m3 << endl;
m1 = m2 + m3;
cout << \"m1 = \" << m1 << endl;
m1 = m1 + 200;
cout << \"m1 + 200 \" << endl;
cout << \"m1 = \" << m1 << endl;
cout << \"m2 + m3\" << endl;
cout << \"m1 = \" << m1 << endl;
cout << \"m2 == m1 \" << endl;
cout << \"m1 = \" << m1 << endl;
cout << \"m2 = \" << m2 << endl;
cout << (m2 == m1) << endl;
m1 = money();
m2 = money();
cout << \"m1 = \" << m1 << endl;
cout << \"m2 = \" << m2 << endl;
cout << (m2 == m1) << endl;
cout << \"++m1 \" << endl;
++m1;
cout << \"m1 = \" << m1 << endl;
cout << \"m1++\" << endl;
cout << m1++ << endl;
cout << \"m1 = \" << m1 << endl;
cout << \"-m1 = \" << -m1 << endl;
m2 = money(1, 0);
m3 = money(2, 0);
money tm;
tm = (m3 + -m2);
cout << \"m3 = \" << m3 << endl;
cout << \"m2 = \" << m2 << endl;
cout << \"(m3 + -m2) = \" << tm << endl;
m1 = money;
m2 = money(101, 78);
m3 = money(202, 10);
m2 <= m3?cout << \"m2 <= m3\" << endl; : cout << \"m2 is not <= m3\" << endl;
m2 >= m3?cout << \"m2 >= m3\" << endl; : cout << \"m2 is not >= m3\" << endl;
m1 = m3 * m2;
cout << \"m3 * m2 = \" << m1 << endl;
m1 = m3 - m2;
cout << \"m3 - m2 = \" << m1 << endl;
return 0;
}








