Interview Question for Developer Advocates


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

// ZoomBA
// define Point 
def Point : {
   $$ : def(x=0,y=0){  $.x = x ; $.y = y },
   $add : def (o) { new ( Point , $.x + o.x , $.y + o.y ) },
   $str : def(){ str('(%s,%s)', $.x, $.y)}
}

a = new ( Point, 1,2)
b = new ( Point, 3,4)
c = a + b 
println(c)

- NoOne April 03, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Point{
    private:
        int x, y;   
    public:
        Point(int xval, int yval):x(xval),y(yval){}
        Point operator+(const Point& other)
        {
            this->x += other.x;
            this->y += other.y;
            return *this;
        }
        void print()
        {
            std::cout << "x: " << x << "\n";
            std::cout << "y: " << y << "\n";
        }
        
};

int main()
{
    Point p1(1,2);
    Point p2(3,4);
    Point p4(4,5);
    Point p3 = p1+p2+p4;
    p3.print();
}

- steep April 04, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

:: - steephen
====
Your + operator is *mutable*. It should never be, definitely NO for a arithmetic type.
What you did is this:
stackoverflow.com/questions/4581961/c-how-to-overload-operator
wikipedia.org/wiki/Immutable_object

- NoOne April 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Found a Ruby implementation:

class Point
    attr_accessor :x, :y

    def initialize(x,y)
        @x, @y = x, y
    end


    def +(other)
      Point.new(@x + other.x, @y + other.y)
    end


    def to_s
        "(#{@x}, #{@y})"
    end
end

- Shlomi December 01, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More