Advertisement
rex897

еееееее

Jan 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class dpoint {
  4.     double *px;
  5.     double y;
  6. public:
  7.     double getPx() const;
  8.  
  9.     double getY() const;
  10.  
  11.     dpoint(double ix, double iy) {
  12.         px = new double(ix);
  13.         y = iy;
  14.     }
  15.  
  16. /*    dpoint(dpoint &a) {
  17.         px = new double(*a.px);
  18.         y = a.y;
  19.     }*/
  20.  
  21.     ~dpoint() {
  22.         delete px;
  23.     }
  24.  
  25.     friend std::istream &operator>>(std::istream &in, dpoint &var) {
  26.         in >> *var.px >> var.y;
  27.         return in;
  28.     }
  29.  
  30.     friend void increaseCoordinate(dpoint &a, double dx, double dy);
  31.  
  32.     friend std::ostream &operator<<(std::ostream &os, const dpoint &dpoint1);
  33.  
  34.     dpoint& operator=(dpoint& a){
  35.         px = new double(*a.px);
  36.         y = a.y;
  37.     }
  38. };
  39.  
  40.  
  41. void increaseCoordinate(dpoint &a, double dx, double dy) {
  42.     std::cout << "\n inc " << *a.px << " " << a.y << "\n";
  43.     if (a.px == nullptr) {
  44.         a.px = new double(dx);
  45.     } else
  46.         *a.px += dx;
  47.     a.y += dy;
  48. }
  49.  
  50. std::ostream &operator<<(std::ostream &os, const dpoint &dpoint1) {
  51.     os << "px: " << *dpoint1.px << " y: " << dpoint1.y;
  52.     return os;
  53. }
  54.  
  55. double dpoint::getPx() const {
  56.     return *px;
  57. }
  58.  
  59. double dpoint::getY() const {
  60.     return y;
  61. }
  62.  
  63. class interval {
  64.     dpoint a;
  65.     dpoint b;
  66. public:
  67.  
  68. //    interval(const dpoint &a, const dpoint &b) : a(a), b(b) {}
  69.     interval(double ax, double ay, double bx, double by): a(ax,ay), b(bx,by){}
  70.     interval(interval &i2) : a(i2.a.getPx(),i2.a.getY()),b(i2.b.getPx(),i2.b.getY()) {}
  71.  
  72.     friend void swap(interval &m) {
  73.         dpoint c(m.a.getPx(),m.a.getY());
  74.         m.a = m.b;
  75.         m.b = c;
  76.     }
  77.  
  78.     void showPoints() {
  79.         std::cout << "xa " << a.getPx() << " ya " << a.getY() << " xb " << b.getPx() << " yb " << b.getY() << "\n";
  80.     }
  81.  
  82.     friend std::istream &operator>>(std::istream &in, interval& x) {
  83.         in >> x.a >> x.b;
  84.         return in;
  85.     }
  86. };
  87.  
  88. int main() {
  89.     dpoint t(3.1, 77.9), a(1, 1);
  90.     std::cout << t << "\nВведите 2 точки\n";
  91.     std::cin >> a;
  92.     std::cout << "magic:\n" << a << "\n";
  93.     increaseCoordinate(a, 5.5, 1.1); std::cout << a << "\n-----------\n";
  94.  
  95. //    interval i1(dpoint(1.1, 2.2), dpoint(3.3, 4.4));
  96. //    interval i1(t, a);
  97.     interval i1(6,7,8,9);
  98.     std::cout << "i1\n";
  99.     i1.showPoints();
  100.     interval i2(i1);
  101.     std::cout << "i2\n";
  102.     i2.showPoints();
  103.     std::cout << "ESHE 4 tochki\n";
  104.     std::cin >> i2;
  105.     std::cout << "i2\n";
  106.     i2.showPoints();
  107.     std::cout << "i1\n";
  108.     i1.showPoints();
  109.     swap(i1);
  110.     std::cout << "i1\n";
  111.     i1.showPoints();
  112.  
  113.     return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement