Multiply fractions

Write your question here.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960`` `````` #include #include 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

 ``12`` ``````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.