Reducing fractions

So I have the following implementation file and I just cannot figure how to introduce a fraction reducing function into this. Any help? The result still has to be in fraction form, even if it's improper. Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
   #include "fraction.h"
  #include <iostream>
  
  using namespace std;
   fraction::fraction()  //default constructor...no incoming parameter
      {//set variables equal to 0
          num=0;
          denom=1;
      }
      fraction::fraction(int n, int d)  //constructor
      {//set variables equal to 0
          fraction final;
          num=n;
          denom=d;
          
      }
   
       void fraction::print() const
      {
            cout<<num<<"/"<<denom;
      }
      fraction fraction::MultipliedBy(fraction f2) const
      {
           fraction temp(num*f2.num, denom*f2.denom);
          fraction Reduce(temp);
          
           return temp;
      } 
      fraction fraction::AddedTo(fraction f2) const
      {
           fraction temp(num*f2.denom+denom*f2.num, denom*f2.denom);
           
           return temp;
      } 
      
      fraction fraction::DividedBy(fraction f2) const
      {
           fraction temp(num*f2.denom, denom*f2.num);
           return temp;
      } 
      
      fraction fraction::Subtract(fraction f2) const
      {
           fraction temp(num*f2.denom-denom*f2.num, denom*f2.denom);
           
           return temp;
      } 
   
fraction fraction::Reduce(int num, int denom)
{
   }
No, you need to find the greatest common divisor of both numerator and denominator and then divide both
by it.

GCD algorithms abound; search Wikipedia.
Yeah, thanks I know about the GCD algorithms. I'm just stumped on implementing it properly into my code.
Wikipedia even gives you C/C++ code that implements it.
Topic archived. No new replies allowed.