Advertisement
DenCoder618

Rational.h

May 25th, 2022
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.30 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <stdlib.h>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. #define INVERSE true
  9.  
  10. class Rational
  11. {
  12. private:
  13.     long long _integer;     // целая часть
  14.     long long _numerator;   // числитель
  15.     long long _denominator; // знаминатель
  16.  
  17. public:
  18.     Rational(long long numerator = 0, long long denominator = 1);
  19.     Rational(const Rational &temp, bool invert = false);
  20.  
  21.     Rational &set(long long numerator, long long denominator);
  22.     long long &integer();
  23.     long long &numerator();
  24.     long long &denominator();
  25.  
  26.     double get_value();
  27.     Rational &simplify();
  28.     Rational &normalize(); // вычисление целой части числа
  29.     Rational &denormalize(); // обратное действие для упрощения вычислений
  30.  
  31.     friend istream &operator>>(istream &in, Rational &temp);
  32.     friend ostream &operator<<(ostream &out, const Rational &temp);
  33.  
  34.     Rational &operator=(const Rational &temp);
  35.     Rational &operator=(const long long &temp);
  36.  
  37.     friend bool operator==(const Rational &r1, const Rational &r2);
  38.     friend bool operator!=(const Rational &r1, const Rational &r2);
  39.  
  40.     // унарные операторы
  41.     const Rational operator+(); // = delete; // унарный плюс бесполезен
  42.     const Rational operator-();
  43.  
  44.     // префиксный инкремент
  45.     Rational &operator++();
  46.     Rational &operator--();
  47.  
  48.     // постфиксный инкремент
  49.     Rational operator++(int);
  50.     Rational operator--(int);
  51.  
  52.     friend Rational operator+(const Rational &r1, const Rational &r2);
  53.     friend Rational operator+(const Rational &r, long long value);
  54.     friend Rational operator+(long long value, const Rational &r);
  55.  
  56.     friend Rational operator-(const Rational &r1, const Rational &r2);
  57.     friend Rational operator-(const Rational &r, long long value);
  58.     friend Rational operator-(long long value, const Rational &r);
  59.  
  60.     friend Rational operator*(const Rational &r1, const Rational &r2);
  61.     friend Rational operator*(const Rational &r, long long value);
  62.     friend Rational operator*(long long value, const Rational &r);
  63.  
  64.     friend Rational operator/(const Rational &r1, const Rational &r2);
  65.     friend Rational operator/(const Rational &r, long long value);
  66.     friend Rational operator/(long long value, const Rational &r);
  67.  
  68.     friend Rational &operator+=(Rational &left, const Rational &right);
  69.     friend Rational &operator+=(Rational &left, const long long &right);
  70.  
  71.     friend Rational &operator-=(Rational &left, const Rational &right);
  72.     friend Rational &operator-=(Rational &left, const long long &right);
  73.  
  74.     friend Rational &operator*=(Rational &left, const Rational &right);
  75.     friend Rational &operator*=(Rational &left, const long long &right);
  76.  
  77.     friend Rational &operator/=(Rational &left, const Rational &right);
  78.     friend Rational &operator/=(Rational &left, const long long &right);
  79.  
  80.     friend bool operator>(const Rational &r1, const Rational &r2);
  81.     friend bool operator<=(const Rational &r1, const Rational &r2);
  82.  
  83.     friend bool operator<(const Rational &r1, const Rational &r2);
  84.     friend bool operator>=(const Rational &r1, const Rational &r2);
  85.  
  86.     friend void ShellSort(int n, Rational* mass[]);
  87. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement