#include <iostream>
//#include "Rational.hpp"
using namespace std;

class Rational
{
      public:
             int arithmitis;
             int paronomastis;
             
             void set(int x, int y)
             {
                  arithmitis = x;
                  paronomastis = y;
             }
             
             void addition(Rational r1, Rational r2)
             {
                  arithmitis = r1.arithmitis*r2.paronomastis + r2.arithmitis*r1.paronomastis;
                  paronomastis = r1.paronomastis * r2.paronomastis;
             }
             
             void subtraction(Rational r1, Rational r2)
             {
                  arithmitis = r1.arithmitis*r2.paronomastis - r2.arithmitis*r1.paronomastis;
                  paronomastis = r1.paronomastis * r2.paronomastis;
             }

             void multiplication(Rational r1, Rational r2)
             {
                  arithmitis = r1.arithmitis * r2.arithmitis;
                  paronomastis = r1.paronomastis * r2.paronomastis;
             }
            
             void printr()
             {
                  std::cout << arithmitis << "/" << paronomastis << endl;
             }
             
             void print()
             {
                  std::cout << (double)arithmitis/paronomastis << endl;
             }
};

Rational inverse(Rational r1)
{
         Rational r2;
         r2.arithmitis = r1.paronomastis;
         r2.paronomastis = r1.arithmitis;
                      
         return (r2);
}
             
int main() {
    
    Rational r1, r2, r3;
    Rational sum, sub, mul;
    
    r1.set(1,2);
    r2.set(2,5);
    
// Print rational numbers (as rationals)
    cout << " r1 = ";
    r1.printr();
    cout << " r2 = ";    
    r2.printr();
    cout << endl;

// Print rational numbers (as real numbers)    
    cout << " r1 = ";
    r1.print();
    cout << " r2 = ";        
    r2.print();
    cout << endl;    
    
// Print r1 + r2
   sum.addition(r1,r2);
   cout << " r1 + r2 = ";
   sum.printr();
       
// Print r1 - r2
   sub.subtraction(r1,r2);
   cout << " r1 - r2 = ";   
   sub.printr();
   
// Print r1 * r2
   mul.multiplication(r1,r2);
   cout << " r1 * r2 = ";   
   mul.printr(); 

   cout << endl << endl;

// Inverse of r1. i.e. r3 = 1/r1
   r3 = inverse(r2);
   cout << " r3 = ";
   r3.printr();
// or we can use inverse(r1).printr();

   std::cin.get();
   return (0);       
}
             
