Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- class dpoint
- {
- private:
- double *px;
- double *py;
- public:
- dpoint() //контсрруктор без параметров
- {
- px = new double(0);
- py = new double(0);
- }
- dpoint(double x, double y) //конструктор инициализирующий (с параметрами)
- {
- px = new double(x);
- py = new double(y);
- }
- ~dpoint() //деструктор
- {
- if (px != NULL) delete px;
- if (py != NULL) delete py;
- }
- dpoint(dpoint &z) //онстркутор копирования
- {
- px = new double(*z.px);
- py = new double(*z.py);
- }
- dpoint& operator=(dpoint &z)// перегрузка операции присваивания
- {
- if (this == &z) return z;
- *px = *z.px;
- *py = *z.py;
- }
- friend int operator!=(dpoint p1, dpoint p2)
- {
- if (p1.px != p2.px) return 1;
- if (p1.py != p2.py) return 1;
- return 0;
- }
- void output()
- {
- cout << "x= " << *px << " y= " << *py << endl;
- }
- void input()
- {
- cout << "x= ";
- cin >> *px;
- cout << "y= ";
- cin >> *py;
- }
- };
- class treug
- {
- private:
- dpoint a;
- dpoint *pb;
- dpoint *pc;
- public:
- treug()
- {
- pb = new dpoint(0, 0);
- pc = new dpoint(0, 0);
- }
- treug(double x1, double y1, double x2, double y2, double x3, double y3) : a(x1, y1)
- {
- pb = new dpoint(x2, y2);
- pc = new dpoint(x3, y3);
- }
- ~treug()
- {
- if (pb != NULL) delete pb;
- if (pc != NULL) delete pc;
- }
- treug(treug &z)
- {
- a = z.a;
- pb = new dpoint(*z.pb);
- pc = new dpoint(*z.pc);
- }
- treug& operator=(treug &z)
- {
- if (this == &z) return z;
- a = z.a;
- *pb = *z.pb;
- *pc = *z.pc;
- }
- friend void input(treug &);
- void output()
- {
- a.output();
- pb->output();
- pc->output();
- }
- };
- void input(treug &tr)
- {
- tr.a.input();
- tr.pb->input();
- tr.pc->input();
- }
- void main()
- {
- treug t(1,2,3,4,5,6);
- treug t1 = t;
- t1.output();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement