Arkanium77

PlanePoint

Jun 26th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 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.  
  15. class PlanePoint {
  16.     double x, y;
  17.  
  18. public:
  19.  
  20.     PlanePoint(double x = 0, double y = 0) {
  21.         this->x = x;
  22.         this->y = y;
  23.     };
  24.  
  25.     PlanePoint(const PlanePoint &a) {
  26.         this->x = a.x;
  27.         this->y = a.y;
  28.     };
  29.  
  30.     PlanePoint random() {
  31.         srand(time(0));
  32.         return PlanePoint(rand() % 31 - 15, rand() % 31 - 15);
  33.     };
  34.    
  35.     //Расстояние между двумя точками
  36.     double distance(PlanePoint a) {
  37.         return sqrt(pow(a.x - x, 2) + pow(a.y - y, 2));
  38.     };
  39.  
  40.     bool equals(PlanePoint a) {
  41.         if (a.rad() == this->rad())
  42.             return true;
  43.         return false;
  44.     };
  45.  
  46.     bool operator==(PlanePoint a) {
  47.         return this->equals(a);
  48.     };
  49.  
  50.     bool operator!=(PlanePoint a) {
  51.         return !(this->equals(a));
  52.     };
  53.  
  54.     void operator=(PlanePoint b) {
  55.         this->x = b.x;
  56.         this->y = b.y;
  57.     };
  58.  
  59.     friend ostream& operator<<(ostream& os, const PlanePoint& at) {
  60.         os << "x=" << at.x << ", y=" << at.y;
  61.         return os;
  62.     };
  63.    
  64.     //Расстояние до центра
  65.     double rad() {
  66.         return sqrt(pow(x, 2) + pow(y, 2));
  67.     };
  68. };
Advertisement
Add Comment
Please, Sign In to add comment