Advertisement
dizzy94

Untitled

Jun 27th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Segment {
  6.     double A, B;
  7. public:
  8.     Segment(double A, double B) : A(A), B(B) { }
  9.  
  10.     friend ostream & operator<< (ostream &wyjscie, const Segment &s);
  11.    
  12.     const Segment operator*(int &d) {
  13.         return Segment(A*d, B*d);
  14.     };
  15.  
  16.     const Segment operator/(int &d) {
  17.         return Segment(A/d, B/d);
  18.     };
  19.  
  20.     const Segment operator+(int &d) {
  21.         return Segment(A + d, B + d);
  22.     };
  23.  
  24.     const Segment operator-(int &d) {
  25.         return Segment(A-d, B-d);
  26.     };
  27.  
  28.     const Segment operator-(Segment &s) {
  29.         return Segment(A + s.A, B + s.B);
  30.     };
  31.  
  32.     const bool operator()(double &d) {
  33.         if (d == A || d == B)
  34.             return true;
  35.         else { false; }
  36.     };
  37.  
  38. };
  39.  
  40. ostream & operator<< (ostream &wyjscie, const Segment &s) {
  41.     return wyjscie << s.A << " " << s.B << endl;
  42. }
  43.  
  44. int main() {
  45.     using std::cout; using std::endl;
  46.     Segment seg{ 2,3 }, s = 1 + 2 * ((seg - 2) / 2 + seg) / 3;
  47.     cout << s << endl << std::boolalpha;
  48.     for (double x = 0.5; x < 4; x += 1)
  49.         cout << "x=" << x << ": " << s(x) << endl;
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement