I have the following program to reduce rational numbers but am getting error messages at the lines x = c.subtraction( d ); and for multiplication, addition and division that says no operator "=" matches these operands. I do not know why. Could someone please help?
class Rational
{
private:
int numerator;
int denominator;
int d;
int x;
public:
Rational(int num = 0, int den = 1);
void addition(Rational c);
void subtraction(Rational c);
void multiplication(Rational c);
void division(Rational c);
void printRational();
void printRationalAsDouble();
private:
void reduction();
};
Rational::Rational(int num, int den) : numerator(num), denominator(den)
{
}
void Rational::addition(Rational c)
{
numerator = numerator + c.numerator;
denominator = denominator + c.denominator;
reduction();
}
void Rational::subtraction(Rational c)
{
numerator = numerator - c.numerator;
denominator = denominator - c.denominator;
reduction();
}
void Rational::multiplication(Rational c)
{
numerator = numerator * c.numerator;
denominator = denominator * c.denominator;
reduction();
}
#include "Rational.h" // include definition of class Rational
int main()
{
Rational c( 2, 6 ), d( 7, 8 ), x; // creates three rational objects
c.printRational(); // prints rational object c
cout << " + ";
d.printRational(); // prints rational object d
x = c.addition( d ); // adds object c and d; sets the value to x
cout << " = ";
x.printRational(); // prints rational object x
cout << '\n';
x.printRational(); // prints rational object x
cout << " = ";
x.printRationalAsDouble(); // prints rational object x as double
cout << "\n\n";
c.printRational(); // prints rational object c
cout << " - ";
d.printRational(); // prints rational object d
x = c.subtraction( d ); // subtracts object c and d
cout << " = ";
x.printRational(); // prints rational object x
cout << '\n';
x.printRational(); // prints rational object x
cout << " = ";
x.printRationalAsDouble(); // prints rational object x as double
cout << "\n\n";
c.printRational(); // prints rational object c
cout << " x ";
d.printRational(); // prints rational object d
x = c.multiplication( d ); // multiplies object c and d
cout << " = ";
x.printRational(); // prints rational object x
cout << '\n';
x.printRational(); // prints rational object x
cout << " = ";
x.printRationalAsDouble(); // prints rational object x as double
cout << "\n\n";
c.printRational(); // prints rational object c
cout << " / ";
d.printRational(); // prints rational object d
x = c.division( d ); // divides object c and d
cout << " = ";
x.printRational(); // prints rational object x
cout << '\n';
x.printRational(); // prints rational object x
cout << " = ";
x.printRationalAsDouble(); // prints rational object x as double
cout << endl;
system("pause");
return 0;
} // end main