Multiply fractions

Write your question here.

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
53
54
55
56
57
58
59
60
  #include <iostream>
#include <string>
using namespace std;

class Fraction
{
    private:
      int numerator;
      int denominator;
    public:
      Fraction()
{
        numerator = 1;
        denominator = 2;
}
    Fraction(int n, int d)
{
      numerator = n;
      denominator = d;
}
    
    void print();
    void multiply(Fraction,Fraction);
};
void Fraction::print()
{
  cout << numerator << "/" << denominator << endl;
}

void Fraction::multiply(Fraction,Fraction)
{
 
 Fraction temp;
  
}

int main()
{
  Fraction f1;
  Fraction f2(3,5);
  Fraction f3;
  
  f3.multiply(f1,f2);
  
  cout << "\nFraction Object f1\n";
  f1.print();
  cout << endl << endl;
  
  cout << "\nFraction Object f2\n";
  f2.print();
  cout << endl << endl;
  
  cout << "\nFraction Object f3\n";
  f3.print();
  cout << endl << endl;
  
  cout << endl;
  
  return 0;
}

How can I get multiplcation done in that void? As soon as I use

1
2
temp.numerator = f1.numerator * f2.numerator;
 temp.denominator = f1.denominator * f2.denominator;


it stops working.
ok so I got that working, by removing temp and adding f1/f2 to the parameters.

But how do I go about adding the fractions together?

Could I do something like f1.num *5 and f2.den *5 ?
Last edited on
Topic archived. No new replies allowed.