Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Hey, looking to do the following with this programFill in the multip.pdf
1. Hey, looking to do the following with this programFill in the multiplication, and division ,
modulus, <=, >=, -, * With division being a friend function
1.) Have Division be a friend function
2.) Have multiplication, divison, and modulus <=, >=, -, * with the program filling them.
I tried doing something along the lines of this....
friend money operator <<(const money& lhs);
friend money operator >>( const money& rhs);
but I'm note quite sure if this is correct. Any help will be helpful. I don't want just answers, I
want good explanations so I can understand this material.
Whole code posted below.
#include
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);
2. 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);
}
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;