daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <math.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Complex{
  8.     float r;
  9.     float i;
  10. public:
  11.     Complex(float r = 0, float i = 0)
  12.         : r(r)
  13.         , i(i)
  14.     {}
  15.     bool operator> (const Complex& c) {
  16.         return sqrt(r * r + i * i) > sqrt(c.r * c.r + c.i * c.i);
  17.     }
  18.     friend ostream& operator<< (ostream &out, const Complex &c);
  19.     friend istream& operator>> (istream &in, Complex& c);
  20. };
  21.  
  22. ostream& operator<< (ostream &out, const Complex &c)
  23. {
  24.     out << c.r << " + " << c.i << "i\n";
  25.     return out;
  26. }
  27.  
  28. istream& operator>> (istream &in, Complex &c)
  29. {
  30.     in >> c.r >> c.i;
  31.     return in;
  32. }
  33.  
  34. template <class T>
  35. T GetMax(T a, T b) {
  36.     if (a > b)
  37.         return a;
  38.     return b;
  39. }
  40.  
  41. int main() {
  42.     int i = 5, j = 6, k;
  43.     long l = 10, m = 5, n;
  44.     k = GetMax<int>(i, j);
  45.     n = GetMax<long>(l, m);
  46.     cout << k << endl;
  47.     cout << n << endl;
  48.     //
  49.     Complex c1;
  50.     Complex c2;
  51.     cin >> c1;
  52.     cin >> c2;
  53.     cout << GetMax<Complex>(c1, c2);
  54.  
  55.     return 0;
  56. }
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