Advertisement
rex897

ррррррр

Jan 15th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. class dpoint
  7. {
  8. private:
  9.     double *px;
  10.     double *py;
  11. public:
  12.     dpoint() //контсрруктор без параметров
  13.     {
  14.         px = new double(0);
  15.         py = new double(0);
  16.     }
  17.     dpoint(double x, double y) //конструктор инициализирующий (с параметрами)
  18.     {
  19.         px = new double(x);
  20.         py = new double(y);
  21.     }
  22.     ~dpoint() //деструктор
  23.     {
  24.         if (px != NULL) delete px;
  25.         if (py != NULL) delete py;
  26.     }
  27.     dpoint(dpoint &z) //онстркутор копирования
  28.     {
  29.         px = new double(*z.px);
  30.         py = new double(*z.py);
  31.     }
  32.     dpoint& operator=(dpoint &z)// перегрузка операции присваивания
  33.     {
  34.         if (this == &z) return z;
  35.         *px = *z.px;
  36.         *py = *z.py;
  37.     }
  38.     friend int operator!=(dpoint p1, dpoint p2)
  39.     {
  40.         if (p1.px != p2.px) return 1;
  41.         if (p1.py != p2.py) return 1;
  42.         return 0;
  43.     }
  44.     void output()
  45.     {
  46.         cout << "x= " << *px << " y= " << *py << endl;
  47.     }
  48.     void input()
  49.     {
  50.         cout << "x= ";
  51.         cin >> *px;
  52.         cout << "y= ";
  53.         cin >> *py;
  54.     }
  55. };
  56.  
  57. class treug
  58. {
  59. private:
  60.     dpoint a;
  61.     dpoint *pb;
  62.     dpoint *pc;
  63. public:
  64.     treug()
  65.     {
  66.         pb = new dpoint(0, 0);
  67.         pc = new dpoint(0, 0);
  68.     }
  69.     treug(double x1, double y1, double x2, double y2, double x3, double y3) : a(x1, y1)
  70.     {
  71.         pb = new dpoint(x2, y2);
  72.         pc = new dpoint(x3, y3);
  73.     }
  74.     ~treug()
  75.     {
  76.         if (pb != NULL) delete pb;
  77.         if (pc != NULL) delete pc;
  78.     }
  79.     treug(treug &z)
  80.     {
  81.         a = z.a;
  82.         pb = new dpoint(*z.pb);
  83.         pc = new dpoint(*z.pc);
  84.     }
  85.     treug& operator=(treug &z)
  86.     {
  87.         if (this == &z) return z;
  88.         a = z.a;
  89.         *pb = *z.pb;
  90.         *pc = *z.pc;
  91.     }
  92.     friend void input(treug &);
  93.     void output()
  94.     {
  95.         a.output();
  96.         pb->output();
  97.         pc->output();
  98.     }
  99. };
  100.  
  101. void input(treug &tr)
  102. {
  103.     tr.a.input();
  104.     tr.pb->input();
  105.     tr.pc->input();
  106. }
  107.  
  108. void main()
  109. {
  110.     treug t(1,2,3,4,5,6);
  111.     treug t1 = t;
  112.     t1.output();
  113.     _getch();
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement