Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
1.0 kB
4
Indexable
Never
#include <iostream>
#include <math.h>

using namespace std;

class Point {
  public:
    // Constructor with initialization list
    Point(int x, int y) : x_(x), y_(y) {}

    void setX(int x) { x_ = x; }
    void setY(int y) { y_ = y; }

    int getX() const { return x_; }
    int getY() const { return y_; }

  private:
    int x_;
    int y_;
};

class Line {
  public:
    // Constructor with initialization list
    Line(int x0, int y0, int x1, int y1)
        : begin_(Point(x0, y0)), end_(Point(x1, y1)) {}

    void setBegin(Point begin) { begin_ = begin; }
    void setEnd(Point end) { end_ = end; }

    Point getBegin() const { return begin_; }
    Point getEnd() const { return end_; }
    double getLine() const {
        return sqrt(pow(end_.getX() - begin_.getX(),2) + pow(end_.getY() - begin_.getY(),2));
    }

  private:
    Point begin_;
    Point end_;
};

int main() {
    Line line(1,2,3,4);
    cout << line.getLine() << endl;
    return 0;
}