#include <iostream>

using namespace std;

class Rat{
public:
    int numer;
    int denom;
    Rat(int num = 0, int den = 1): numer(num), denom(den){cout << "ctor\n";}
    Rat(const Rat&);
    Rat& operator=(const Rat& rhs);
    friend Rat operator+(const Rat& lhs, const Rat& rhs);
    friend ostream& operator<<(ostream& o, Rat& rhs);
};

Rat operator+(const Rat& lhs, const Rat& rhs){
    int num = lhs.numer * rhs.denom + rhs.numer * lhs.denom;
    return Rat(num, rhs.denom * lhs.denom);
}

ostream& operator<<(ostream& o, Rat& rhs){
    o << rhs.numer << "/" << rhs.denom;
    return o;
}

Rat& Rat::operator=(const Rat& rhs){
    numer = rhs.numer;
    denom = rhs.denom;
    return *this;
}

Rat::Rat(const Rat& other){
    cout << "copy ctor\n";
    numer = other.numer;
    denom = other.denom;
}

int main(){

    Rat a(3,2);
    Rat b(5);

    Rat c = a;
    cout << c << endl;
    c = a + b;
    cout << c << endl;
    Rat d = 6 + c;
    cout << d << endl;
    Rat e = 2;
    cout << e << endl;


    return 0;
}

