So in this project, I have to create a rationalizer program that helps reduce numbers to a simplified format. The part of the program that I am struggling the most with are the operators with the long parameters.I'm trying to write out the proper conditions so that LongRational will be stored properly into this->_num , this->_den but the logic I've written doesn't seem right. Is there something wrong with my function parameters themself or anyway to correct this.
Rational& Rational::operator += (const Rational& rational)
{
this->_num += ((rational._num * _den) + (rational._den * _num));
this->_den += (rational._den * _den);
return *this;
}
//Part I am having trouble on. Tried editing but unsure if correct.
Rational& Rational::operator += (long LongRational)
{
this->_num += (LongRational * _den) + (_num * LongRational);
this->_den += (LongRational * _num);
return *this;
}
Rational& Rational::operator -= (const Rational& rational)
{
this->_num -= ((rational._den * _num) - (_den * rational._num));
this->_den -= (rational._den * _den);
return *this;
}
//Part I am having trouble on. Haven't edited this bit yet,
Rational& Rational::operator -= (long LongRational)
{
this->_num -= LongRational;
this->_den -= _den;
return *this;
}
//NOTE: He wants there to be a set of two assignment operators with parameters that takes in a Rational object as it's parameter and another with a long.