### class and functions help

help with classes I need get these denominators to multiply and numerators as well and for some reason the numerator is switched with the denominator and the other one will not multiply for whatever reason. I do need have them divide and add and subtract as well later but one step at a time. here is my code.
 ``12345678910111213141516171819202122`` ``````#ifndef FRACTION_H_INCLUDED #define FRACTION_H_INCLUDED class fraction { public: fraction (); // default constructor fraction (int,int); void print() const; fraction MultipliedBy(fraction) const; fraction isGreaterThan(fraction) const; fraction AddedTo(fraction) const; fraction Subtract(fraction) const; fraction isEqualTo(fraction) const; fraction DividedBy(fraction) const; private: int numerator; int denominator; }; #endif // FRACTION_H_INCLUDED ``````

 ``12345678910111213141516171819202122232425`` ``````#include #include "fraction.h" using namespace std; fraction::fraction ()// default constructor { numerator=0; denominator=1; } fraction::fraction (int newNumerator,int newDenominator) { denominator=newDenominator; numerator=newNumerator; } void fraction::print() const { cout<

 ``1234567891011121314151617181920212223`` ``````#include #include "fraction.h" using namespace std; int main() { fraction f1(9,8); //calling a parameterized class constructor fraction f2(2,3); //calling a parameterized class constructor fraction result; //calling a default class constructor fraction f3; //calling a default class constructor cout << "The result starts off at "; result.print(); //calling an observer function cout << endl; cout << "The product of "; f1.print(); cout << " and "; f2.print(); cout << " is "; result = f1.MultipliedBy(f2); //a class binary operation - function result.print(); cout << endl;/``````

 ``` The result starts off at 0/1 The product of 9/8 and 2/3 is 24/3 Process returned 0 (0x0) execution time : -0.000 s Press any key to continue. ```
 ``123456`` `````` fraction fraction::MultipliedBy(fraction f) const { f.numerator*=numerator; f.denominator*=denominator; // ¿return? }``````
Last edited on
i tried return numerator; and return denominator no luck i get an error
conversion from 'const int' to non-scalar type 'fraction' requested
here was the problem
 ``12345678`` `````` fraction fraction::MultipliedBy(fraction f) const { f.denominator*=denominator; f.numerator*=numerator; return f; }``````
Topic archived. No new replies allowed.