Aaaaa988

Untitled

Sep 27th, 2020 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #pragma once
  2. #include <string>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. class TFrac {
  7. private:
  8.     int numerator;
  9.     int denominator;
  10.     int gcd(int a, int b);
  11. public:
  12.     TFrac();
  13.     TFrac(int a, int b);
  14.     TFrac(string fraction);
  15.     TFrac(const TFrac &anotherFrac);
  16.     TFrac operator-();
  17.  
  18.     TFrac add(const TFrac &anotherFrac);
  19.     TFrac multiply(const TFrac &anotherFrac);
  20.     TFrac substract(const TFrac &anotherFrac);
  21.     TFrac divide(const TFrac &anotherFrac);
  22.     TFrac square();
  23.     TFrac reverse();
  24.  
  25.     bool operator==(const TFrac &anotherFrac);
  26.     bool operator>(const TFrac &anotherFrac);
  27.     TFrac operator=(const TFrac &anotherFrac) const {
  28.         if (&anotherFrac == this)
  29.             return *this;
  30.         return TFrac(anotherFrac.numerator, anotherFrac.denominator);
  31.     }
  32.  
  33.     bool operator< (const TFrac & anotherFrac) const {
  34.         if (float(this->numerator) / float(this->denominator)
  35.             < float(anotherFrac.numerator) / float(anotherFrac.denominator))
  36.             return true;
  37.         else
  38.             return false;
  39.     }
  40.  
  41.     int getNumeratorNumber();
  42.     int getDenominatorNumber();
  43.     string getNumeratorString();
  44.     string getDenominatorString();
  45.     string getFractionString();
  46.     ~TFrac();
  47. };
  48.  
Add Comment
Please, Sign In to add comment