Advertisement
Guest User

harkach

a guest
Sep 22nd, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Fraction
  5. {
  6. private:
  7.     int value, x, y, z;
  8. public:
  9.     Fraction::Fraction() {};
  10.     Fraction(int a) : value(a) {};
  11.  
  12.     friend const Fraction& operator+(const Fraction& a);
  13.  
  14.     friend const Fraction operator-(const Fraction& a);
  15.  
  16.     friend const Fraction& operator*(const Fraction& a);
  17.  
  18.     friend const Fraction& operator/(const Fraction& a, const Fraction& b);
  19.  
  20.     friend bool operator==(const Fraction& a, const Fraction& b);
  21.  
  22.     Fraction& operator=(const Fraction& a)
  23.     {
  24.  
  25.         if (this == &a)
  26.         {
  27.             return *this;
  28.         }
  29.         value = a.value;
  30.         return *this;
  31.     }
  32.  
  33.     friend bool operator!=(const Fraction &a, const Fraction &b);
  34.  
  35.     friend bool operator<(Fraction const & a, Fraction const & b);
  36.  
  37.     friend bool operator>(Fraction const & a, Fraction const & b);
  38.  
  39.     friend ostream& operator << (ostream &a, const Fraction &b);
  40.  
  41.     friend istream& operator >> (istream &a, Fraction &b);
  42.  
  43.  
  44. };
  45.  
  46.  
  47.  
  48.  
  49. const Fraction& operator+(const Fraction& a)
  50. {
  51.     return a.value;
  52. }
  53.  
  54. const Fraction operator-(const Fraction& a)
  55. {
  56.     return Fraction(-a.value);
  57. }
  58.  
  59. const Fraction& operator*(const Fraction& a)  
  60. {
  61.     return a.value;
  62. }
  63.  
  64. const Fraction& operator/(const Fraction& a, const Fraction& b)
  65. {
  66.     return Fraction(-a.value);
  67. }
  68.  
  69. bool operator==(const Fraction& a, const Fraction& b)
  70. {
  71.     return a.value == b.value;
  72. }
  73.  
  74. bool operator!=(const Fraction &a, const Fraction &b)
  75. {
  76.     return !(a == b);
  77. }
  78.  
  79. bool operator <(Fraction const & a, Fraction const & b)
  80. {
  81.     return a < b;
  82. }
  83.  
  84. bool operator >(Fraction const & a, Fraction const & b)
  85. {
  86.     return a > b;
  87. }
  88.  
  89. ostream& operator << (ostream &a, const Fraction &b)
  90. {
  91.     a << '(' << b.x << ", " << b.y << ", " << b.z << ')';
  92.     return a;
  93. }
  94.  
  95. istream& operator >> (istream &a, Fraction &b)
  96. {
  97.     cout << "Введите Fraction.\nX:";
  98.     cin >> b.x;
  99.     cout << "\nY:";
  100.     cin >> b.y;
  101.     cout << "\nZ:";
  102.     cin >> b.z;
  103.     cout << endl;
  104.     return a;
  105. }
  106.  
  107. int main() {
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement