Help with understanding Fraction class code

So this is just my assignment. Were given this code to start out with, i'm just trying to understand what does it exactly do and what its passing in as the parameters. So op is the RHS pretty much the method is multplies RHS with the fraction object invoked with this method.

Any help would be appreciated it thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "Fraction.h"
#include "GCD.h" // template function for calculating greatest common divisor
#include <iostream>
using namespace std;

//Implementation of the timesEq() member function
//Performs similar operation as the *= operator on the built-in types
const Fraction & Fraction::timesEq(const Fraction & op )
{
	numerator *= op.numerator;
	denominator *= op.denominator;

	simplify();  // will make sure that denominator is positive and
	             //   will invoke gcd() function to reduce fraction
	             //   as much as possible

	return (*this); // returns the object which invoked the method
}
Last edited on
this is introducing you the operator overload *=

this will happen when you have something like this

Fraction a(3, 4);
Fraction b(4 , 2);

a *= b ;

is th same as a = 3/4 * 4/2 ;

a will be change , but not b ( the right operand (op) ) because it is a constant reference of instance of type Fraction

hope this clear you a little bit
Ok cool, thanks. Yeah that helps a lot!
Topic archived. No new replies allowed.