### Overloaded Arithmetic Operations on fractions

Hey, I'm 100% new to Overloading Operators, I don't fully get the syntax.

The goal here is trying to divide fractions. Fractions are stored within a class.

My main question is, how do I need to fix my syntax to make it work? I have a lot of red lines...

Resource File:
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````Mixed Mixed::operator/ (const Mixed mixed1, const Mixed mixed2) { Mixed fraction; mixed1.ToFraction(); mixed2.ToFraction(); fraction.numerator = (mixed1.numerator * mixed2.denominator); fraction.denominator = (mixed2.numerator * mixed1.denominator); fraction.Simplify(); return fraction; } void Mixed::ToFraction() { if((numerator==0)&&(denominator==0)) cout << integer << '/' << '1' << endl; else { if(integer<0) numerator = (integer*denominator) - numerator; else numerator = (integer*denominator) + numerator; integer = 0; cout << numerator << '/' << denominator << endl; } } void Mixed::Simplify() { int greatestCommonDenominator = gcd(numerator,denominator); cout << "This is the LCD: " << greatestCommonDenominator << endl; if(greatestCommonDenominator==0) cout << integer << endl; else if((denominator/greatestCommonDenominator != 0)&&(numerator/greatestCommonDenominator != 0)) { numerator=numerator/greatestCommonDenominator; denominator=denominator/greatestCommonDenominator; if(integer != 0) cout << integer << ' '; cout << numerator << "/" << denominator << endl << endl; } } int Mixed::gcd(int a, int b) { if(b == 0) return a; else return gcd(b, a%b); }``````

(It's within Public, should it be a friend?)
 ``12`` `````` Mixed operator/ (const Mixed mixed1, const Mixed mixed2);``````

Testing Code:
 ``12`` `````` Mixed m2(-1,2,4),m8(0,12,24); cout << "(m2 / m8) = " << (m2/m8) << '\n';``````

Any and all advice or resources would be appreciated!
Last edited on
Topic archived. No new replies allowed.