Arkanium77

Segment

Jun 26th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7. /*
  8.  *
  9.  *    Программное обеспечение пожирает мир.
  10.  *                                       — Марк Андрессен
  11.  *
  12.  */
  13.  
  14. class Segment {
  15. private:
  16.     double x, xx;
  17.     double y, yy;
  18. public:
  19.  
  20.     Segment(double x = 0, double y = 0, double xx = 0, double yy = 0) {
  21.         this->x = x;
  22.         this->y = y;
  23.         this->xx = xx;
  24.         this->yy = yy;
  25.     };
  26.  
  27.     Segment random() {
  28.         srand(time(0));
  29.         return Segment(rand() % 31 - 15, rand() % 31 - 15, rand() % 31 - 15, rand() % 31 - 15);
  30.     };
  31.  
  32.     friend ostream& operator<<(ostream& os, const Segment& at) {
  33.         os << "x=" << at.x << ", y=" << at.y << "  ->  x1=" << at.xx << ", y1=" << at.yy;
  34.         return os;
  35.     };
  36.    
  37.     //Длинна отрезка
  38.     double length() {
  39.         return sqrt(pow(xx - x, 2) + pow(yy - y, 2));
  40.     };
  41.  
  42.     bool equals(Segment a) {
  43.         if (this->length() == a.length())return true;
  44.         return false;
  45.     };
  46.  
  47.     bool operator==(Segment a) {
  48.         return this->equals(a);
  49.     };
  50.  
  51.     bool operator!=(Segment a) {
  52.         return !(this->equals(a));
  53.     };
  54.  
  55.     void operator=(Segment b) {
  56.         this->x = b.x;
  57.         this->y = b.y;
  58.         this->xx = b.xx;
  59.         this->yy = b.yy;
  60.     };
  61.  
  62. };
Advertisement
Add Comment
Please, Sign In to add comment