Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class dpoint {
- double *px;
- double y;
- public:
- double getPx() const;
- double getY() const;
- dpoint(double ix, double iy) {
- px = new double(ix);
- y = iy;
- }
- /* dpoint(dpoint &a) {
- px = new double(*a.px);
- y = a.y;
- }*/
- ~dpoint() {
- delete px;
- }
- friend std::istream &operator>>(std::istream &in, dpoint &var) {
- in >> *var.px >> var.y;
- return in;
- }
- friend void increaseCoordinate(dpoint &a, double dx, double dy);
- friend std::ostream &operator<<(std::ostream &os, const dpoint &dpoint1);
- dpoint& operator=(dpoint& a){
- px = new double(*a.px);
- y = a.y;
- }
- };
- void increaseCoordinate(dpoint &a, double dx, double dy) {
- std::cout << "\n inc " << *a.px << " " << a.y << "\n";
- if (a.px == nullptr) {
- a.px = new double(dx);
- } else
- *a.px += dx;
- a.y += dy;
- }
- std::ostream &operator<<(std::ostream &os, const dpoint &dpoint1) {
- os << "px: " << *dpoint1.px << " y: " << dpoint1.y;
- return os;
- }
- double dpoint::getPx() const {
- return *px;
- }
- double dpoint::getY() const {
- return y;
- }
- class interval {
- dpoint a;
- dpoint b;
- public:
- // interval(const dpoint &a, const dpoint &b) : a(a), b(b) {}
- interval(double ax, double ay, double bx, double by): a(ax,ay), b(bx,by){}
- interval(interval &i2) : a(i2.a.getPx(),i2.a.getY()),b(i2.b.getPx(),i2.b.getY()) {}
- friend void swap(interval &m) {
- dpoint c(m.a.getPx(),m.a.getY());
- m.a = m.b;
- m.b = c;
- }
- void showPoints() {
- std::cout << "xa " << a.getPx() << " ya " << a.getY() << " xb " << b.getPx() << " yb " << b.getY() << "\n";
- }
- friend std::istream &operator>>(std::istream &in, interval& x) {
- in >> x.a >> x.b;
- return in;
- }
- };
- int main() {
- dpoint t(3.1, 77.9), a(1, 1);
- std::cout << t << "\nВведите 2 точки\n";
- std::cin >> a;
- std::cout << "magic:\n" << a << "\n";
- increaseCoordinate(a, 5.5, 1.1); std::cout << a << "\n-----------\n";
- // interval i1(dpoint(1.1, 2.2), dpoint(3.3, 4.4));
- // interval i1(t, a);
- interval i1(6,7,8,9);
- std::cout << "i1\n";
- i1.showPoints();
- interval i2(i1);
- std::cout << "i2\n";
- i2.showPoints();
- std::cout << "ESHE 4 tochki\n";
- std::cin >> i2;
- std::cout << "i2\n";
- i2.showPoints();
- std::cout << "i1\n";
- i1.showPoints();
- swap(i1);
- std::cout << "i1\n";
- i1.showPoints();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement