'Don't know what Im doing wrong-adding,subtracting,dividing,multiplying rationals in c++

This is the code that I wrote so far. Not sure what I am doing wrong. Every time I try to run it it displays "Invalid operands to binary expression" next to the "cin >> rational_2;" in the main file. If there is any that could help me I could deeply appreciate it. Also, provided the description what I need to do at the bottom.

  1. Rational Arithmetic I A rational number is a quotient of two integers. For example, 12/5, 12/–4, –3/4, and 4/6 are all rational numbers. A rational number is said to be in reduced form if its denominator is positive and its numerator and denominator have no common divisor other than 1. For example, the reduced forms of the rational numbers given above are 12/5, –3/1, –3/4, and 2/3.

Write a class called Rational with a constructor Rational(int, int) that takes two integers, a numerator and a denominator, and stores those two values in reduced form in corresponding private members. Ensure that the denominator is not 0. The class should have a private member function void reduce() that is used to accomplish the transformation to reduced form. The class should have an overloaded insertion operator << that will be used for output of objects of the class.

  1. Rational Arithmetic II Modify the class Rational of Programming Challenge 8 to add overloaded operators +, −, *, and / to be used for addition, subtraction, multiplication, and division.

#include <iostream>

using namespace std;

class Rational
{
private:
    int denom;
    int numer;
    void reduce();
    
public:
    Rational();
    Rational(int num, int den);
    
    //********** overloading mathematical operators ************
    Rational operator-(const Rational& rightFr);
    Rational operator*(const Rational& rightFr);
    Rational operator/(const Rational& rightFr);
    Rational operator+(const Rational& rightFr);
    
    
    //********** overloading relational operators ************
    bool operator == (const Rational& rightFr);
    
    
    // F R I E N D     F U N C T I I O N S
     friend ostream& operator<<(ostream& the_output, Rational&);


};

//Rational.cpp file
#include "Rational.h"

Rational::Rational()
{
    
}

Rational::Rational(int num, int den)
{
    numer = num;
    denom = den;
    reduce();
}
// reduce method
void Rational::reduce()
{
    int topnum;
    
    if (numer > denom )
    {
        topnum = numer;
    }
    else
    {
        topnum = denom;
    }
    
    int divisor = 2;
    while (divisor <= topnum)
    {
        if (numer%divisor == 0 && denom%divisor == 0)
        {
            numer /= divisor;
            denom /= divisor;
            divisor =2;
        }
        else
        {
            divisor++;
        }
        
    }
    
    if(denom < 0 )
    {
        denom *= -1;
        numer *= -1;
    }
}
// Operator Overload for Adding
Rational Rational:: operator+(const Rational &rightFr){
    
    Rational ret_val( 1, 1);
    
    ret_val.numer = this ->numer * rightFr.denom + this->denom * rightFr.numer;
    
    ret_val.denom = this-> denom + rightFr.denom;
    
    
    return ret_val;
}

// Operator Overload for Sub
Rational Rational:: operator-(const Rational &rightFr){
    
    Rational ret_val( 1, 1);
    
    ret_val.numer = this ->numer * rightFr.denom - this->denom * rightFr.numer;
    
    ret_val.denom = this-> denom - rightFr.denom;
    
    
    return ret_val;
}

// Operator Overload for Mult.
Rational Rational::operator * (const Rational &rightFr){
    Rational ret_val(1,1);
    ret_val.numer = this ->numer * rightFr.numer;
    ret_val.denom = this ->numer * rightFr.numer;
    reduce();
    
    return ret_val;
}

Rational Rational::operator / (const Rational &rightFr){
    Rational ret_val(1,1);
    ret_val.numer = this ->numer * rightFr.numer;
    ret_val.denom = this ->denom * rightFr.denom;
    reduce();
    
    return ret_val;
}

bool Rational::operator==(const Rational &rightFr)
{
    bool answer = false;
    if( numer == rightFr.numer && this-> denom == rightFr.denom)
    {
        answer = true;
    }
    
    return answer;
    
}

// friend functions
ostream& operator<<(ostream& the_output, Rational& obj ){
    the_output << obj.numer <<"/"<< obj.denom << endl;
    return the_output;
}


//main file
#include <iostream>
#include <iomanip>
#include "Rational.h"

using namespace std;

int main()
{
    Rational rational_1(5, 6);
    Rational rational_2;
    Rational rational_Add, rational_Sub, rational_Mult, rational_Divide;
    cout << "Enter numerator and denominator separated by a space :";
    cin >> rational_2; // this is were I get the error

    rational_Add = rational_1 + rational_2;
    rational_Sub = rational_1 - rational_2;
    rational_Mult = rational_1 * rational_2;
    rational_Divide = rational_1 / rational_2;

    cout << "rational_1 : " << rational_1 << endl
        << "rational_2 : " << rational_2 << endl
        << "rational_Add : " << rational_Add << endl
        << "rational_Sub : " << rational_Sub << endl
        << "rational_Mult : " << rational_Mult << endl
        << "rational_Divide : " << rational_Divide << endl;


    return 0;
}



Solution 1:[1]

cin >> rational_2; // this is were I get the error

Please implement istream operator overloading operator>>. For example,

friend istream& operator>>(istream& is, Rational& obj) {
        is >> obj.numer >> obj.denom;
    return is;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GAVD