#include <iostream>
#include <math.h>
#include "racional.h"

using namespace std;

Racional::Racional(double x){
  
}

double Racional::racionalAflotante(){
  return (double)num/(double)den;
}

Racional Racional::operator^(int n){
  Racional r;
  int i,s=1;
  for(i=1;i<=n;i++) s *= num;
  r.num = s;
  s = 1;
  for(i=1;i<=n;i++) s *= den;
  r.den = s;
  return r;
}

Racional Racional::operator+(Racional a) {
  Racional r;
  r.num = num*a.den+den*a.num;
  r.den = den*a.den;
  return r;
}

Racional Racional::operator-(Racional a) {
  Racional r;
  r.num = num*a.den-den*a.num;
  r.den = den*a.den;
  return r;
}

Racional Racional::operator*(Racional a) {
  Racional r;
  r.num = num*a.num;
  r.den = den*a.den;
  return r;
}

Racional Racional::operator/(Racional a) {
  Racional r;
  r.num = num*a.den;
  r.den = den*a.num;
  return r;
}

void Racional::escribe(){
  cout << num << "/" << den << "\n";
}

