tomasaccini

Untitled

Jul 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Pareja {
  6. public:
  7.     double a, b;
  8.     bool operator > (const Pareja& other) const;
  9.     Pareja& operator = (const Pareja& other) {
  10.         if (*this == other) return *this;
  11.         a = other.a;
  12.         b = other.b;
  13.         return *this;
  14.     }
  15.  
  16.     operator int() const {
  17.         return (int)(a+b);
  18.     }
  19.  
  20.     Pareja operator +(const Pareja& other) const{
  21.         Pareja temp = *this;
  22.         temp.a += other.a;
  23.         temp.b += other.b;
  24.         return temp;
  25.     }
  26.  
  27.     Pareja operator -(const Pareja& other) const{
  28.         Pareja temp = *this;
  29.         temp.a -= other.a;
  30.         temp.b -= other.b;
  31.         return temp;
  32.     }
  33.  
  34.     Pareja operator *(const Pareja& other) const{
  35.         Pareja temp = *this;
  36.         temp.a -= other.a;
  37.         temp.b -= other.b;
  38.         return temp;
  39.     }
  40.  
  41.     //Prefix:
  42.     Pareja& operator ++(void) {
  43.         ++a;
  44.         ++b;
  45.         return *this;
  46.     }
  47.     //Posfix
  48.     Pareja operator ++(int) {
  49.         Pareja temp = *this;
  50.         a++;
  51.         b++;
  52.         return temp;
  53.     }
  54.  
  55.     // Shift left
  56.     Pareja operator <<(unsigned int shift) const{
  57.         Pareja temp = *this;
  58.         temp.a = (int)temp.a << shift;
  59.         temp.b = (int)temp.b << shift;
  60.         return temp;
  61.     }
  62.  
  63.     // Shift right
  64.     Pareja operator >>(unsigned int shift){
  65.         Pareja temp = *this;
  66.         temp.a = (int)temp.a >> shift;
  67.         temp.b = (int)temp.b >> shift;
  68.         return temp;
  69.     }
  70.  
  71.     friend ostream& operator << (ostream& o, const Pareja& p);
  72.     friend istream& operator >> (istream& i, const Pareja& p);
  73. };
  74.  
  75. ostream& operator << (ostream& o, const Pareja& p){
  76.     o << "( " << p.a << " , " << p.b << " )";
  77.     return o;
  78. }
  79.  
  80. istream& operator >> (istream& i, const Pareja& p){
  81.     // Sarasa
  82.     return i;
  83. }
  84.  
  85. int main(){
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment