SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     Fractions operator+(Fractions &y){
  2.         Fractions temp;
  3.         //er = &temp;
  4.         temp.numerator = (numerator * y.denominator) + (y.numerator * denominator);
  5.         temp.denominator = denominator * y.denominator;
  6.         temp.reduction();
  7.         return temp;
  8.     }
  9.     Fractions operator-(Fractions &y){
  10.         Fractions temp;
  11.         //er = &temp;
  12.         temp.numerator = (numerator * y.denominator) - (y.numerator * denominator);
  13.         temp.denominator = denominator * y.denominator;
  14.         temp.reduction();
  15.         return temp;
  16.     }
  17.     Fractions operator/(Fractions &y){
  18.         Fractions temp;
  19.         //er = &temp;
  20.         temp.numerator = numerator * y.denominator;
  21.         temp.denominator = denominator * y.numerator;
  22.         temp.reduction();
  23.         return temp;
  24.     }
  25.     Fractions operator*(Fractions &y){
  26.         Fractions temp;
  27.         //er = &temp;
  28.         temp.numerator = numerator * y.numerator;
  29.         temp.denominator = denominator * y.denominator;
  30.         temp.reduction();
  31.         return temp;
  32.     }
  33.     Fractions operator*(const int &y){
  34.         Fractions temp,tempy;
  35.         //er = &temp;
  36.         //tempy.numerator = y;
  37.         //tempy.denominator = 1;
  38.         temp.numerator = numerator * y;
  39.         temp.denominator = denominator;
  40.         temp.reduction();
  41.         return temp;
  42.     }
  43.     Fractions &operator=(Fractions &y){
  44.         if(this == &y)
  45.             return *this;
  46.        
  47.         numerator = y.numerator;
  48.         denominator = y.denominator;
  49.         reduction();
  50.         return *this;
  51.     }
  52.     Fractions &operator=(const int &y){
  53.         numerator = y;
  54.         denominator = 1;
  55.         return *this;
  56.     }
  57.     void reduction(){
  58.         int min, d, n;
  59.         n = numerator;
  60.         d = denominator;
  61.         if (n<d){
  62.             min = n;
  63.         }
  64.         else
  65.             min = d;
  66.         bool flag = true;
  67.         while(flag){
  68.             flag = false;
  69.             for (int i = 2; i<=min; i++)
  70.                 if (n%i==0 && d%i==0){
  71.                     n = n/i;
  72.                     d = d/i;
  73.                     flag = true;
  74.                 }
  75.         }
  76.         numerator = n;
  77.         denominator = d;
  78.         std::cout << "reduction reduction" << std::endl;
  79.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top