Advertisement
Arkanium77

LinePoint

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