So I'm writing a mixed numerals class for my OO class. We need to overload every comparison and boolean operand (among other things) but I'm having trouble with how to think about the '<' and '>' operands. Here are my '==' and '!=' operand functions for some context.
Edit: Also If anyone has any tips for to addition/subtraction methods I would be grateful.
bool operator ==(Mixed& mn1, Mixed& mn2){
mn1.ToFraction();
mn2.ToFraction();
mn1.Simplify();
mn2.Simplify();
if(mn1.numerator == mn2.numerator && mn1.denominator == mn2.denominator)
return true;
else
return false;
}
and
bool operator !=( Mixed& mn1, Mixed& mn2){
mn1.ToFraction();
mn2.ToFraction();
mn1.Simplify();
mn2.Simplify();
if(mn1.numerator == mn2.numerator && mn1.denominator == mn2.denominator)
return false;
else
return true;
}
If anyone could offer some guidance I'd be appreciative. Oh and we can't convert them to decimals for the comparisons.
Edit: Here's my header.
#include <iostream>
using namespace std;
class Mixed
{
public:
Mixed(int integer, int numerator = 0, int denominator = 1);
Mixed(int integer = 0);
double Evaluate();
void ToFraction();
void Simplify();
friend istream& operator >>(istream& in, Mixed& mn);
friend ostream& operator <<(ostream& out, Mixed& mn);
friend bool operator ==( Mixed& mn1, Mixed& mn2);
friend bool operator !=( Mixed& mn1, Mixed& mn2);
friend bool operator >( Mixed& mn1, Mixed& mn2);
friend bool operator <( Mixed& mn1, Mixed& mn2);
friend bool operator <=( Mixed& mn1, Mixed& mn2);
friend bool operator >=( Mixed& mn1, Mixed& mn2);
friend const Mixed operator +( Mixed& mn1, Mixed& mn2);
friend const Mixed operator -( Mixed& mn1, Mixed& mn2);
friend const Mixed operator *( Mixed& mn1, Mixed& mn2);
friend const Mixed operator /( Mixed& mn1, Mixed& mn2);
private:
int GCD(int a, int b);
int integer, numerator, denominator;
};