2d point class in c 2b 2b

Solutions on MaxInterview for 2d point class in c 2b 2b by the best coders in the world

showing results for - "2d point class in c 2b 2b"
Jacopo
10 Feb 2018
1class point
2{
3
4private:
5    float x;
6    float y;
7
8public:
9    point(float a = 0, float b = 0)
10    {
11        x = a;
12        y = b;
13        cout << "***" << x << "," << y << endl;
14    }
15    point operator+(point p)
16    {
17        point p3;
18        p3.x = this->x + p.x;
19        p3.y = this->y + p.y;
20
21        return p3;
22    }
23    friend point operator*(float a, point p)
24    {
25        return p * a;
26    }
27
28    point operator*(float a)
29    {
30        point p1;
31        p1.x = a * x;
32        p1.y = a * y;
33        return p1;
34    }
35
36    void print()
37    {
38        cout << this->x << "\n"
39             << this->y << "\n";
40    }
41    friend float get_x(point);
42};
43float get_x(point p)
44{
45    return p.x;
46}